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['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 static function exportCsv($cookbookTitle, $header, $rows, $filename, $pIndex, $options = []) { $options = self::_mergeOptions($options); if (file_exists($filename)) { $handle = fopen($filename, 'a+'); if (count($rows) > 0) { foreach ($rows as $row) { $row = ExcelUtil::setRowValue($row, $header, $options); fputcsv($handle, $row); unset($row); } fclose($handle); unset($header, $filename, $pIndex, $options, $handle); } } else { $objPHPExcel = new \PHPExcel(); $objPHPExcel->getActiveSheet()->setCellValue('A1', '食譜名稱'); $objPHPExcel->getActiveSheet()->setCellValue('B1', $cookbookTitle); $pIndex = $pIndex + 2; if ($options['printHeader']) { $index = 0; foreach ($header as $item) { $pCoordinate = ExcelUtil::setColumnIndex($index) . $pIndex; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $item); $index++; } $pIndex = $pIndex + 1; } if (count($rows) > 0) { foreach ($rows as $row) { $row = ExcelUtil::setRowValue($row, $header, $options); $index = 0; foreach ($header as $key => $value) { $item = isset($row[$key]) ? $row[$key] : ''; $pCoordinate = ExcelUtil::setColumnIndex($index) . $pIndex; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($pCoordinate, $item); $index++; } $pIndex++; } } $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV')->setDelimiter($options['delimiter'])->setEnclosure($options['quote'])->setLineEnding($options['linefeed'])->setSheetIndex(0)->setUseBOM(true)->save($filename); unset($objPHPExcel, $objWriter); } unset($rows); }
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; } }
private function writeCsv($classFunction, $args, $header, $newFilePath) { $data = call_user_func_array($classFunction, $args); ExcelUtil::exportCsv($header, [$data], $newFilePath, 1); unset($data); }
/** * process every rows data whitch read from file * @param $header, array, write use csv header title * @param $filePath, string, file path * @param $classFunction, string, recall functuion * @param $params, array, pass to recall function as argments */ public static function processRowsData($header, $filePath, $classFunction, $params = []) { LogUtil::info(['message' => 'Begin to read csv file', 'fileName' => $filePath], 'resque'); $fileInfos = fopen($filePath, "r"); $newFilePath = self::getDownloadFile($filePath); while (!feof($fileInfos)) { $fileInfo = Json::decode(fgets($fileInfos), true); if (!empty($fileInfo)) { $data = call_user_func_array($classFunction, [$fileInfo, $params]); //fputcsv($handle, $data); if (!isset($data[0])) { $data = [$data]; } ExcelUtil::exportCsv($header, $data, $newFilePath, 1); unset($data); } } fclose($fileInfos); LogUtil::info(['message' => 'End to read csv file and end to write file', 'fileName' => $filePath], 'resque'); }