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['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']) || 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['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; $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['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; } }
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'); }