/**
  * 以数据中心用户为基础针对iHeima用户进行数据修复
  */
 public function actionRepire($startTime = false, $endTime = false)
 {
     list($startTime, $endTime) = $this->_getTime($startTime, $endTime);
     $mMember = new Member();
     $ihmMobiles = [];
     $ihmUsers = Member::getByTime($startTime, $endTime);
     $dcUsers = UserBaseInfo::getByTime($startTime, $endTime);
     if (!$dcUsers) {
         die(date('Y-m-d H:i:s', $startTime) . ' 至 ' . date('Y-m-d H:i:s', $endTime) . " 暂无用户注册\n");
     }
     $msgData = [];
     $storeMsg = [];
     $updateMsg = [];
     $insertData = [];
     $stat = ['sync_ok' => 0, 'sync_fail' => 0, 'openid_incon' => 0, 'multi_openid' => 0];
     $ihmUsers = $this->_transform($ihmUsers);
     echo "\n\n";
     foreach ($dcUsers as $user) {
         // $user['open_id'] = '';
         $mobile = $user['mobile'];
         $openid = $user['open_id'];
         if (isset($ihmUsers[$mobile])) {
             if (is_array($ihmUsers[$mobile])) {
                 $msgData[] = $mobile . '  (' . $openid . '): 存在多OPENID';
                 $stat['multi_openid']++;
             } else {
                 if ($ihmUsers[$mobile] == $user['open_id']) {
                     $msgData[] = $mobile . '  (' . $openid . '): 同步无误';
                     $stat['sync_ok']++;
                 } else {
                     $msgData[] = $mobile . '  (' . $openid . '): OPENID不匹配';
                     if ($mMember->updateOpenid($mobile, $openid)) {
                         $ihmOpenid = $ihmUsers[$mobile] ? $ihmUsers[$mobile] : '空';
                         $updateMsg[] = $mobile . ': OPENID同步成功(' . $ihmOpenid . '=>' . $openid . ')';
                     } else {
                         $updateMsg[] = $mobile . ': OPENID同步失败';
                     }
                     $stat['openid_incon']++;
                 }
             }
         } else {
             $msgData[] = $mobile . '  (' . $openid . '): 不存在';
             if ($userid = $this->_store($user)) {
                 $storeMsg[] = $mobile . ':  重新同步成功(' . $userid . ')';
             } else {
                 $storeMsg[] = $mobile . ': 重新同步失败';
             }
             $stat['sync_fail']++;
         }
     }
     $statMsg = [];
     foreach ($stat as $key => $val) {
         $statMsg[] = $key . ':' . $val;
     }
     echo implode("\n", $msgData) . "\n\n";
     echo implode("\t", $statMsg) . "\n\n";
     if ($storeMsg) {
         echo "用户信息重新同步结果如下:\n";
         echo implode("\n", $storeMsg) . "\n\n";
     }
     if ($updateMsg) {
         echo "用户OPENID重新同步结果如下:\n";
         echo implode("\n", $updateMsg) . "\n\n";
     }
 }
 public function actionReport($startTime = false, $endTime = false)
 {
     date_default_timezone_set('PRC');
     if (empty($startTime) && empty($endTime)) {
         $startTime = strtotime(date('Y-m-d 00:00:00', strtotime("-1 day")));
         $endTime = strtotime(date('Y-m-d 23:59:59', strtotime("-1 day")));
     } else {
         if (empty($startTime) || empty($endTime)) {
             $tmp = $startTime;
             $startTime = strtotime($tmp . ' 00:00:00');
             $endTime = strtotime($tmp . ' 23:59:59');
         } else {
             if ($startTime > $endTime) {
                 $tmp = $startTime;
                 $startTime = $endTime;
                 $endTime = $tmp;
             }
             $startTime = strtotime($startTime);
             $endTime = strtotime($endTime);
         }
     }
     //获取i黑马注册用户的信息
     $ihmUsers = Member::getByTime($startTime, $endTime);
     //获取数据中心注册用户的信息
     $dcUsers = UserBaseInfo::getByTime($startTime, $endTime);
     if (empty($dcUsers) && empty($ihmUsers)) {
         $errorMessage[] = date('Y-m-d H:i:s', $startTime) . '至' . date('Y-m-d H:i:s', $endTime) . ' 无用户注册。';
     } else {
         if (empty($dcUsers) && isset($ihmUsers)) {
             $errorMessage[] = date('Y-m-d H:i:s', $startTime) . '至' . date('Y-m-d H:i:s', $endTime) . ' 数据中心中无用户注册,而i黑马有用户注册。';
         } else {
             $ihmOpenIds = array();
             foreach ($ihmUsers as $key => $user) {
                 $mobile = $user['mobile'];
                 if (isset($ihmOpenIds[$mobile])) {
                     if (is_string($ihmOpenIds[$mobile])) {
                         $ihmOpenIds[$mobile] = [$ihmOpenIds[$mobile], $user['open_id']];
                     } else {
                         if (is_array($ihmOpenIds[$mobile])) {
                             $ihmOpenIds[$mobile][] = $user['open_id'];
                         }
                     }
                 } else {
                     $ihmOpenIds[$mobile] = $user['open_id'];
                 }
             }
             foreach ($dcUsers as $key => $user) {
                 $mobile = $ihmOpenIds[$user['mobile']];
                 if (!isset($mobile)) {
                     $errorMessage[] = $user['mobile'] . '(' . $user['open_id'] . ') : 同步失败';
                 } else {
                     if (is_array($mobile)) {
                         $mobile = implode(", ", $mobile);
                         $errorMessage[] = $user['mobile'] . '(' . $user['open_id'] . ') : 存在多OPENID (' . $mobile . ')';
                     } else {
                         if (is_string($mobile)) {
                             if ($mobile != $user['open_id']) {
                                 $errorMessage[] = $user['mobile'] . '(' . $user['open_id'] . ') : OPENID不匹配(' . $user['open_id'] . ',' . $mobile . ')';
                             }
                         }
                     }
                 }
             }
         }
     }
     $errorMessage = implode("<br/>", $errorMessage);
     //发送邮件操作
     $userID = UserBaseInfo::SYSTEM_USER;
     $email = Yii::$app->params['syncUserEmail'];
     $data = ['userID' => $userID, 'to' => $email, 'appID' => '100000', 'business' => S_SYNCUSER_CHECK, 'tplno' => 5, 'subject' => '检测同步用户报告', 'content' => $errorMessage];
     $sender = Yii::$app->mailer;
     $result = $sender->check($data, true);
     if (!$result[0]) {
         $result = $sender->exec($result[1]);
     } else {
         //邮箱发送失败记录到日志文件中
         FileLogger::getInstance(date('Ymd') . '_sync_user_report.log')->writeOne('邮箱发送失败', Logger::LEVEL_ERROR, 'report');
     }
 }