Esempio n. 1
0
 public function actionExport()
 {
     $params = $this->getQuery();
     $accountId = $this->getAccountId();
     if (!empty($params['cardStates'])) {
         $params['cardExpiredAt'] = Member::getCardExpiredTime($params);
     }
     $where = Member::getCondition($params, $accountId);
     $condition = $where['condition'];
     //only export enable member
     $condition['isDisabled'] = ['$ne' => true];
     if (!empty($where['cardStatusCondition'])) {
         $condition = ['and', $condition, $where['cardStatusCondition']];
     }
     if (!empty($where['searchCondition'])) {
         $condition = ['and', $condition, $where['searchCondition']];
     }
     $result = Member::find()->where($condition)->one();
     if (!empty($result)) {
         $key = Yii::t('product', 'export_member_file_name') . '_' . date('YmdHis');
         $headerTitle = Yii::t('member', 'member_export_title');
         $headerValue = explode(',', $headerTitle);
         $header = ['cardNumber', 'cardName', 'score', 'totalScore', 'totalScoreAfterZeroed', 'costScoreAfterZeroed', 'channel', 'createdAt', 'tag'];
         $showHeader = array_combine($header, $headerValue);
         $exportArgs = ['key' => $key, 'header' => $showHeader, 'accountId' => (string) $accountId, 'condition' => serialize($condition), 'description' => 'Direct: export member', 'params' => $params];
         $jobId = Yii::$app->job->create('backend\\modules\\member\\job\\ExportMember', $exportArgs);
         return ['result' => 'success', 'message' => 'exporting file', 'data' => ['jobId' => $jobId, 'key' => $key]];
     } else {
         throw new BadRequestHttpException(Yii::t('member', 'export_member_failed'));
         //return ['result' => 'member_error', 'message' => 'no datas', 'data' => []];
     }
 }