11], [['reason'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => '商城ID', 'user_import_log_id' => '导入批次id', 'mobile' => '手机号码', 'reason' => '失败原因', 'extra' => '导入的内容', 'updated_at' => 'Updated At', 'created_at' => '添加时间', ]; } /** * @param array $where * @param string $select * @param array $with * @param int $is_array * @return array|User[]|\yii\db\ActiveRecord[] */ public static function getList(array $where, $select = '*', array $with = [], int $is_array = 0) { $query = self::find(); self::paramPack(['where' => $where, 'with' => $with], $query); return $query->select($select)->asArray($is_array)->all(); } public static function packFailArr($param, $fail_arr, $fail_counts) { $fail_counts++; $param['extra'] = json_encode($param); $fail_arr[] = $param; return [$fail_arr, $fail_counts]; } /** * 保存数据 * @param array $params * @param $user_import_log_id * @return bool|UserImportFailLog */ public static function setData(array $params, $user_import_log_id) { try { foreach ($params as $param) { $model = new self(); $model->loadDefaultValues(); $param['user_import_log_id'] = $user_import_log_id; if (!$model->load($param, '') || !$model->save()) throw new Exception($model->getErrorMessage()); } return true; } catch (Exception $e) { self::$static_error = $e->getMessage(); return false; } } public static function exportFailLog($params){ $csv = new CsvExport(); $list = self::getList([['user_import_log_id' => $params['user_import_log_id']]]); $file_name = date('YmdHis', time()); $head_list = ["序号", "手机号(必填)", "昵称(最多10个字必填", '推荐人手机号(匹配不到则导入失败)', '性别(男/女)', '生日(1989/08/09或1989-08-09)', '积分(限整数)', '余额(限整数)', '备注', '失败原因']; $arr = []; foreach ($list as $k => $val) { $row = []; $extra = json_decode($val['extra'], true); $row[] = $k + 1; $row[] = $extra['mobile']; $row[] = $extra['nickname']; $row[] = $extra['parent_mobile']; $row[] = $extra['sex']; $row[] = $extra['birthday']; $row[] = $extra['source']; $row[] = $extra['balance']; $row[] = $extra['remark']; $row[] = $val['reason']; $arr[] = $row; } return $csv->export($arr, $head_list, $file_name); } }