11], [['commission'], 'string', 'max' => 64], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城ID', 'hand_bouns_id' => '导入ID,qimall_addons_hand_bouns.id', 'mobile' => '手机号码', 'balance' => '余额', 'score' => '积分', 'commission' => '佣金', 'status' => '0是禁用,1是导入成功,2是导入失败', 'export_status' => '导入状态,0是正在处理中,1是导入成功,2是导入失败', 'created_at' => '创建时间', 'updated_at' => '修改时间', 'reason' => '失败的原因', ]; } /** * @Author: ltm * @DateTime: 2022/3/7 0007 11:31 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $data * @return string */ public static function setData($mall_id, $params = null) { try { if (empty($params)) { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $mall_id; $model->period_num = self::getPrevPeriodNum($mall_id); } else { $model = self::findOne(['id' => $params['id']]); } if ($params && !$model->load($params, '')) throw new Exception($model->getErrorMessage()); if (!$model->save()) throw new Exception($model->getErrorMessage()); return $model->id; } catch (\Exception $e) { return false; } } /** * 失败分红导出 * @Author: ltm * @DateTime: 2022/3/7 0007 14:58 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $data * @return string */ public static function exportHandle(array $data) { $download_id = $data['download_id'] ?? 0; $download = Download::findOne(['id' => $download_id]); if ($download) { try { $params = json_decode($download->params,true); $filename = $download->name; $type = $download->type; $list = self::find()->select("mobile,balance,score,commission,reason")->where(['mall_id' => $params['mall_id'], 'hand_bouns_id' => $params['hand_bouns_id'], 'export_status' => $params['style']])->asArray()->all(); if($params['style'] == 1){ // 成功 $have_select_field_arr = ['手机号码', '余额','佣金','积分']; }else{ // 失败 $have_select_field_arr = ['手机号码', '余额','佣金','积分','失败原因']; } $csv = new CsvTool(); $csv->filename = $filename; $csv->file_dirname = DownloadEnum::getTypeStorageDirMap($type); $csv->export_mode = CsvTool::EXPORT_MODE_ASYNC; $csv->header = $have_select_field_arr; foreach ($list as $item) { is_numeric($item['id']) && $item['id'] = $item['id'] . "\t"; $rows[] = $item; } $csv->data = $rows; $csv->export(); $csv->updateDown($download,$params['mall_id']); return true; } catch (\Exception $e) { $download->status = 3; $res = $download->save(); self::setStaticError($e->getMessage()); return $e->getMessage(); } } } }