| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace common\models\user;
- use common\components\CsvExport;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_user_import_fail_log".
- *
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_import_log_id 导入批次id
- * @property string $mobile 手机号码
- * @property string $reason 失败原因
- * @property string|null $extra 导入的内容
- * @property int $updated_at
- * @property int $created_at 添加时间
- */
- class UserImportFailLog extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_import_fail_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_import_log_id', 'updated_at', 'created_at'], 'integer'],
- [['extra'], 'string'],
- [['mobile'], 'string', 'max' => 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);
- }
- }
|