public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header']) || empty($args['activityName'])) { ResqueUtil::log(['status' => 'fail to export lucky draw winners record', 'message' => 'missing params', 'args' => $args]); return false; } // $accountId = new \MongoId($args['accountId']); $condition = unserialize($args['condition']); $header = $args['header']; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $rows = array(); if ($args['activityName'] == 'cny') { $rows = LuckyDrawWinner::preProcessCnyWinnerData($condition); } ExcelUtil::exportCsv($header, $rows, $filePath, 1); $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName); if ($hashKey) { //notice frontend the job is finished Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $args['accountId']]); return true; } else { ResqueUtil::log(['status' => 'fail to export lucky draw winners record', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
public static function createSmsJob($condition, $operator, $smsName) { $totalCount = 0; $accountId = Token::getAccountId(); if (!array_key_exists('accountId', $condition)) { $condition = array_merge($condition, ['accountId' => $accountId]); } switch ($smsName) { case 'cny_winners': $smsTemplate = self::CNY_WINNERS_SMS_TEMPLATE; $totalCount = LuckyDrawWinner::find()->where($condition)->count(); break; default: break; } $recordId = BulkSmsRecord::createSmsRecord($operator, $smsName, $smsTemplate, $totalCount); if (is_bool($recordId) && !$recordId) { throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!"); } $args = ['condition' => serialize($condition), 'smsName' => $smsName, 'smsRecord' => (string) $recordId]; $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\BulkSms', $args); if (!empty($jobId)) { return ['smsRecordId' => (string) $recordId, 'count' => $totalCount]; } else { throw new ServerErrorHttpException("發送失敗,請刷新頁面重試!"); } }
public function perform() { $args = $this->args; if (empty($args['condition']) || empty($args['smsName'])) { ResqueUtil::log(['status' => 'fail to send early bird sms', 'message' => 'missing params', 'args' => $args]); LogUtil::error(['message' => 'missing params in job', 'args' => $args], 'bulkSms'); } $condition = unserialize($args['condition']); $smsRecordId = new \MongoId($args['smsRecord']); $smsData = null; switch ($args['smsName']) { case 'cny_winners': $smsData = LuckyDrawWinner::preProcessCnyWinnerSmsData($condition); break; default: break; } BulkSmsUtil::sendSms($smsData, $args['smsName'], $smsRecordId, $condition['accountId']); }
public static function preProcessCnyWinnerSmsData($condition) { // TODO refine smsContent $winners = LuckyDrawWinner::find()->where($condition)->all(); $smsTemplate = BulkSmsUtil::CNY_WINNERS_SMS_TEMPLATE; $rows = array(); foreach ($winners as $winner) { $smsContent = str_replace("%username%", $winner->name, $smsTemplate); $smsContent = str_replace("%awardName%", $winner->awardName, $smsContent); $row = ['mobile' => $winner->mobile, 'smsContent' => $smsContent]; $rows[] = $row; unset($row, $smsContent); } return $rows; }
public function actionExportSmsContent($id) { $accountId = $this->getAccountId(); $condition = ['accountId' => $accountId, 'drawRecordId' => new \MongoId($id)]; $result = LuckyDrawWinner::find()->where($condition)->one(); if (!empty($result)) { $key = 'CNY活動中獎通知簡訊_' . date('YmdHis'); $condition = serialize($condition); $header = ['mobile' => '手機號碼', 'smsContent' => '簡訊內容']; $exportArgs = ['key' => $key, 'header' => $header, 'accountId' => (string) $accountId, 'condition' => $condition, 'activityName' => 'cny', 'description' => "Direct: export CNY winners' SMS"]; $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\ExportLuckyDrawWinners', $exportArgs); return ['result' => 'success', 'message' => 'exporting file', 'data' => ['jobId' => $jobId, 'key' => $key]]; } else { LogUtil::error(['message' => "Failed exporting CNY winners' SMS content", 'reason' => '没有数据(no data)', 'condition' => $condition], 'cny'); return ['result' => 'error', 'message' => 'no datas', 'data' => []]; } }