'会员ID', 'nickname' => '昵称', 'username' => '用户名', 'mobile' => '手机号', 'real_name' => '姓名', 'id_no' => '证件号', 'created_at' => '认证时间', ]; if ($field === null) return $fields; $temp = []; foreach ($field as $val) { if (isset($fields[$val])) $temp[$val] = $fields[$val]; } return $temp; } /** * {@inheritdoc} */ public function rules() { return [ [['mall_id', 'user_id', 'id_type', 'auth', 'created_at','updated_at','auth_type'], 'integer'], [['real_name','id_no'], 'string', 'max' => 64], [['auth_result','business_code'], 'string'], ]; } public static function getUser($mall_id,$user_id,$auth_type=0) { $query = self::find()->where(['mall_id' => $mall_id,'user_id' =>$user_id]); if($auth_type){ $query->andWhere(['=','auth_type',$auth_type]); } return $query->one(); } public static function getUserByInfo($mall_id, $user_id, $real_name, $id_no, $auth_type=0) { $query = self::find()->where(['mall_id' => $mall_id,'user_id' =>$user_id, 'real_name' => trim($real_name), 'id_no' => trim($id_no)]); if($auth_type){ $query->andWhere(['=','auth_type',$auth_type]); } return $query->one(); } /** * @param array $data * @return int * @throws \Exception */ public static function setData(array $data) { if(isset($data['id']) && $data['id'] > 0 ){ $model = self::findOne([ 'id' => $data['id']]); if(!$model){ throw new \Exception('记录不存在'); } }else{ $model = self::findOne(['mall_id' => $data['mall_id'], 'user_id' => $data['user_id']]); if(!$model){ $model = new self(); } } $model->attributes = $data; if (!$model->save()) { throw new \Exception($model->getErrorMessage()); } return $model->id; } public static function exportHandle(array $data) { date_default_timezone_set('Asia/Shanghai'); $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; $model = RealAuthUser::find(); $model->where(['mall_id' => $params['mall_id']]); if (!empty($params['user_id'])) $model->andWhere(['=', 'user_id', $params['user_id']]); if (!empty($params['real_name'])) $model->andWhere(['=', 'real_name', $params['real_name']]); if (!empty($params['id_no'])) $model->andWhere(['=', 'id_no', $params['id_no']]); if (!empty($params['data'])) { list($start, $end) = $params['data']; $end .= ' 23:59:59'; $model->andWhere(['between', 'created_at', strtotime($start), strtotime($end)]); } $fields = $params['fields']; $fields_arr = self::fieldsList(); $have_select_field_arr = []; foreach ($fields as $value) { if (isset($fields_arr[$value])) $have_select_field_arr[] = $fields_arr[$value]; } $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; $i = 1; $page_size = 1000; while ($list = $model ->offset(($i - 1) * $page_size)->limit($page_size)->orderBy('id asc')->all()) { $user_ids = array_column($list, 'user_id'); $users = User::lists(['where' => [['id' => $user_ids]], 'index' => 'id']); $csv->data = array_map(function ($real_auth_user) use ($fields, $users) { $row = []; foreach ($fields as $field) { switch (true) { case (in_array($field, ['created_at'])): $row[] = !empty($real_auth_user[$field]) ? date('Y-m-d H:i:s', $real_auth_user[$field]) : ''; break; case (in_array($field, ['id_no'])): $row[] = !empty($real_auth_user[$field]) ? $real_auth_user[$field] . "\t" : ''; break; case (in_array($field, ['nickname', 'username', 'mobile'])): if (isset($users[$real_auth_user['user_id']])) { $row[] = $users[$real_auth_user['user_id']][$field] . "\t"; } else { $row[] = ''; } break; default: $row[] = !empty($real_auth_user[$field]) ? $real_auth_user[$field] : ''; } } return $row; }, $list); $csv->export(); $i++; } $csv->updateDown($download, $params['mall_id']); return true; } catch (\Exception $e) { $download->status = 3; $res = $download->save(); \Yii::error($e->getMessage() . $e->getFile() . $e->getLine()); self::setStaticError($e->getMessage()); return $e->getMessage(); } } } }