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,"更新失败"); } }