作者 lyh

gx

@@ -19,10 +19,10 @@ use App\Models\User\User as UserModel; @@ -19,10 +19,10 @@ use App\Models\User\User as UserModel;
19 */ 19 */
20 class ProjectUserController extends BaseController 20 class ProjectUserController extends BaseController
21 { 21 {
22 - //类型  
23 - const TYPE_ONE = 1; 22 + //超级管理员
  23 + const ROLE_ID = 0;
24 /** 24 /**
25 - * @remark :用户列表 25 + * @remark :超级管理员用户列表
26 * @name :lists 26 * @name :lists
27 * @author :lyh 27 * @author :lyh
28 * @method :post 28 * @method :post
@@ -30,6 +30,7 @@ class ProjectUserController extends BaseController @@ -30,6 +30,7 @@ class ProjectUserController extends BaseController
30 */ 30 */
31 public function lists(){ 31 public function lists(){
32 $userModel = new UserModel(); 32 $userModel = new UserModel();
  33 + $this->map['role_id'] = $this::ROLE_ID;//超级管理员管理
33 $lists = $userModel->lists($this->map,$this->page,$this->row,$this->order); 34 $lists = $userModel->lists($this->map,$this->page,$this->row,$this->order);
34 if(!empty($lists)){ 35 if(!empty($lists)){
35 foreach ($lists['list'] as $k => $v){ 36 foreach ($lists['list'] as $k => $v){
@@ -60,36 +61,15 @@ class ProjectUserController extends BaseController @@ -60,36 +61,15 @@ class ProjectUserController extends BaseController
60 } 61 }
61 62
62 /** 63 /**
63 - * @param UserRequest $request  
64 - * @param UserLogic $userLogic  
65 - * @remark :添加用户  
66 - * @name :add  
67 - * @author :lyh  
68 - * @method :post  
69 - * @time :2023/6/25 9:27  
70 - */  
71 - public function add(UserRequest $request,UserLogic $userLogic){  
72 - $request->validated();  
73 - $userLogic->user_add();  
74 - $this->response('success');  
75 - }  
76 -  
77 - /**  
78 - * @param UserRequest $request  
79 - * @param UserLogic $userLogic  
80 - * @remark :编辑用户 64 + * @remark :保存用户
81 * @name :edit 65 * @name :edit
82 * @author :lyh 66 * @author :lyh
83 * @method :post 67 * @method :post
84 * @time :2023/6/25 9:28 68 * @time :2023/6/25 9:28
85 */ 69 */
86 - public function edit(UserRequest $request,UserLogic $userLogic){  
87 - $request->validate([  
88 - 'id'=>'required'  
89 - ],[  
90 - 'id.required' => 'ID不能为空'  
91 - ]);  
92 - $userLogic->user_edit(); 70 + public function save(UserRequest $request,UserLogic $userLogic){
  71 + $request->validated();
  72 + $userLogic->projectUserSave();
93 $this->response('success'); 73 $this->response('success');
94 } 74 }
95 75
@@ -14,7 +14,6 @@ class UserLogic extends BaseLogic @@ -14,7 +14,6 @@ class UserLogic extends BaseLogic
14 public function __construct() 14 public function __construct()
15 { 15 {
16 parent::__construct(); 16 parent::__construct();
17 -  
18 $this->model = new User(); 17 $this->model = new User();
19 $this->param = $this->requestAll; 18 $this->param = $this->requestAll;
20 } 19 }
@@ -25,36 +24,48 @@ class UserLogic extends BaseLogic @@ -25,36 +24,48 @@ class UserLogic extends BaseLogic
25 * @author :liyuhang 24 * @author :liyuhang
26 * @method 25 * @method
27 */ 26 */
28 - public function user_info(){  
29 - $info = Common::get_user_cache($this->model,$this->param['id'],'A');  
30 - if(empty($info)){  
31 - $info = $this->model->read($this->param,['id','project_id','name','status','mobile','operator_id']);  
32 - if($info === false){ 27 + public function user_info()
  28 + {
  29 + $info = Common::get_user_cache($this->model, $this->param['id'], 'A');
  30 + if (empty($info)) {
  31 + $info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'mobile', 'operator_id']);
  32 + if ($info === false) {
33 $this->fail('当前数据不存在'); 33 $this->fail('当前数据不存在');
34 } 34 }
35 - $userModel = new UserModel();  
36 - $info['operator_name'] = $userModel->read(['id'=>$info['operator_id']],['name'])['name'];  
37 - $info['project_name'] = (new Project())->read(['id'=>$info['project_id']],['title'])['title'];  
38 - Common::set_user_cache($info,$this->model,$this->param['id'],'A'); 35 + $info['project_name'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title'];
  36 + Common::set_user_cache($info, $this->model, $this->param['id'], 'A');
39 } 37 }
40 return $this->success($info); 38 return $this->success($info);
41 } 39 }
  40 +
42 /** 41 /**
43 * @name :添加会员 42 * @name :添加会员
44 * @return void 43 * @return void
45 * @author :liyuhang 44 * @author :liyuhang
46 * @method 45 * @method
47 */ 46 */
48 - public function user_add(){  
49 - //验证当前项目是否已存在超级管理员  
50 - $info = $this->model->read(['project_id'=>$this->param['project_id'],'role_id'=>0]);  
51 - if($info !== false){  
52 - $this->fail('一个项目只允许一个超级管理员'); 47 + public function projectUserSave()
  48 + {
  49 + if (isset($this->param['id']) && !empty($this->param['id'])) {
  50 + $info = $this->model->read(['mobile' => $this->param['mobile'], 'id' => ['!=', $this->param['id']]]);
  51 + if ($info !== false) {
  52 + $this->fail('当前手机号码已存在');
  53 + }
  54 + $this->param = $this->editPassword($this->param);
  55 + $rs = $this->model->edit($this->param, ['id' => $this->param['id']]);
  56 + } else {
  57 + $info = $this->model->read(['mobile'=>$this->param['mobile']]);
  58 + if($info !== false){
  59 + $this->fail('当前手机号码已存在');
  60 + }
  61 + $info = $this->model->read(['project_id'=>$this->param['id'],'role_id'=>0]);
  62 + if($info !== false){
  63 + $this->fail('当前项目已存在超级管理员,请选择其他项目');
  64 + }
  65 + $this->param['password'] = base64_encode(md5($this->param['password']));
  66 + $rs = $this->model->add($this->param);
53 } 67 }
54 - $this->verifyMobile();//验证手机号  
55 - $this->param['password'] = base64_encode(md5($this->param['password']));  
56 - $rs = $this->model->add($this->param);  
57 - if($rs === false){ 68 + if ($rs === false) {
58 $this->fail('添加失败'); 69 $this->fail('添加失败');
59 } 70 }
60 return $this->success(); 71 return $this->success();
@@ -66,21 +77,16 @@ class UserLogic extends BaseLogic @@ -66,21 +77,16 @@ class UserLogic extends BaseLogic
66 * @author :liyuhang 77 * @author :liyuhang
67 * @method 78 * @method
68 */ 79 */
69 - public function user_edit(){  
70 - $this->verifyMobile();//验证手机号 80 + public function editPassword($param)
  81 + {
71 //验证密码是否更改 82 //验证密码是否更改
72 - if(isset($this->param['password']) && !empty($this->param['password'])){  
73 - $info = $this->model->read(['id'=>$this->param['id']]);  
74 - if($info['password'] != $this->param['password']){  
75 - $this->param['password'] = base64_encode(md5($this->param['password'])); 83 + if (isset($param['password']) && !empty($param['password'])) {
  84 + $info = $this->model->read(['id' => $param['id']]);
  85 + if ($info['password'] != $param['password']) {
  86 + $param['password'] = base64_encode(md5($param['password']));
76 } 87 }
77 } 88 }
78 - $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);  
79 - if($rs === false){  
80 - $this->fail('编辑失败');  
81 - }  
82 - Common::del_user_cache($this->model,$this->param['id'],'A');  
83 - return $this->success(); 89 + return $this->success($param);
84 } 90 }
85 91
86 /** 92 /**
@@ -89,36 +95,15 @@ class UserLogic extends BaseLogic @@ -89,36 +95,15 @@ class UserLogic extends BaseLogic
89 * @author :liyuhang 95 * @author :liyuhang
90 * @method 96 * @method
91 */ 97 */
92 - public function user_del(){ 98 + public function user_del()
  99 + {
93 $ids = $this->param['id']; 100 $ids = $this->param['id'];
94 - $this->param['id'] = ['in',$this->param['id']]; 101 + $this->param['id'] = ['in', $this->param['id']];
95 $rs = $this->model->del($this->param); 102 $rs = $this->model->del($this->param);
96 - if($rs === false){ 103 + if ($rs === false) {
97 $this->fail('删除失败'); 104 $this->fail('删除失败');
98 } 105 }
99 - Common::del_user_cache($this->model,$ids,'A'); 106 + Common::del_user_cache($this->model, $ids, 'A');
100 return $this->success(); 107 return $this->success();
101 } 108 }
102 -  
103 - /**  
104 - * @remark :验证手机号  
105 - * @name :verifyMobile  
106 - * @author :lyh  
107 - * @method :post  
108 - * @time :2023/6/25 9:47  
109 - */  
110 - public function verifyMobile(){  
111 - if(isset($this->param['id']) && !empty($this->param['id'])){  
112 - $info = $this->model->read(['mobile'=>$this->param['mobile'],'id'=>['!=',$this->param['id']]]);  
113 - if($info !== false){  
114 - $this->fail('当前手机号码已存在');  
115 - }  
116 - }else{  
117 - $info = $this->model->read(['mobile'=>$this->param['mobile']]);  
118 - if($info !== false){  
119 - $this->fail('当前手机号码已存在');  
120 - }  
121 - }  
122 - return true;  
123 - }  
124 } 109 }
@@ -16,8 +16,7 @@ Route::middleware(['aloginauth'])->group(function () { @@ -16,8 +16,7 @@ Route::middleware(['aloginauth'])->group(function () {
16 //会员管理 16 //会员管理
17 Route::any('/', [Aside\User\ProjectUserController::class, 'lists'])->name('admin.user_lists'); 17 Route::any('/', [Aside\User\ProjectUserController::class, 'lists'])->name('admin.user_lists');
18 Route::any('/info', [Aside\User\ProjectUserController::class, 'info'])->name('admin.user_info'); 18 Route::any('/info', [Aside\User\ProjectUserController::class, 'info'])->name('admin.user_info');
19 - Route::any('/add', [Aside\User\ProjectUserController::class, 'add'])->name('admin.user_add');  
20 - Route::any('/edit', [Aside\User\ProjectUserController::class, 'edit'])->name('admin.user_edit'); 19 + Route::any('/save', [Aside\User\ProjectUserController::class, 'save'])->name('admin.user_save');
21 Route::any('/del', [Aside\User\ProjectUserController::class, 'del'])->name('admin.user_del'); 20 Route::any('/del', [Aside\User\ProjectUserController::class, 'del'])->name('admin.user_del');
22 21
23 //角色管理 22 //角色管理