public function perform() { $args = $this->args; if (empty($args['key']) || empty($args['header']) || empty($args['accountId'])) { ResqueUtil::log(['status' => 'fail to export registration record', 'message' => 'missing params', 'args' => $args]); return false; } $keyword = $args['keyword']; $header = $args['header']; $fileName = $args['key']; $accountId = unserialize($args['accountId']); $filePath = ExcelUtil::getFile($fileName, 'csv'); $query = new Query(); if ($keyword == '') { $records = $query->from('uhkklpRegistration')->select(['name', 'mobile', 'restaurantName', 'zipCode', 'city', 'address'])->where(['accountId' => $accountId])->all(); } else { $records = $query->from('uhkklpRegistration')->select(['name', 'mobile', 'restaurantName', 'zipCode', 'city', 'address'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->all(); } $rows = $records; 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 registration', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
public function perform() { $args = $this->args; if (empty($args['language']) || empty($args['header']) || empty($args['key']) || empty($args['accountId']) || empty($args['condition'])) { ResqueUtil::log(['status' => 'fail to export code', 'message' => 'missing params', 'args' => $args]); return false; } //set the language Yii::$app->language = empty($args['language']) ? LanguageUtil::DEFAULT_LANGUAGE : $args['language']; $header = $args['header']; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $condition = unserialize($args['condition']); $object = GoodsExchangeLog::find(); $classFunction = '\\backend\\modules\\product\\models\\GoodsExchangeLog::preProcessExportData'; $backendUser = Account::findByPk(new \MongoId($args['accountId'])); ExcelUtil::processMultiData($header, $filePath, $backendUser, $condition, $object, $classFunction, ['changeTostring' => ['goods']]); $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; } }
public function perform() { $args = $this->args; if (empty($args['key']) || empty($args['header']) || empty($args['condition'])) { ResqueUtil::log(['status' => 'fail to export sms result record', 'message' => 'missing params', 'args' => $args]); return false; } $condition = unserialize($args['condition']); $header = $args['header']; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $rows = BulkSmsFailed::find()->where($condition)->all(); $rowsSuccess = BulkSmsFailed::find()->where($condition)->all(); $finalRows = array_merge($rows, $rowsSuccess); ExcelUtil::exportCsv($header, $finalRows, $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 result', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) { ResqueUtil::log(['status' => 'fail to export slotgame useRecord', 'message' => 'missing params', 'args' => $args]); return false; } $condition = unserialize($args['condition']); $activityId = $condition['activityId']; $condition = ['activityId' => $activityId]; $accountId = new \MongoId($args['accountId']); $header = $args['header']; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $object = ActivityUser::find(); if (empty($object)) { ResqueUtil::log(['status' => 'fail to export slotgame useRecord', 'message' => 'no data found in DB', 'args' => $args]); return false; } $classFunction = '\\backend\\modules\\uhkklp\\models\\ActivityUser::preProcessBarUseRecordData'; ExcelUtil::processMultiData($header, $filePath, $args, $condition, $object, $classFunction); $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 slotgame useRecord', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
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 function perform() { $args = $this->args; if (empty($args['header']) || empty($args['condition']) || empty($args['key']) || empty($args['accountId']) || empty($args['collection']) || empty($args['sort']) || empty($args['fields']) || empty($args['classFunction']) || !isset($args['params'])) { LogUtil::error(['message' => 'missing params when create job for export file', 'args' => $args]); return false; } $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $condition = ExcelUtil::processCondition(unserialize($args['condition'])); ExcelUtil::exportWithMongo($args['collection'], $args['fields'], $filePath, $condition, $args['sort']); if (!file_exists($filePath)) { LogUtil::error(['message' => 'Can not find this file', 'fileName' => $filePath, 'condition' => $condition, 'args' => $args], 'resque'); return false; } self::processProductInfoData($args['header'], $filePath, $args['classFunction'], $args['params']); $newFilePath = ExcelUtil::getDownloadFile($filePath); $hashKey = ExcelUtil::setQiniuKey($newFilePath, $fileName); @unlink($filePath); @unlink($newFilePath); 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; } }
public function perform() { $args = $this->args; if (empty($args['status']) || empty($args['header']) || empty($args['key']) || empty($args['accountId']) || empty($args['sku'])) { LogUtil::error(['message' => 'Faild to export code, missing params', 'args' => $args], 'resque'); return false; } $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $condition = ExcelUtil::processCondition(unserialize($args['condition'])); $baseData = ['sku' => $args['sku'], 'status' => $args['status']]; ExcelUtil::exportWithMongo('promotionCode', $args['fields'], $filePath, $condition); $classFunction = '\\backend\\modules\\product\\models\\PromotionCode::preProcessCodeData'; if (!file_exists($filePath)) { return false; } ExcelUtil::processRowsData($args['header'], $filePath, $classFunction, $baseData); $newFilePath = ExcelUtil::getDownloadFile($filePath); $hashKey = ExcelUtil::setQiniuKey($newFilePath, $fileName); @unlink($filePath); @unlink($newFilePath); 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; } }
public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header']) || empty($args['type']) || empty($args['smsRecordId'])) { ResqueUtil::log(['status' => 'fail to export bulk sms record', 'message' => 'missing params', 'args' => $args]); return false; } $accountId = new \MongoId($args['accountId']); $smsRecordId = new \MongoId($args['smsRecordId']); $header = $args['header']; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $rows = null; if ($args['type'] == 'all') { $rows = BulkSmsLog::preProcessBulkSmsRecordData($smsRecordId, $accountId); } else { if ($args['type'] == 'faild') { // 暂时还没用到 } } 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 early bird sms details', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header'])) { ResqueUtil::log(['status' => 'fail to export member', 'message' => 'missing params', 'args' => $args]); return false; } Yii::$app->language = empty($args['language']) ? LanguageUtil::DEFAULT_LANGUAGE : $args['language']; $accountId = new \MongoId($args['accountId']); $header = $args['header']; // get member's customized properties $memberProperties = MemberProperty::getByAccount($accountId); foreach ($memberProperties as $memberProperty) { if ($memberProperty->isDefault) { $header[$memberProperty->name] = Yii::t('member', $memberProperty->name); } else { $header[$memberProperty->name] = $memberProperty->name; } } $socialAccountsMap = []; $account = Account::findByPk($accountId); $channelIds = Channel::getEnableChannelIds($accountId); if (!empty($channelIds)) { $socialAccounts = \Yii::$app->weConnect->getAccounts($channelIds); foreach ($socialAccounts as $socialAccount) { $socialAccountsMap[$socialAccount['id']] = $socialAccount['name']; } } $cardMap = []; $cards = MemberShipCard::getByAccount($accountId); foreach ($cards as $card) { $cardMap[(string) $card->_id] = $card->name; } $condition = unserialize($args['condition']); //get properties $memberProperties = MemberProperty::findAll(['accountId' => $accountId]); $base = ['cardMap' => $cardMap, 'socialAccountsMap' => $socialAccountsMap, 'memberProperties' => $memberProperties]; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $orderBy = Member::normalizeOrderBy($args['params']); $object = Member::find(); $classFunction = '\\backend\\modules\\member\\models\\Member::preProcessMemberData'; ExcelUtil::processMultiData($header, $filePath, $base, $condition, $object, $classFunction, [], $orderBy); $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; } }
public function perform() { $args = $this->args; $messageId = $args['messageId']; $accoutnId = $args['accoutnId']; $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $header = ['messageId' => '消息ID', 'messageContent' => '消息內容', 'mobile' => '手機號', 'deviceType' => '設備類型', 'deviceId' => '設備ID', 'result' => '推播結果']; $rows = PushMessageLog::getResults($messageId); ExcelUtil::exportCsv($header, $rows, $filePath, 1); $hashKey = ExcelUtil::setQiniuKey($filePath, $fileName); Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $accoutnId]); }
public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['key']) || empty($args['header']) || empty($args['collection']) || empty($args['fields'])) { LogUtil::info(['message' => 'fail to export klp member, missing params', 'args' => $args], 'resque'); return false; } $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $condition = ExcelUtil::processCondition(unserialize($args['condition'])); ExcelUtil::exportWithMongo($args['collection'], $args['fields'], $filePath, $condition); $classFunction = '\\backend\\modules\\member\\models\\Member::preProcessKlpMemberData'; $headerKeys = array_keys($args['header']); ExcelUtil::processRowsData($args['header'], $filePath, $classFunction, $headerKeys); $newFilePath = ExcelUtil::getDownloadFile($filePath); $downloadFilePath = self::getFile($fileName); copy($newFilePath, $downloadFilePath); @unlink($newFilePath); @unlink($filePath); //notice frontend the job is finished Yii::$app->tuisongbao->triggerEvent(Message::EVENT_EXPORT_FINISH, ['key' => $fileName], [Message::CHANNEL_GLOBAL . $args['accountId']]); }
public function perform() { $args = $this->args; if (empty($args['accountId']) || empty($args['header']) || empty($args['key']) || empty($args['channelId']) || empty($args['qrcodeId']) || empty($args['condition'])) { ResqueUtil::log(['message' => 'missing param in export qrcode info', 'args' => $args]); return false; } $condition = unserialize($args['condition']); $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $classFunction = '\\backend\\models\\Qrcode::preProcessData'; $condition = ['condition' => $condition, 'channelId' => $args['channelId'], 'qrcodeId' => $args['qrcodeId']]; ExcelUtil::processData($args['header'], $filePath, $classFunction, $condition); $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; } }
public function perform() { $args = $this->args; if (empty($args['key']) || empty($args['header']) || empty($args['accountId'])) { ResqueUtil::log(['status' => 'fail to export goods record', 'message' => 'missing params', 'args' => $args]); return false; } $keyword = $args['keyword']; $header = $args['header']; $fileName = $args['key']; $accountId = unserialize($args['accountId']); $filePath = ExcelUtil::getFile($fileName, 'csv'); $query = new Query(); if ($keyword == '') { $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->all(); } else { $records = $query->from('uhkklpOrder')->select(['_id', 'createdAt', 'name', 'mobile', 'restaurantName', 'address', 'businessForm', 'product'])->where(['accountId' => $accountId])->andWhere(['like', 'mobile', $keyword])->all(); } for ($i = 0; $i < count($records); $i++) { $records[$i]['createdAt'] = MongodbUtil::MongoDate2String($records[$i]['createdAt'], 'Y-m-d H:i:s', null); $records[$i]['_id'] = (string) $records[$i]['_id']; $pro = ""; for ($j = 0; $j < count($records[$i]['product']); $j++) { $pro .= " " . $records[$i]['product'][$j]; } $records[$i]['product'] = $pro; } $rows = $records; 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 order', 'message' => 'fail to setQiniuKey', 'filePath' => $filePath]); return false; } }
public function perform() { $args = $this->args; /** * @param $header, array. key is used to map the data to export,value is file title * @param $condition, string. it is a serialize string.example serialize(array()) * @param $key, string, file name * @param collection, string, collection name * @param $sort, array. example:['createdAt':-1] * @param $fields, string. it is used as fields for mongoexport * @param $classFunction, string.example:\backend\modules\product\models\CampaignLog::preProcessRedeemedCodeData * @param $params, array, it is a extra data as params in preProcessRedeemedCodeData */ if (empty($args['header']) || empty($args['condition']) || empty($args['key']) || empty($args['accountId']) || empty($args['collection']) || empty($args['sort']) || empty($args['fields']) || empty($args['classFunction']) || !isset($args['params'])) { LogUtil::error(['message' => 'missing params when create job for export file', 'args' => $args]); return false; } $fileName = $args['key']; $filePath = ExcelUtil::getFile($fileName, 'csv'); $condition = ExcelUtil::processCondition(unserialize($args['condition'])); ExcelUtil::exportWithMongo($args['collection'], $args['fields'], $filePath, $condition, $args['sort']); if (!file_exists($filePath)) { LogUtil::error(['message' => 'Can not find this file', 'fileName' => $filePath, 'condition' => $condition, 'args' => $args], 'resque'); return false; } ExcelUtil::processRowsData($args['header'], $filePath, $args['classFunction'], $args['params']); $newFilePath = ExcelUtil::getDownloadFile($filePath); $hashKey = ExcelUtil::setQiniuKey($newFilePath, $fileName); @unlink($filePath); @unlink($newFilePath); 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; } }