/** * 用户同步报告(默认汇总前一日) */ public function actionEmailReport($startTime = false, $endTime = false) { list($startTime, $endTime) = $this->_getTime($startTime, $endTime, false); $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 = ['<h3>' . date('Y-m-d H:i:s', $startTime) . ' 至 ' . date('Y-m-d H:i:s', $endTime) . " iHeima用户注册情况</h3>"]; $msgData[] = '<table cellpadding=\'5\' cellspacing=\'0\' style=\'border: 2px solid #EEE\'>'; $msgData[] = '<tr style=\'background-color: #EEE;\'><td>手机号码</td><td>OPENID</td><td>同步状态</td></tr>'; $stat = ['sync_ok' => 0, 'sync_fail' => 0, 'openid_incon' => 0, 'multi_openid' => 0]; $ihmUsers = $this->_transform($ihmUsers); foreach ($dcUsers as $user) { $mobile = $user['mobile']; $openid = $user['open_id']; if (isset($ihmUsers[$mobile])) { if (is_array($ihmUsers[$mobile])) { $msgData[] = '<tr><td>' . $mobile . '</td><td>' . $openid . '</td><td>存在多OPENID</td></tr>'; $stat['multi_openid']++; } else { if ($ihmUsers[$mobile] == $user['open_id']) { // $msgData[] = $mobile . ' (' . $openid . '): 同步无误'; $msgData[] = '<tr><td>' . $mobile . '</td><td>' . $openid . '</td><td>同步无误</td></tr>'; $stat['sync_ok']++; } else { // $msgData[] = $mobile . ' (' . $openid . '): OPENID不匹配'; $msgData[] = '<tr><td>' . $mobile . '</td><td>' . $openid . '</td><td>OPENID不匹配</td></tr>'; $stat['openid_incon']++; } } } else { // $msgData[] = $mobile . ' (' . $openid . '): 不存在'; $msgData[] = '<tr><td>' . $mobile . '</td><td>' . $openid . '</td><td>不存在</td></tr>'; $stat['sync_fail']++; } } $msgData[] = '</tr></table>'; $statMsg = ['<div>']; foreach ($stat as $key => $val) { $statMsg[] = $key . ':' . $val; } $statMsg[] = '</div>'; // echo implode("\n", $msgData) . "\n\n"; // echo implode("\t", $statMsg) . "\n\n"; $email = Yii::$app->params['syncuser_notify_email']; $data = ['userID' => 0, 'to' => $email, 'appID' => '100000', 'business' => 'S_SYNCUSER_REPORT', 'tplno' => 6, 'subject' => '检测同步用户报告(' . date('Y-m-d', $startTime) . ')', 'msg' => implode('', $msgData) . implode(' ', $statMsg)]; $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'); } }