Пример #1
0
 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;
     }
 }
Пример #2
0
 /**
  * deal with the data before export
  * @param $condition,array. (activityId:MongoId, accountId:MongoId)
  */
 public static function preProcessUserPlayCountData($condition)
 {
     $activityId = $condition['activityId'];
     $users = ActivityUser::find()->where(['activityId' => $activityId])->orderBy(['createdAt' => SORT_ASC])->all();
     $userCountArr = array();
     if (!empty($users)) {
         foreach ($users as $user) {
             if (!empty($userCountArr[$user->mobile])) {
                 $userCountArr[$user->mobile] += 1;
             } else {
                 $userCountArr[$user->mobile] = 1;
             }
         }
     }
     $rows = array();
     if (!empty($userCountArr) and is_array($userCountArr)) {
         foreach ($userCountArr as $key => $value) {
             $row = ['mobile' => "'" . $key, 'count' => $value];
             $rows[] = $row;
             unset($row);
         }
         unset($userCountArr);
     }
     return $rows;
 }
 public function actionExportBarUseRecord()
 {
     $activityId = $this->getQuery('activityId');
     $activityId = new \MongoId($activityId);
     $accountId = $this->getAccountId();
     if (empty($activityId)) {
         throw new BadRequestHttpException("activityId params missing in exporting bar use record");
     }
     $condition = ['activityId' => $activityId, 'accountId' => $accountId];
     $result = ActivityUser::find()->where($condition)->one();
     if (!empty($result)) {
         $key = '使用者拉霸記錄表_' . date('YmdHis');
         $condition = serialize($condition);
         $header = ['createdAt' => '拉霸時間', 'mobile' => '手機號碼', 'prizeContent' => '中獎內容', 'deviceId' => 'Device ID'];
         $exportArgs = ['key' => $key, 'header' => $header, 'accountId' => (string) $accountId, 'condition' => $condition, 'description' => 'Direct: export slotgame use record'];
         $jobId = Yii::$app->job->create('backend\\modules\\uhkklp\\job\\ExportBarUseRecord', $exportArgs);
         return ['result' => 'success', 'message' => 'exporting file', 'data' => ['jobId' => $jobId, 'key' => $key]];
     } else {
         LogUtil::error(['message' => '导出使用者拉霸记录表失败', 'reason' => '没有数据(no data)', 'condition' => $condition], 'activitybar');
         return ['result' => 'error', 'message' => 'no datas', 'data' => []];
     }
 }