123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\BaseController;
- use think\facade\Db;
- use think\App;
- //管理员权限分组
- class Group extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
- /**
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function GroupList(){
- $post =$this->post;
- $token = isset($post['token']) ? trim($post['token']) : "";
- $page = isset($post['page']) ? intval($post['page']): 1;
- $size = isset($post['size']) ? intval($post['size']):10;
- $condition=['is_del'=>0];
- $count = Db::name("role_group")->where($condition)->count();
- $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
- $list = Db::name("role_group")->where($condition)->page($page,$size)->order('addtime','desc')->select()->toArray();
- $data =[];
- foreach ($list as $key=>$val) {
- $userlist = [];
- if ($val['group_user'] != "") {
- $cond = ['id' => explode(",",$val['group_user'])];
- $user = GetUserlist($token, $cond);
- if ($user['code'] == 0 && !empty($user['data'])) {
- foreach ($user['data'] as $v) {
- $userlist[] = isset($v['nickname']) ?$v['nickname']:"";
- }
- }
- }
- $val['userlist']= $userlist;
- $data[] = $val;
- }
- return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
- }
- /**
- * @return \think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function GroupAll(){
- $post =$this->post;
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $condition=[];
- isset($post['name']) && $post['name']!=="" ? $condition[]= ['group_name',"like","%{$post['name']}%"] : "";
- isset($post['status']) && $post['status']!=="" ? $condition[] = ['status',"=",$post['status']] : "";
- $list = Db::name("role_group")->where($condition)->select();
- $data =[];
- foreach ($list as $key=>$val) {
- $userlist = [];
- if ($val['group_user'] != "") {
- $cond = ['id' => explode(",",$val['group_user'])];
- $user = GetUserlist($token, $cond);
- if ($user['code'] == 0 && !empty($user['data'])) {
- foreach ($user['data'] as $v) {
- $userlist[] = isset($v['nickname']) ?$v['nickname']:"";
- }
- }
- }
- $val['userlist']= $userlist;
- $data[] = $val;
- }
- return app_show(0,"获取成功",$data);
- }
- /**@param id
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function GroupInfo(){
- $post =$this->post;
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $id = isset($post['id']) ? intval($post['id']) : "";
- if($id==""){
- return error_show(1002,"用户组id不能为空");
- }
- $group = Db::name("role_group")->where("id","=",$id)->find();
- if(!$group){
- return error_show(1003,"未找到对应的数据");
- }
- $userlist=[];
- if($group['group_user']!=""){
- $cond = ['id' => explode(",",$group['group_user'])];
- $user = GetUserlist($token, $cond);
- if ($user['code'] == 0&& !empty($user['data'])) {
- foreach ($user['data'] as $v) {
- $userlist[] = isset($v['nickname']) ?$v['nickname']:"";
- }
- }
- }
- $group['userlist'] = $userlist;
- return app_show(0,"获取成功",$group);
- }
- /**
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function GroupAdd(){
- $post =$this->post;
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $groupname = isset($post['name']) ? trim($post['name']):"";
- if($groupname==""){
- return error_show(1002,"用户组名不能为空");
- }
- $groupuser = isset($post['group_user']) ? trim($post['group_user']):"";
- if($groupuser==""){
- return error_show(1002,"组成员不能为空");
- }
- $marke = isset($post['group_remark']) ? trim($post['group_remark']):"";
- $list = ['group_name'=>$groupname];
- $select = Db::name("role_group")->where($list)->find();
- if($select){
- return error_show(1003,"用户组名称已存在");
- }
- $data= [
- 'group_name'=>$groupname,
- 'group_user'=>$groupuser,
- 'status'=>1,
- 'group_remark'=>$marke,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $in = Db::name("role_group")->save($data);
- // $orde = ["order_code"=>$groupuser,"status"=>$in['status'],"action_remark"=>'',"action_type"=>"create"];
- // ActionLog::logAdd($token,$orde,'role_group',1,$orde);
- return $in ? app_show(0,"新建成功"): error_show(1005,"新建失败");
- }
- /**
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function GroupSave(){
- $post =$this->post;
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $groupid = isset($post['id']) ? intval($post['id']):"";
- if($groupid==""){
- return error_show(1002,"用户组id不能为空");
- }
- $groupname = isset($post['name']) ? trim($post['name']):"";
- if($groupname==""){
- return error_show(1002,"用户组名不能为空");
- }
- $groupuser = isset($post['group_user']) ? trim($post['group_user']):"";
- if($groupuser==""){
- return error_show(1002,"组成员不能为空");
- }
- $marke = isset($post['group_remark']) ? trim($post['group_remark']):"";
- $list = ['group_name'=>$groupname];
- $select =Db::name("role_group")->where($list)->find();
- if($select && $select['id']!=$groupid){
- return error_show(1003,"用户组名称已存在");
- }
- $data= [
- "id"=>$groupid,
- 'group_name'=>$groupname,
- 'group_user'=>$groupuser,
- 'group_remark'=>$marke,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $in = Db::name("role_group")->save($data);
- // $orde = ["order_code"=>$groupname,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
- // ActionLog::logAdd($token,$orde,'role_group',0,$orde);
- return $in ? app_show(0,"更新成功"): error_show(1005,"更新失败");
- }
- /**
- * @return \think\response\Json
- * @throws \think\exception\DbException
- */
- public function GroupStatus(){
- $post =$this->post;
- $token = isset($post['token']) ? trim($post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $groupid = isset($post['id']) ? intval($post['id']):"";
- if($groupid==""){
- return error_show(1002,"用户组id不能为空");
- }
- $status = isset($post['status']) ? intval($post['status']) : "";
- if($status===""){
- return error_show(1001,'status不能为空');
- }
- if(!in_array($status,[0,1])){
- return error_show(1001,'status参数非法');
- }
- $data= [
- "id"=>$groupid,
- "status"=>$status,
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $in = Db::name("role_group")->save($data);
- // $orde = ["order_code"=>$groupid,"status"=>$status,"action_remark"=>'',"action_type"=>"edit"];
- // ActionLog::logAdd($token,$orde,'role_group',$status,$orde);
- return $in ? app_show(0,"更新成功"): error_show(1005,"更新失败");
- }
- }
|