diff --git a/app/BaseApp/BaseController.php b/app/BaseApp/BaseController.php index b0d20feb..4f7490bf 100755 --- a/app/BaseApp/BaseController.php +++ b/app/BaseApp/BaseController.php @@ -147,7 +147,7 @@ class BaseController if (mb_strlen(strval($checkValue)) <= 0 && !in_array($fieldName, $this->notRequest)) { $requiredFields[] = $fieldName; } else { - if (!empty($checkValue)) { + if (!empty($checkValue) || $checkValue === 0) { $result[$fieldName] = $checkValue; } } diff --git a/app/BaseApp/BaseService.php b/app/BaseApp/BaseService.php index 52aa52bd..16f35c25 100755 --- a/app/BaseApp/BaseService.php +++ b/app/BaseApp/BaseService.php @@ -76,6 +76,11 @@ class BaseService */ protected array $optionField = ['id', 'name']; + /** + * @var array 下拉列表字段 + */ + protected array $queryField = []; + /** * @var array 关联加载 */ diff --git a/app/Http/Controllers/LoginController.php b/app/Http/Controllers/LoginController.php index 5405c166..ce1c49ff 100644 --- a/app/Http/Controllers/LoginController.php +++ b/app/Http/Controllers/LoginController.php @@ -24,7 +24,7 @@ class LoginController extends BaseController public function login() { $this->insertField = [ - 'account', 'password', 'is_remember' + 'account', 'password', 'remember' ]; $param = $this->checkRequiredFields(request()->post()); diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php new file mode 100644 index 00000000..e03c6406 --- /dev/null +++ b/app/Http/Controllers/ProjectController.php @@ -0,0 +1,19 @@ +service = ProjectService::getInstance(); + $this->insertField = [ 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status']; + $this->updateField = [ 'id', 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status']; + } +} diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php new file mode 100644 index 00000000..5133dce9 --- /dev/null +++ b/app/Http/Controllers/RoleController.php @@ -0,0 +1,20 @@ +service = RoleService::getInstance(); + $this->insertField = [ 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status']; + $this->updateField = [ 'id', 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status']; + } +} diff --git a/app/Service/LoginService.php b/app/Service/LoginService.php index dba71d8a..a68c1e9f 100644 --- a/app/Service/LoginService.php +++ b/app/Service/LoginService.php @@ -39,7 +39,7 @@ class LoginService */ public function login($account, $password) { - $userModel = UserModel::where('account', $account)->first(); + $userModel = UserModel::with(['roles:id,name,value'])->where('account', $account)->first(); if (empty($userModel)) { UtilsService::getInstance()->errorThrow('用户或密码错误!'); // return $this->register($account, $password); @@ -72,6 +72,8 @@ class LoginService 'nick_name' => $userModel->nick_name, 'avatar' => $userModel->avatar, 'email' => $userModel->email, + 'role_name' => $userModel->roles->name, + 'role_value' => $userModel->roles->value, 'ip' => $userModel->ip, 'ip_table' => $userModel->ip_table, ]; @@ -99,6 +101,7 @@ class LoginService 'password' => password_hash($password, PASSWORD_DEFAULT), 'nick_name' => '新用户'. Str::random(), 'avatar' => 'https://pic.rmb.bdstatic.com/bjh/80852bfe7c321988191838517ba64e309354.jpeg@h_1280', + 'role_id' => 2, 'ip' => get_ip(), 'ip_table' => json_encode([get_ip()]), 'created_at' => get_time() @@ -114,6 +117,8 @@ class LoginService 'nick_name' => $createModel->nick_name, 'avatar' => $createModel->avatar, 'email' => $userModel->email?? '', + 'role_name' => $userModel->roles->name, + 'role_value' => $userModel->roles->value, 'ip' => $createModel->ip, 'ip_table' => $createModel->ip_table, ]; diff --git a/app/Service/ProjectService.php b/app/Service/ProjectService.php new file mode 100644 index 00000000..84281f97 --- /dev/null +++ b/app/Service/ProjectService.php @@ -0,0 +1,93 @@ +selectField = [ 'id', 'user_id', 'title', 'cover', 'description', 'video_url', 'author_id', 'price', 'preferential_price', 'front', 'service', 'deploy', 'status', 'created_at', 'updated_at', 'deleted_at', ]; + $this->model = ProjectModel::class; + } + + /** + * 获取项目列表 + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function list(): array + { + $this->with = [ + 'frameworks:id,name', + 'labels:id,name', +// 'features:id,project_id,name' + ]; + return $this->getPageList(); + } + + public function detail($id) + { + $this->with = [ + 'frameworks:id,name', + 'labels:id,name', + 'features:id,project_id,name' + ]; + return $this->getDetail($id); + } + + /** + * 项目下拉列表 + * @return mixed + */ + public function option() + { + $this->optionField = ['id', 'title']; + return $this->getOption(); + } + + /** + * 创建项目 + * @param $params + * @return mixed + * @throws Exception + */ + public function create($params): mixed + { + $params['user_id'] = $this->userId; + $params['author_id'] = $params['author_id']?? $this->userId; + return $this->insert($params); + } + + /** + * 编辑项目 + * @param $id + * @param $params + * @return mixed + * @throws Exception + */ + public function update($id, $params): mixed + { + return $this->save($id, $params); + } + + /** + * 删除项目 + * @param $ids + * @return mixed|true + * @throws Exception + */ + public function delete($ids): mixed + { + return $this->del($ids); + } + +} diff --git a/app/Service/RoleService.php b/app/Service/RoleService.php new file mode 100644 index 00000000..5baec14c --- /dev/null +++ b/app/Service/RoleService.php @@ -0,0 +1,82 @@ +selectField = ['id', 'name', 'value', 'pid', 'desc', 'created_at', 'updated_at', 'deleted_at']; + $this->model = RoleModel::class; + } + + /** + * 获取项目列表 + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ + public function list(): array + { + return $this->getPageList(); + } + + public function detail($id) + { + return $this->getDetail($id); + } + + /** + * 项目下拉列表 + * @return mixed + */ + public function option() + { + $this->optionField = ['id', 'name']; + return $this->getOption(); + } + + /** + * 创建项目 + * @param $params + * @return mixed + * @throws Exception + */ + public function create($params): mixed + { + return $this->insert($params); + } + + /** + * 编辑项目 + * @param $id + * @param $params + * @return mixed + * @throws Exception + */ + public function update($id, $params): mixed + { + return $this->save($id, $params); + } + + /** + * 删除项目 + * @param $ids + * @return mixed|true + * @throws Exception + */ + public function delete($ids): mixed + { + return $this->del($ids); + } + +} diff --git a/app/Service/UserService.php b/app/Service/UserService.php index 1499ee8d..b8f4f177 100644 --- a/app/Service/UserService.php +++ b/app/Service/UserService.php @@ -16,6 +16,13 @@ class UserService extends BaseService parent::__construct(); $this->selectField = [ 'id', 'account', 'nick_name', 'avatar', 'email', 'balance', 'qr_code', 'role_id', 'ip', 'ip_table', 'status', 'last_reset_password_at', 'created_at', 'updated_at', 'deleted_at', ]; $this->model = UserModel::class; + $this->queryField = [ + 'account' => 'like', + 'nick_name' => 'like', + 'email' => 'like', + 'role_id' => '=', + 'status' => '=', + ]; } /** @@ -26,11 +33,15 @@ class UserService extends BaseService */ public function list(): array { + $this->with = [ + 'roles' + ]; $result = $this->getPageList(); foreach ($result['items'] as &$v) { $v['ip_table'] = json_decode($v['ip_table'], true); $v['status_text'] = UserStatusEnum::from($v['status'])->description(); + $v['last_reset_password_at'] = format_time($v['last_reset_password_at']); } return $result; diff --git a/config/helpers.php b/config/helpers.php index 808e38cd..88b4674c 100755 --- a/config/helpers.php +++ b/config/helpers.php @@ -490,3 +490,15 @@ if (!function_exists('get_time')) { return $isString === true ? date($format) : time(); } } + +/** + * 格式化 + * + * @return array + */ +if (!function_exists('format_time')) { + function format_time($time, $format = 'Y-m-d H:i:s'): string + { + return !empty($time)? date($format, $time) : ''; + } +} diff --git a/routes/api.php b/routes/api.php index d6cd98bd..85a733c2 100644 --- a/routes/api.php +++ b/routes/api.php @@ -17,5 +17,7 @@ UtilsService::class::getInstance()->autoRouteRegister([ Route::group([], function () { UtilsService::class::getInstance()->autoRouteRegister([ 'user' => \App\Http\Controllers\UserController::class, // 用户控制器 + 'project' => \App\Http\Controllers\ProjectController::class, // 项目控制器 + 'role' => \App\Http\Controllers\RoleController::class, // 角色控制器 ]); }); diff --git a/routes/web.php b/routes/web.php index f35ab5bb..86a06c53 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,12 +3,5 @@ use Illuminate\Support\Facades\Route; Route::get('/', function () { -// -// $framework = \App\Models\ProjectModel::with([ -// 'frameworks', -// 'labels', -// 'technologyStacks', -// ])->get(); -// ds($framework); return view('welcome'); });