正在显示
8 个修改的文件
包含
212 行增加
和
12 行删除
| @@ -23,6 +23,7 @@ class BaseController extends Controller | @@ -23,6 +23,7 @@ class BaseController extends Controller | ||
| 23 | protected $order = 'id'; | 23 | protected $order = 'id'; |
| 24 | protected $map = [];//处理后的参数 | 24 | protected $map = [];//处理后的参数 |
| 25 | protected $uid = 0; | 25 | protected $uid = 0; |
| 26 | + protected $user = [];//当前登录用户详情 | ||
| 26 | /** | 27 | /** |
| 27 | * 获取所有参数 | 28 | * 获取所有参数 |
| 28 | */ | 29 | */ |
| @@ -44,6 +45,7 @@ class BaseController extends Controller | @@ -44,6 +45,7 @@ class BaseController extends Controller | ||
| 44 | public function auth_token(){ | 45 | public function auth_token(){ |
| 45 | $info = Cache::get($this->token); | 46 | $info = Cache::get($this->token); |
| 46 | if(isset($info) && !empty($info)){ | 47 | if(isset($info) && !empty($info)){ |
| 48 | + $this->user = $info; | ||
| 47 | $this->uid = $info['id']; | 49 | $this->uid = $info['id']; |
| 48 | } | 50 | } |
| 49 | } | 51 | } |
| @@ -74,7 +76,7 @@ class BaseController extends Controller | @@ -74,7 +76,7 @@ class BaseController extends Controller | ||
| 74 | $response = [ | 76 | $response = [ |
| 75 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | 77 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; |
| 76 | } | 78 | } |
| 77 | - return response()->json($response)->header($this->header); | 79 | + return response()->json($response,200,$this->header); |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | /** | 82 | /** |
| @@ -99,12 +101,12 @@ class BaseController extends Controller | @@ -99,12 +101,12 @@ class BaseController extends Controller | ||
| 99 | case 'row': | 101 | case 'row': |
| 100 | $this->row = $v; | 102 | $this->row = $v; |
| 101 | break; | 103 | break; |
| 102 | - case "create_at": | 104 | + case "created_at": |
| 103 | $this->_btw[0] = $v; | 105 | $this->_btw[0] = $v; |
| 104 | $this->_btw[1] = date('Y-m-d H:i:s',time()); | 106 | $this->_btw[1] = date('Y-m-d H:i:s',time()); |
| 105 | $this->map['create_at'] = ['between', $this->_btw]; | 107 | $this->map['create_at'] = ['between', $this->_btw]; |
| 106 | break; | 108 | break; |
| 107 | - case "update_at": | 109 | + case "updated_at": |
| 108 | $this->_btw[1] = $v; | 110 | $this->_btw[1] = $v; |
| 109 | $this->map['update_at'] = ['between', $this->_btw]; | 111 | $this->map['update_at'] = ['between', $this->_btw]; |
| 110 | break; | 112 | break; |
| @@ -158,4 +160,26 @@ class BaseController extends Controller | @@ -158,4 +160,26 @@ class BaseController extends Controller | ||
| 158 | $this->header['Per-Page'] = $this->row; //每页条数 | 160 | $this->header['Per-Page'] = $this->row; //每页条数 |
| 159 | return $this->header; | 161 | return $this->header; |
| 160 | } | 162 | } |
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * @name :上传图片 | ||
| 166 | + * @return void | ||
| 167 | + * @author :liyuhang | ||
| 168 | + * @method | ||
| 169 | + */ | ||
| 170 | + public function uploads(){ | ||
| 171 | + $files = $this->request->file('file'); | ||
| 172 | + if(empty($files)){ | ||
| 173 | + return $this->response('没有上传文件',Code::USER_ERROR); | ||
| 174 | + } | ||
| 175 | + $url = './uploads/images/'; | ||
| 176 | + $param = $this->request->post(); | ||
| 177 | + if($this->request->hasFile('image') && $files->isValid()){ | ||
| 178 | + $filename = date('ymdHis').rand(10000,99999).$this->request->file('image'); | ||
| 179 | + $this->request->file('image')->move('./uploads/images/',$filename); | ||
| 180 | + }else{ | ||
| 181 | + return false; | ||
| 182 | + } | ||
| 183 | + return $url.$filename; | ||
| 184 | + } | ||
| 161 | } | 185 | } |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Controllers\Aside; | ||
| 4 | + | ||
| 5 | +use App\Http\Controllers\Aside\BaseController; | ||
| 6 | + | ||
| 7 | +class ManagerController extends BaseController | ||
| 8 | +{ | ||
| 9 | + /** | ||
| 10 | + * @name :管理员列表 | ||
| 11 | + * @return void | ||
| 12 | + * @author :liyuhang | ||
| 13 | + * @method | ||
| 14 | + */ | ||
| 15 | + public function lists(){ | ||
| 16 | + | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * @name:新增 | ||
| 21 | + * @return void | ||
| 22 | + * @author :liyuhang | ||
| 23 | + * @method | ||
| 24 | + */ | ||
| 25 | + public function add(){ | ||
| 26 | + | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @name :编辑管理员 | ||
| 31 | + * @return void | ||
| 32 | + * @author :liyuhang | ||
| 33 | + * @method | ||
| 34 | + */ | ||
| 35 | + public function edit(){ | ||
| 36 | + | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public function del(){ | ||
| 40 | + | ||
| 41 | + } | ||
| 42 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Controllers\Aside; | ||
| 4 | + | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Models\ProjectMenu as ProjectMenuModel; | ||
| 7 | +use Illuminate\Support\Facades\Validator; | ||
| 8 | + | ||
| 9 | +class ProjectMenuController extends BaseController | ||
| 10 | +{ | ||
| 11 | + /** | ||
| 12 | + * @name :用户组菜单列表(带分页) | ||
| 13 | + * @return void | ||
| 14 | + * @author :liyuhang | ||
| 15 | + * @method | ||
| 16 | + */ | ||
| 17 | + public function lists(){ | ||
| 18 | + //根据角色获取菜单列表 | ||
| 19 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 20 | + $lists = $projectMenuModel->lists($this->map,$this->p,$this->row,$this->order); | ||
| 21 | + $this->allCount = $projectMenuModel->allCount; | ||
| 22 | + $this->result($lists); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * @name :添加用户组菜单 | ||
| 27 | + * @return void | ||
| 28 | + * @author :liyuhang | ||
| 29 | + * @method | ||
| 30 | + */ | ||
| 31 | + public function add(){ | ||
| 32 | + //参数验证 | ||
| 33 | + $rules = [ | ||
| 34 | + 'name'=>'required|max:11', | ||
| 35 | + 'rules'=>'required', | ||
| 36 | + ]; | ||
| 37 | + //验证的提示信息 | ||
| 38 | + $message = [ | ||
| 39 | + 'name.required'=>'名称必须填写', | ||
| 40 | + 'name.max' => '名称不大于16字符.', | ||
| 41 | + 'rules.required'=>'路由必须填写', | ||
| 42 | + ]; | ||
| 43 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 44 | + if($validate->fails()){ | ||
| 45 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 46 | + } | ||
| 47 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 48 | + $rs = $projectMenuModel->add($this->param); | ||
| 49 | + if($rs === false){ | ||
| 50 | + $this->response('请求失败',Code::USER_ERROR,[]); | ||
| 51 | + } | ||
| 52 | + $this->response('success',Code::SUCCESS); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * @name :编辑用户组菜单 | ||
| 57 | + * @return void | ||
| 58 | + * @author :liyuhang | ||
| 59 | + * @method | ||
| 60 | + */ | ||
| 61 | + public function edit(){ | ||
| 62 | + //参数验证 | ||
| 63 | + $rules = [ | ||
| 64 | + 'id'=>'required', | ||
| 65 | + 'name'=>'required|max:11', | ||
| 66 | + 'rules'=>'required', | ||
| 67 | + ]; | ||
| 68 | + //验证的提示信息 | ||
| 69 | + $message = [ | ||
| 70 | + 'id.required'=>'服务器id错误', | ||
| 71 | + 'name.required'=>'名称必须填写', | ||
| 72 | + 'name.max' => '名称不大于16字符.', | ||
| 73 | + 'rules.required'=>'路由必须填写', | ||
| 74 | + ]; | ||
| 75 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 76 | + if($validate->fails()){ | ||
| 77 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 78 | + } | ||
| 79 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 80 | + $rs = $projectMenuModel->edit($this->param,['id'=>$this->param['id']]); | ||
| 81 | + if($rs === false){ | ||
| 82 | + $this->response('请求失败',Code::USER_ERROR); | ||
| 83 | + } | ||
| 84 | + $this->response('success',Code::SUCCESS); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @name :编辑状态 | ||
| 89 | + * @return void | ||
| 90 | + * @author :liyuhang | ||
| 91 | + * @method | ||
| 92 | + */ | ||
| 93 | + public function status(){ | ||
| 94 | + //参数验证 | ||
| 95 | + $rules = [ | ||
| 96 | + 'id'=>'required', | ||
| 97 | + 'status'=>'required', | ||
| 98 | + ]; | ||
| 99 | + //验证的提示信息 | ||
| 100 | + $message = [ | ||
| 101 | + 'id.required'=>'主键必须填写', | ||
| 102 | + 'status.required'=>'状态必须填写', | ||
| 103 | + ]; | ||
| 104 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 105 | + if($validate->fails()){ | ||
| 106 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 107 | + } | ||
| 108 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 109 | + $rs = $projectMenuModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); | ||
| 110 | + if($rs === false){ | ||
| 111 | + $this->response('编辑失败',Code::USER_PARAMS_ERROE); | ||
| 112 | + } | ||
| 113 | + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); | ||
| 114 | + } | ||
| 115 | +} |
| @@ -58,7 +58,7 @@ class ComController extends BaseController | @@ -58,7 +58,7 @@ class ComController extends BaseController | ||
| 58 | $info = $projectRoleModel->read(['id'=>$this->user['role_id']]); | 58 | $info = $projectRoleModel->read(['id'=>$this->user['role_id']]); |
| 59 | $projectMenuModel = new ProjectMenuModel(); | 59 | $projectMenuModel = new ProjectMenuModel(); |
| 60 | $info['role_menu'] = trim($info['role_menu'],','); | 60 | $info['role_menu'] = trim($info['role_menu'],','); |
| 61 | - $lists = DB::table($projectMenuModel->getTable())->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get(); | 61 | + $lists = $this->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get(); |
| 62 | $lists = $lists->toArray(); | 62 | $lists = $lists->toArray(); |
| 63 | $menu = array(); | 63 | $menu = array(); |
| 64 | foreach ($lists as $k => $v){ | 64 | foreach ($lists as $k => $v){ |
| @@ -19,6 +19,8 @@ class ProjectRoleController extends BaseController | @@ -19,6 +19,8 @@ class ProjectRoleController extends BaseController | ||
| 19 | //TODO::根据当前登录用户返回 | 19 | //TODO::根据当前登录用户返回 |
| 20 | $projectRoleModel = new ProjectRoleModel(); | 20 | $projectRoleModel = new ProjectRoleModel(); |
| 21 | $this->map['status'] = 0; | 21 | $this->map['status'] = 0; |
| 22 | + $this->map['project_id'] = $this->user['project_id']; | ||
| 23 | + //获取当前登录用户自己的菜单栏 | ||
| 22 | $lists = $projectRoleModel->lists($this->map,$this->p,$this->row,$this->order); | 24 | $lists = $projectRoleModel->lists($this->map,$this->p,$this->row,$this->order); |
| 23 | $this->allCount = $projectRoleModel->allCount; | 25 | $this->allCount = $projectRoleModel->allCount; |
| 24 | $this->result($lists); | 26 | $this->result($lists); |
| @@ -18,7 +18,7 @@ class Base extends Model | @@ -18,7 +18,7 @@ class Base extends Model | ||
| 18 | public function lists($map, $p, $row, $order = 'id', $fields = ['*']){ | 18 | public function lists($map, $p, $row, $order = 'id', $fields = ['*']){ |
| 19 | //TODO::where(['id'=>'','name'=>'']) | 19 | //TODO::where(['id'=>'','name'=>'']) |
| 20 | $lists = $this->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get(); | 20 | $lists = $this->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get(); |
| 21 | - if ($lists->isEmpty() === false) { | 21 | + if ($lists->isEmpty() !== false) { |
| 22 | return false; | 22 | return false; |
| 23 | } | 23 | } |
| 24 | $lists = $lists->toArray(); | 24 | $lists = $lists->toArray(); |
| @@ -38,7 +38,7 @@ class Base extends Model | @@ -38,7 +38,7 @@ class Base extends Model | ||
| 38 | */ | 38 | */ |
| 39 | public function list($map,$order = 'id',$fields = ['*']){ | 39 | public function list($map,$order = 'id',$fields = ['*']){ |
| 40 | $lists = $this->select($fields)->where($map)->orderBy($order)->get(); | 40 | $lists = $this->select($fields)->where($map)->orderBy($order)->get(); |
| 41 | - if ($lists->isEmpty() === false) { | 41 | + if ($lists->isEmpty() !== false) { |
| 42 | return false; | 42 | return false; |
| 43 | } | 43 | } |
| 44 | $lists = $lists->toArray(); | 44 | $lists = $lists->toArray(); |
| @@ -54,9 +54,10 @@ class Base extends Model | @@ -54,9 +54,10 @@ class Base extends Model | ||
| 54 | public function read($condition,$files = ['*']) | 54 | public function read($condition,$files = ['*']) |
| 55 | { | 55 | { |
| 56 | $info = $this->select($files)->where($condition)->first(); | 56 | $info = $this->select($files)->where($condition)->first(); |
| 57 | - if (!empty($info)) { | ||
| 58 | - $info = $info->toArray(); | 57 | + if ($info->isEmpty() !== false) { |
| 58 | + return false; | ||
| 59 | } | 59 | } |
| 60 | + $info = $info->toArray(); | ||
| 60 | return $info; | 61 | return $info; |
| 61 | } | 62 | } |
| 62 | 63 | ||
| @@ -68,8 +69,6 @@ class Base extends Model | @@ -68,8 +69,6 @@ class Base extends Model | ||
| 68 | * @method post | 69 | * @method post |
| 69 | */ | 70 | */ |
| 70 | public function add($data){ | 71 | public function add($data){ |
| 71 | -// $data['created_at'] = date('Y-m-d H:i:s',time()); | ||
| 72 | -// $data['updated_at'] = date('Y-m-d H:i:s',time()); | ||
| 73 | return $this->insert($data); | 72 | return $this->insert($data); |
| 74 | } | 73 | } |
| 75 | 74 | ||
| @@ -83,7 +82,6 @@ class Base extends Model | @@ -83,7 +82,6 @@ class Base extends Model | ||
| 83 | if(isset($data['id']) && !empty($data['id'])){ | 82 | if(isset($data['id']) && !empty($data['id'])){ |
| 84 | unset($data['id']); | 83 | unset($data['id']); |
| 85 | } | 84 | } |
| 86 | -// $data['updated_at'] = date('Y-m-d H:i:s',time()); | ||
| 87 | return $this->where($condition)->update($data); | 85 | return $this->where($condition)->update($data); |
| 88 | } | 86 | } |
| 89 | 87 |
| @@ -14,8 +14,12 @@ Route::group([], function () { | @@ -14,8 +14,12 @@ Route::group([], function () { | ||
| 14 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); | 14 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); |
| 15 | Route::any('/get_menu', [\App\Http\Controllers\Bside\ComController::class, 'get_menu'])->name('get_menu'); | 15 | Route::any('/get_menu', [\App\Http\Controllers\Bside\ComController::class, 'get_menu'])->name('get_menu'); |
| 16 | Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project'); | 16 | Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project'); |
| 17 | + //用户相关路由 | ||
| 18 | + Route::any('/user/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add'); | ||
| 19 | + Route::any('/user/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit'); | ||
| 20 | + Route::any('/user/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status'); | ||
| 17 | Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); | 21 | Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); |
| 18 | - Route::any('/project/page_lists', [\App\Http\Controllers\Bside\ProjectController::class, 'page_lists'])->name('page_lists'); | 22 | + Route::any('/user/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del'); |
| 19 | //用户角色相关路由 | 23 | //用户角色相关路由 |
| 20 | Route::any('/project_role/lists', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists'); | 24 | Route::any('/project_role/lists', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists'); |
| 21 | Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add'); | 25 | Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add'); |
-
请 注册 或 登录 后发表评论