|
|
@@ -1,181 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace App\Http\Controllers\AdminApi;
|
|
|
-
|
|
|
-use App\Models\SysModels\Menu;
|
|
|
-use App\Models\UserModels\Role;
|
|
|
-use App\Models\UserModels\User;
|
|
|
-use App\Http\Controllers\AdminController;
|
|
|
-use App\Servers\Common\MenuServer;
|
|
|
-use App\Servers\Common\RedisDataServer;
|
|
|
-
|
|
|
-class RoleController extends AdminController
|
|
|
-{
|
|
|
-
|
|
|
- /**
|
|
|
- * 后台账号列表
|
|
|
- * @return \Illuminate\Http\JsonResponse
|
|
|
- */
|
|
|
- function getList(){
|
|
|
- $status = request()->input('status', 0);//是否通过 1启用 2停用
|
|
|
- $search = request()->input('search', '');//搜索的内容
|
|
|
- $start = request()->input('start', '');//获取开始时间
|
|
|
- $end = request()->input('end', '');//获取结束时间
|
|
|
-
|
|
|
- //获取店铺角色列表
|
|
|
- $where = [['is_del',0]];
|
|
|
- if(in_array($status,[1,2])) $where[] = ['status','=',$status];
|
|
|
-
|
|
|
- if ($search) $where[] = ['name', 'like', "%$search%"];
|
|
|
- if ($start) $where[] = ['created_at', '>=', $start . ' 00:00:00'];
|
|
|
- if ($end) $where[] = ['created_at', '<=', $end . ' 23:59:59'];
|
|
|
-
|
|
|
- $list = Role::where($where)
|
|
|
- ->select(['id','name','status','created_at'])
|
|
|
- ->orderBy('created_at','desc')
|
|
|
- ->paginate(10);
|
|
|
- foreach ($list as $value){
|
|
|
- $value['count'] = User::where('role_id',$value['id'])->where('is_del',0)->count();
|
|
|
- }
|
|
|
- return $this->apiResponseSuccess('获取信息成功', [
|
|
|
- 'list' => $list->items(),
|
|
|
- 'total' => $list->total(),
|
|
|
- 'limit' => 10
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增&编辑店铺角色
|
|
|
- * @return \Illuminate\Http\JsonResponse
|
|
|
- */
|
|
|
- function saveRole(){
|
|
|
- $id = request()->input('id','');//记录id
|
|
|
- $name = request()->input('name','');//名称
|
|
|
- $status = request()->input('status',1);//状态1启用 2停用
|
|
|
- $permission_ids = request()->input('ids','');//权限节点id
|
|
|
-
|
|
|
- if (empty($name)) return $this->apiResponseError( '角色名称必填');
|
|
|
- if (empty($permission_ids)) return $this->apiResponseError( '请选择权限节点');
|
|
|
- if(!in_array($status,[1,2])) return $this->apiResponseError( '状态错误');
|
|
|
-
|
|
|
- if(is_array($permission_ids)){
|
|
|
- $permission_ids = implode(',',$permission_ids);
|
|
|
- }
|
|
|
- $data = compact('name','status','permission_ids');
|
|
|
- if(empty($id)){
|
|
|
-
|
|
|
- $count = Role::where('name', '=', $name)->where('is_del',0)->count();
|
|
|
- if ($count > 0 ) {
|
|
|
- return $this->apiResponseError( '该角色已存在');
|
|
|
- }
|
|
|
-
|
|
|
- $res = Role::create($data);
|
|
|
- }else{
|
|
|
- if (empty($id)) return $this->apiResponseError( '缺少必要参数');
|
|
|
-
|
|
|
- $info = Role::where('id',$id)->first();
|
|
|
- if(!$info) return $this->apiResponseError( '记录不存在');
|
|
|
-
|
|
|
- $count = Role::where('name', '=', $name)->where('id', '<>', $id)->where('is_del',0)->count();
|
|
|
- if ($count > 0 ) {
|
|
|
- return $this->apiResponseError( '该角色已存在');
|
|
|
- }
|
|
|
- $res = $info->update($data);
|
|
|
- //更新该角色redis节点信息
|
|
|
- RedisDataServer::creatServer()->delData('gw_role_ids_' . $id);
|
|
|
- }
|
|
|
- if ($res) {
|
|
|
- return $this->apiResponseSuccess('成功');
|
|
|
- } else {
|
|
|
- return $this->apiResponseError('失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取记录详情
|
|
|
- * @return \Illuminate\Http\JsonResponse
|
|
|
- */
|
|
|
- function getInfo()
|
|
|
- {
|
|
|
- $id = request()->input('id', '');//获取需要查询的记录id
|
|
|
- if (empty($id)) return $this->apiResponseError('缺少必要参数');
|
|
|
-
|
|
|
- //查询数据
|
|
|
- $where = [['id', $id], ['is_del',0]];
|
|
|
- $info = Role::where($where)->select(['id','name','status'])->first();
|
|
|
-
|
|
|
- if (empty($info)) return $this->apiResponseError('没有找到该记录');
|
|
|
- return $this->apiResponseSuccess('获取成功', $info);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取后台菜单
|
|
|
- * @return \Illuminate\Http\JsonResponse
|
|
|
- */
|
|
|
- function getMenuList(){
|
|
|
- $role_id = request()->input('role_id','');
|
|
|
-
|
|
|
- $list = MenuServer::creatServer()->getMenuList($role_id);
|
|
|
-
|
|
|
- return $this->apiResponseSuccess('获取列表成功', [
|
|
|
- 'items' => $list,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取导航栏目
|
|
|
- * @return \Illuminate\Http\JsonResponse
|
|
|
- */
|
|
|
- function getSideMenu(){
|
|
|
- $role_id = $this->getRoleId();//获取登录物流公司id
|
|
|
- //获取该角色的权限节点
|
|
|
- $permission_ids =Role::where('id', $role_id)->value('permission_ids');
|
|
|
- $url_ids = explode(',', $permission_ids);
|
|
|
-
|
|
|
- //获取导航栏数据
|
|
|
-
|
|
|
- $data = Menu::where([['status',1], ['is_del',0]])
|
|
|
- ->where(function ($q) use ($role_id,$url_ids){
|
|
|
- if($role_id){
|
|
|
- $q->whereIn('id',$url_ids);
|
|
|
- }
|
|
|
- })
|
|
|
- ->where(function ($q){
|
|
|
-
|
|
|
- $q->orWhere('level',1);
|
|
|
- $q->orWhere('level',2);
|
|
|
- })
|
|
|
- ->orderBy('id','asc')
|
|
|
- ->pluck('id')
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- return $this->apiResponseSuccess('获取信息成功', $data);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除(批量)角色
|
|
|
- * @return \Illuminate\Http\JsonResponse
|
|
|
- */
|
|
|
- function destroys(){
|
|
|
- $ids = request()->input('ids','');//获取需要删除的id
|
|
|
- if(empty($ids)) return $this->apiResponseError('请选择需要删除的数据');
|
|
|
- //数据条件
|
|
|
- if(!is_array($ids)){
|
|
|
- $ids = array_filter(explode(',', $ids));
|
|
|
- }
|
|
|
- foreach ($ids as $value){
|
|
|
- //检查每一个角色下面是否有使用
|
|
|
- $where = [['is_del',0], ['role_id',$value]];
|
|
|
- $count = User::where($where)->count();
|
|
|
- if($count > 0){
|
|
|
- return $this->apiResponseError('所选角色还有管理员使用,不能删除');
|
|
|
- }
|
|
|
- }
|
|
|
- $res = Role::whereIn('id',$ids)->update(['is_del' => 1,'status'=>2]);
|
|
|
- if ($res) {
|
|
|
- return $this->apiResponseSuccess('删除成功');
|
|
|
- } else {
|
|
|
- return $this->apiResponseError('删除失败');
|
|
|
- }
|
|
|
- }
|
|
|
-}
|