Ejemplo n.º 1
0
 public function actionExportSmsModel()
 {
     $id = $this->getQuery('modelGroupId');
     // LogUtil::error(date('Y-m-d h:i:s') . ' $id: ' . $id);
     $condition = ['groupId' => $id];
     $result = SmsModel::find()->where($condition)->one();
     if (!empty($result)) {
         $key = 'Sms發送手機號及內容列表' . date('YmdHis');
         $header = ['groupId' => '導入批號', 'mobile' => '手機號碼', 'content' => '內容'];
         $exportArgs = ['key' => $key, 'header' => $header, 'condition' => serialize($condition)];
         $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\ExportSmsModel', $exportArgs);
         return ['result' => 'success', 'message' => 'exporting SmsModel', 'data' => ['jobId' => $jobId, 'key' => $key]];
     } else {
         LogUtil::error(['message' => 'smsModel記錄表失败', 'reason' => '没有数据(no data)', 'condition' => $condition], 'sms');
         return ['result' => 'error', 'message' => 'no datas', 'data' => []];
     }
 }
Ejemplo n.º 2
0
 public function perform()
 {
     $args = $this->args;
     if (empty($args['key']) || empty($args['header']) || empty($args['condition'])) {
         ResqueUtil::log(['status' => 'fail to export sms model record', 'message' => 'missing params', 'args' => $args]);
         return false;
     }
     $condition = unserialize($args['condition']);
     $header = $args['header'];
     $fileName = $args['key'];
     $filePath = ExcelUtil::getFile($fileName, 'csv');
     $rows = SmsModel::find()->where($condition)->all();
     // LogUtil::error(date('Y-m-d h:i:s') . ' $content....: ' . count($rows));
     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]);
         return true;
     } else {
         ResqueUtil::log(['status' => 'fail to export sms model', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]);
         return false;
     }
 }