public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) { ResqueUtil::log(['status' => 'fail to export slotgame prize statistic', 'message' => 'missing params', 'args' => $args]); return false; } $cookbookTitle = $args['cookbookTitle']; $header = $args['header']; $fileName = $args['key']; $filePath = self::getFile($fileName . date('YmdHis'), 'csv'); $pIndex = 1; $condition = unserialize($args['condition']); $accountId = new \MongoId($args['accountId']); $cookbookId = (string) $condition['cookbookId']; $rows = SampleRecord::getSampleRecordExcelDate($cookbookId, $accountId); self::exportCsv($cookbookTitle, $header, $rows, $filePath, $pIndex); $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 { return false; } return false; }
public function actionSaveSampleRecordOneTime() { $accountId = $this->getAccountId(); $mobile = $this->getParams('mobile', ''); $cookbookId = $this->getParams('cookbookId', ''); $sampleIds = $this->getParams('sampleId', ''); $username = $this->getParams('username', ''); $city = $this->getParams('city', ''); $address = $this->getParams('address', ''); $restaurantName = $this->getParams('restaurantName', ''); $userAppellation = $this->getParams('userAppellation', ''); $placeNumber = $this->getParams('placeNumber', ''); $cookbook = Cookbook::findOne($cookbookId); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if ($cookbook == null) { return ['code' => 1204, 'msg' => 'cookbook not found.']; } if (strlen($mobile) == 0) { return ['code' => 1202, 'msg' => 'mobile is required.']; } $sample = $cookbook->sample; $sampleIdArray = explode(",", $sampleIds); for ($j = 1; $j <= count($sampleIdArray); $j++) { $sampleId = $sampleIdArray[$j - 1]; $query = new Query(); $query->from('uhkklpSamplerecord')->where(['mobile' => $mobile, 'cookbookId' => $cookbookId, 'sampleId' => $sampleId, 'accountId' => $accountId]); $record = $query->one(); if ($record != null) { $msg = 'sample ' . $sampleIdArray[$j]['name'] . ' has been recorded'; return ['code' => 1206, 'msg' => $msg]; } } for ($j = 1; $j <= count($sampleIdArray); $j++) { $sampleId = $sampleIdArray[$j - 1]; for ($i = 0; $i < count($sample); $i++) { if ($sample[$i]['id'] == $sampleId) { break; } } if ($i >= count($sample)) { return ['code' => 1208, 'msg' => 'sample is not exist.']; } $sampleQuantity = $sample[$i]['quantity']; $sampleName = $sample[$i]['name']; $record = new SampleRecord(); $record->mobile = $mobile; $record->cookbookId = $cookbookId; $record->cookbookTitle = $cookbook->title; $record->sampleId = $sampleId; $record->sampleName = $sampleName; $record->username = $username; $record->city = $city; $record->address = $address; $record->createdDate = time(); $record->accountId = $accountId; $record->quantity = $sampleQuantity; $record->restaurantName = $restaurantName; $record->userAppellation = $userAppellation; $record->placeNumber = $placeNumber; if (!$record->save()) { return ['code' => 1205, 'msg' => 'Save error!']; } } LogUtil::info('SaveSampleRecordOneTime' . ' mobile:' . $mobile . ' cookbookTitle' . $cookbook->title . ' time' . time(), 'cookbook-log'); return ['code' => 200, 'msg' => 'OK']; }