diff --git a/app/admin/controller/UserController.php b/app/admin/controller/UserController.php new file mode 100644 index 0000000..33baa25 --- /dev/null +++ b/app/admin/controller/UserController.php @@ -0,0 +1,53 @@ +service = new UserService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if(isset($data['records'])){ + return $data; + } + $data['sex_txt'] = ''; + if (isset($data['sex']) && $data['sex'] == 1){ + $data['sex_txt'] = '男'; + }elseif(isset($data['sex']) && $data['sex'] == 2){ + $data['sex_txt'] = '女'; + } + + switch ($data['status']){ + case 1: + $data['status_txt'] = '正常'; + break; + case 2: + $data['status_txt'] = '离职'; + break; + default: + $data['status_txt'] = ''; + break; + } + + $data['customer_count'] = Customer::where('user_id', $data['id'])->count(); + return $data; + } +} \ No newline at end of file diff --git a/app/admin/logic/UserLogic.php b/app/admin/logic/UserLogic.php new file mode 100644 index 0000000..de0d15d --- /dev/null +++ b/app/admin/logic/UserLogic.php @@ -0,0 +1,17 @@ +validator; + } + + + /** + * 构造 CrudUtil 查询配置 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'default': + $config['where']['status'] = 1; + $config['order']['id'] = 'desc'; + break; + case 'index': + $config['where']['status'] = 1; + $config['order']['id'] = 'desc'; + $config['fields'] = ['id', 'name', 'email', 'sex', 'phone', 'avatar', 'corp_id', 'country_id', 'position', 'status', 'created_at']; + break; + case 'show': + $config['where']['id'] = $p['id']; + $config['where']['status'] = 1; + break; + case 'store': + break; + case 'update': + $config['where']['id'] = $p['id']; + break; + case 'destroy': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } +} \ No newline at end of file diff --git a/app/admin/validate/UserValidate.php b/app/admin/validate/UserValidate.php new file mode 100644 index 0000000..e478c5b --- /dev/null +++ b/app/admin/validate/UserValidate.php @@ -0,0 +1,29 @@ + [ + + ], + + 'update' => [ + + ] + ]; +} \ No newline at end of file diff --git a/config/route.php b/config/route.php index 5d0fa46..fb27d10 100644 --- a/config/route.php +++ b/config/route.php @@ -71,6 +71,12 @@ Route::group('/admin', function () { Route::any('/update', [app\admin\controller\RoleController::class, 'update']); Route::any('/destroy', [app\admin\controller\RoleController::class, 'destroy']); }); + + // 用户 + Route::group('/user', function () { + Route::any('/list', [app\admin\controller\UserController::class, 'index']); + }); + // 公司 Route::group('/corp', function () { Route::any('/list', [app\admin\controller\CorpController::class, 'index']);