Exemplo n.º 1
0
 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("發送失敗,請刷新頁面重試!");
     }
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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' => []];
     }
 }