diff --git a/server/app/admin/controller/user/App.php b/server/app/admin/controller/user/App.php new file mode 100644 index 00000000..5618d669 --- /dev/null +++ b/server/app/admin/controller/user/App.php @@ -0,0 +1,104 @@ +request->isAjax()){ + $get = $this->request->get(); + $lists = AppLogic::lists($get); + return JsonServer::success('', $lists); + } + return view(); + } + + public function add() + { + if($this->request->isAjax()) { + try{ + $post = $this->request->post(); + validate(AppValidate::class)->scene('add')->check($post); + }catch(ValidateException $e) { + return JsonServer::error($e->getError()); + } + $result = AppLogic::add($post); + if($result === true) { + return JsonServer::success('添加成功'); + } + return JsonServer::error(AppLogic::getError()); + } + + return view(); + } + + public function getUserList() + { + $keyword = input('keyword/s'); + $page = input('page/d', 1); + $size = 10; + + $q = \app\common\model\user\User::where('nickname|mobile', 'like', '%'.$keyword.'%'); + $total = $q->count(); + $userList = $q->page($page, $size) + ->field('id,nickname,mobile') + ->select() + ->toArray(); + + foreach ($userList as &$item) { + $item['name'] = $item['nickname'].'-'.$item['mobile']; + $item['value'] = $item['id']; + } + $res = [ + 'code' => 0, + 'data' => [ + 'total' => $total, + 'totalPage' => ceil($total/$size), + 'list' => $userList, + 'page' => $page, + 'size' => $size, + ], + 'msg' => 'success' + ]; + return json($res); + } + + public function edit(){ + if($this->request->isAjax()){ + try{ + $post = $this->request->post(); + validate(AppValidate::class)->scene('edit')->check($post); + }catch(ValidateException $e) { + return JsonServer::error($e->getError()); + } + $result = AppLogic::edit($post); + if($result === true) { + return JsonServer::success('编辑成功'); + } + return JsonServer::error(AppLogic::getError()); + } + + $id = $this->request->get('id', '', 'intval'); + $detail = AppLogic::getUserApi($id); + return view('', [ + 'detail' => $detail + ]); + } + + public function del() + { + $id = $this->request->post('id', '', 'intval'); + $result = AppLogic::del($id); + if($result === true) { + return JsonServer::success('删除成功'); + } + return JsonServer::error(AppLogic::getError()); + } +} \ No newline at end of file diff --git a/server/app/admin/logic/user/AppLogic.php b/server/app/admin/logic/user/AppLogic.php new file mode 100644 index 00000000..5a79415b --- /dev/null +++ b/server/app/admin/logic/user/AppLogic.php @@ -0,0 +1,105 @@ +leftJoin('user u', 'u.id = ua.user_id') + ->order('ua.id', 'desc') + ->page($get['page'], $get['limit']) + ->field('ua.*,u.nickname') + ->select() + ->toArray(); + + return ['count' => $count, 'lists' => $lists]; + } + + public static function add($post) + { + try{ + if (empty($post['user_id']) || empty($post['app_id']) || empty($post['app_secret'])) { + throw new \Exception('参数错误'); + } + $userLevel = UserApi::where(['app_id'=>trim($post['app_id'])])->findOrEmpty(); + if(!$userLevel->isEmpty()) { + throw new \Exception('APP_ID已被使用,请更换后重试'); + } + $data = [ + 'user_id' => trim($post['user_id']), + 'app_id' => trim($post['app_id']), + 'app_secret' => trim($post['app_secret']), + 'remarks' => trim($post['remarks']), + 'status' => 1, + ]; + UserApi::create($data); + User::where('id', $post['user_id'])->save([ + 'is_api' => 1 + ]); + return true; + }catch(\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function edit($post) + { + try{ + $userLevel = UserApi::where([ + ['app_id', '=', trim($post['app_id'])], + ['id', '<>', $post['id']] + ])->findOrEmpty(); + if(!$userLevel->isEmpty()) { + throw new \think\Exception('名称已被使用,请更换后重试'); + } + $data = [ + 'id' => $post['id'], + 'user_id' => trim($post['user_id']), + 'app_id' => trim($post['app_id']), + 'app_secret' => trim($post['app_secret']), + 'remarks' => trim($post['remarks']), + ]; + UserApi::update($data); + return true; + }catch(\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function del($id) + { + try{ + UserApi::where('id', $id)->delete(); + return true; + }catch(\Exception $e) { + self::$error = $e->getMessage(); + return false; + } + } + + public static function getUserApiList() + { + $levelArr = UserApi::field('id,name,phone') + ->order('id desc') + ->select() + ->toArray(); + return $levelArr; + } + + public static function getUserApi($id){ + $detail = UserApi::alias('ua')->leftJoin('user u', 'u.id=ua.user_id')->field('ua.*,u.nickname,u.mobile')->where(['ua.id'=>$id])->findOrEmpty(); + if($detail->isEmpty()) { + return []; + } + $detail = $detail->toArray(); + return $detail; + } +} \ No newline at end of file diff --git a/server/app/admin/logic/user/UserLogic.php b/server/app/admin/logic/user/UserLogic.php index 4c8d8c49..6242e686 100644 --- a/server/app/admin/logic/user/UserLogic.php +++ b/server/app/admin/logic/user/UserLogic.php @@ -36,6 +36,11 @@ class UserLogic extends Logic $where[] = ['team_id','=',$get['team_id']]; } + //是否API授权用户 + if(isset($get['is_api']) && $get['is_api'] !== ''){ + $where[] = ['is_api','=',$get['is_api']]; + } + //等级查询 if(isset($get['level']) && $get['level'] !== ''){ $where[] = ['level','=',$get['level']]; @@ -70,7 +75,7 @@ class UserLogic extends Logic $user_count = User::where($where)->count(); $user_list = User::where($where) - ->field('id,sn,nickname,avatar,level,total_order_amount,tag_ids,client,login_time,create_time,user_growth,user_money,earnings,first_leader,disable,team_id') + ->field('id,sn,nickname,avatar,level,total_order_amount,tag_ids,client,login_time,create_time,user_growth,user_money,earnings,first_leader,disable,team_id,is_api') ->page($get['page'],$get['limit']) ->order('id desc') ->select() diff --git a/server/app/admin/validate/user/AppValidate.php b/server/app/admin/validate/user/AppValidate.php new file mode 100644 index 00000000..c33dfda1 --- /dev/null +++ b/server/app/admin/validate/user/AppValidate.php @@ -0,0 +1,22 @@ + 'require', + 'user_id|用户' => 'require', + 'app_id|APP_ID' => 'require', + 'app_secret|APP_SECRET' => 'require', + ]; + + public function sceneAdd() { + return $this->only(['user_id', 'app_id', 'app_secret']); + } + + public function sceneEdit() { + return $this->only(['user_id', 'app_id', 'app_secret']); + } +} \ No newline at end of file diff --git a/server/app/admin/view/user/app/add.html b/server/app/admin/view/user/app/add.html new file mode 100644 index 00000000..3fe99928 --- /dev/null +++ b/server/app/admin/view/user/app/add.html @@ -0,0 +1,97 @@ +{layout name="layout2" /} + +
+
+ +
+
+
+
+ +
+ +
+ +

APP_ID和APP_SECRET为自动生产,如不需要则自定义输入,需要保证APP_ID全局唯一

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/server/app/admin/view/user/app/edit.html b/server/app/admin/view/user/app/edit.html new file mode 100644 index 00000000..eaaeb745 --- /dev/null +++ b/server/app/admin/view/user/app/edit.html @@ -0,0 +1,49 @@ +{layout name="layout2" /} + +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + +
+
+ \ No newline at end of file diff --git a/server/app/admin/view/user/app/lists.html b/server/app/admin/view/user/app/lists.html new file mode 100644 index 00000000..5608df9a --- /dev/null +++ b/server/app/admin/view/user/app/lists.html @@ -0,0 +1,193 @@ +{layout name="layout1" /} +
+
+
+
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+
+ + \ No newline at end of file diff --git a/server/app/admin/view/user/user/lists.html b/server/app/admin/view/user/user/lists.html index 216c770a..8e9a99f3 100644 --- a/server/app/admin/view/user/user/lists.html +++ b/server/app/admin/view/user/user/lists.html @@ -79,6 +79,16 @@ +
+ +
+ +
+
@@ -135,6 +145,10 @@ {{# } }}

业务团队:{{d.team_name}}

+ {{# if(d.is_api == 1){ }} +

API授权用户

+ {{# } }} +
@@ -233,6 +247,7 @@ $('#client').val(''); //清空输入框 $('#disable').val(''); //清空禁用状态 $('#team_id').val(''); //业务团队 + $('#is_api').val(''); //业务团队 $('#total_amount_start').val(''); //清空输入框 $('#total_amount_end').val(''); //清空输入框 $('#start_time').val(''); //清空输入框