正在显示
6 个修改的文件
包含
49 行增加
和
35 行删除
| @@ -30,6 +30,7 @@ class BaseController extends Controller | @@ -30,6 +30,7 @@ class BaseController extends Controller | ||
| 30 | { | 30 | { |
| 31 | $this->request = $request; | 31 | $this->request = $request; |
| 32 | $this->param = $this->request->all(); | 32 | $this->param = $this->request->all(); |
| 33 | + $this->param['created_at'] = date("YmdHis"); | ||
| 33 | $this->token = $this->request->header('token'); | 34 | $this->token = $this->request->header('token'); |
| 34 | $this->get_param(); | 35 | $this->get_param(); |
| 35 | $this->auth_token(); | 36 | $this->auth_token(); |
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Logic\Bside\ComLogic; | 6 | use App\Http\Logic\Bside\ComLogic; |
| 7 | +use App\Models\Project as ProjectModel; | ||
| 7 | use App\Models\ProjectMenu as ProjectMenuModel; | 8 | use App\Models\ProjectMenu as ProjectMenuModel; |
| 8 | use App\Models\ProjectRole as ProjectRoleModel; | 9 | use App\Models\ProjectRole as ProjectRoleModel; |
| 9 | use Illuminate\Support\Facades\DB; | 10 | use Illuminate\Support\Facades\DB; |
| @@ -81,10 +82,10 @@ class ComController extends BaseController | @@ -81,10 +82,10 @@ class ComController extends BaseController | ||
| 81 | foreach ($arr as $k => $v) { | 82 | foreach ($arr as $k => $v) { |
| 82 | $v = (array)$v; | 83 | $v = (array)$v; |
| 83 | if ($v['pid'] == $my_id) { | 84 | if ($v['pid'] == $my_id) { |
| 84 | - $new_arr[$k] = $v; | ||
| 85 | - $new_arr[$k]['son'] = $this->_get_child($v['id'],$arr); | ||
| 86 | - } | 85 | + $v['sub'] = $this->_get_child($v['id'],$arr); |
| 86 | + $new_arr[] = $v; | ||
| 87 | 87 | ||
| 88 | + } | ||
| 88 | } | 89 | } |
| 89 | return $new_arr ? $new_arr : false; | 90 | return $new_arr ? $new_arr : false; |
| 90 | } | 91 | } |
| @@ -95,6 +96,11 @@ class ComController extends BaseController | @@ -95,6 +96,11 @@ class ComController extends BaseController | ||
| 95 | * @method | 96 | * @method |
| 96 | */ | 97 | */ |
| 97 | public function get_project(){ | 98 | public function get_project(){ |
| 98 | - | 99 | + $projectModel = new ProjectModel(); |
| 100 | + $info = $projectModel->read(['id'=>$this->user['project_id']]); | ||
| 101 | + if(empty($info)){ | ||
| 102 | + $this->response('error',Code::USER_ERROR); | ||
| 103 | + } | ||
| 104 | + $this->response('success',Code::SUCCESS,[$info]); | ||
| 99 | } | 105 | } |
| 100 | } | 106 | } |
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Models\ProjectRole as ProjectRoleModel; | 6 | use App\Models\ProjectRole as ProjectRoleModel; |
| 7 | +use Illuminate\Support\Facades\DB; | ||
| 7 | use Illuminate\Support\Facades\Validator; | 8 | use Illuminate\Support\Facades\Validator; |
| 8 | 9 | ||
| 9 | class ProjectRoleController extends BaseController | 10 | class ProjectRoleController extends BaseController |
| @@ -44,16 +45,11 @@ class ProjectRoleController extends BaseController | @@ -44,16 +45,11 @@ class ProjectRoleController extends BaseController | ||
| 44 | if($validate->fails()){ | 45 | if($validate->fails()){ |
| 45 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | 46 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); |
| 46 | } | 47 | } |
| 48 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 49 | + //获取当前项目下的角色超级管理员 | ||
| 47 | $projectRoleModel = new ProjectRoleModel(); | 50 | $projectRoleModel = new ProjectRoleModel(); |
| 48 | //验证当前角色是否存在 | 51 | //验证当前角色是否存在 |
| 49 | - if(!isset($this->param['pid'])){ | ||
| 50 | - $data['pid'] = 0; | ||
| 51 | - } | ||
| 52 | - $data = [ | ||
| 53 | - 'name' => $this->param['name'], | ||
| 54 | - 'pid' => $this->param['pid'], | ||
| 55 | - ]; | ||
| 56 | - $info = $projectRoleModel->read($data); | 52 | + $info = $projectRoleModel->read(['name'=>$this->param['name']]); |
| 57 | if(!empty($info)){ | 53 | if(!empty($info)){ |
| 58 | $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE); | 54 | $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE); |
| 59 | } | 55 | } |
| @@ -76,28 +72,22 @@ class ProjectRoleController extends BaseController | @@ -76,28 +72,22 @@ class ProjectRoleController extends BaseController | ||
| 76 | $rules = [ | 72 | $rules = [ |
| 77 | 'id'=>'required', | 73 | 'id'=>'required', |
| 78 | 'name'=>'required|max:11', | 74 | 'name'=>'required|max:11', |
| 75 | + 'role_menu'=>'required', | ||
| 79 | ]; | 76 | ]; |
| 80 | //验证的提示信息 | 77 | //验证的提示信息 |
| 81 | $message = [ | 78 | $message = [ |
| 82 | 'id.required'=>'主键必须填写', | 79 | 'id.required'=>'主键必须填写', |
| 83 | 'name.required'=>'名称必须填写', | 80 | 'name.required'=>'名称必须填写', |
| 84 | - 'name.max' => '号码不大于11字符.', | 81 | + 'role_menu.required'=>'菜单权限列表填写', |
| 85 | ]; | 82 | ]; |
| 86 | $validate = Validator::make($this->param, $rules, $message); | 83 | $validate = Validator::make($this->param, $rules, $message); |
| 87 | if($validate->fails()){ | 84 | if($validate->fails()){ |
| 88 | - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | 85 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE); |
| 89 | } | 86 | } |
| 90 | - //验证当前角色是否存在 | ||
| 91 | - if(!isset($this->param['pid'])){ | ||
| 92 | - $data['pid'] = 0; | ||
| 93 | - } | ||
| 94 | - $data = [ | ||
| 95 | - //TODO::自动写入当前用户 | ||
| 96 | - 'name' => $this->param['name'], | ||
| 97 | - 'pid' => $this->param['pid'], | ||
| 98 | - ]; | ||
| 99 | $projectRoleModel = new ProjectRoleModel(); | 87 | $projectRoleModel = new ProjectRoleModel(); |
| 100 | - $info = $projectRoleModel->read($data); | 88 | + //TODO::查询当前名称是否重复 |
| 89 | + $info = DB::table($projectRoleModel->getTable())->where('id','<>',$this->param['id']) | ||
| 90 | + ->where(['name'=>$this->param['name'],'project_id'=>$this->user['project_id']])->first(); | ||
| 101 | if(!empty($info)){ | 91 | if(!empty($info)){ |
| 102 | $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE); | 92 | $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE); |
| 103 | } | 93 | } |
| @@ -16,13 +16,13 @@ class ComLogic extends BaseLogic | @@ -16,13 +16,13 @@ class ComLogic extends BaseLogic | ||
| 16 | public function login($param){ | 16 | public function login($param){ |
| 17 | #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code | 17 | #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code |
| 18 | $userModel = new UserModel(); | 18 | $userModel = new UserModel(); |
| 19 | - if($param['login_method'] == 1){ | 19 | + if(!isset($param['login_method'])){ |
| 20 | //密码加密 | 20 | //密码加密 |
| 21 | $param['password'] = base64_encode(md5($param['password'])); | 21 | $param['password'] = base64_encode(md5($param['password'])); |
| 22 | - $info = $userModel->read(['mobile'=>$param['mobile'],'password'=>$param['password']], ['id','mobile','role_id','project_id','name']); | 22 | + $info = $userModel->read(['mobile'=>$param['mobile'],'password'=>$param['password']], ['*']); |
| 23 | }else{ | 23 | }else{ |
| 24 | //TODO::验证验证码是否正确 | 24 | //TODO::验证验证码是否正确 |
| 25 | - $info = $userModel->read(['mobile'=>$param['mobile']],['id','mobile','role_id','project_id','name']); | 25 | + $info = $userModel->read(['mobile'=>$param['mobile']],['*']); |
| 26 | } | 26 | } |
| 27 | if(empty($info)){ | 27 | if(empty($info)){ |
| 28 | return false; | 28 | return false; |
| @@ -39,7 +39,11 @@ class ComLogic extends BaseLogic | @@ -39,7 +39,11 @@ class ComLogic extends BaseLogic | ||
| 39 | Cache::add($token,$info); | 39 | Cache::add($token,$info); |
| 40 | //更新数据库 | 40 | //更新数据库 |
| 41 | 41 | ||
| 42 | - $data = $info; | 42 | + $data = [ |
| 43 | + 'id'=>$info['id'], | ||
| 44 | + 'mobile'=>$info['mobile'], | ||
| 45 | + 'name'=>$info['name'] | ||
| 46 | + ]; | ||
| 43 | $rs = $userModel->edit(['token'=>$token],['id'=>$info['id']]); | 47 | $rs = $userModel->edit(['token'=>$token],['id'=>$info['id']]); |
| 44 | if($rs === false){ | 48 | if($rs === false){ |
| 45 | return false; | 49 | return false; |
| @@ -17,13 +17,21 @@ class Base extends Model | @@ -17,13 +17,21 @@ class Base extends Model | ||
| 17 | */ | 17 | */ |
| 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 = DB::table($this->table)->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 (!empty($lists)) { | 21 | if (!empty($lists)) { |
| 22 | + $lists = $lists->toArray(); | ||
| 22 | $this->allCount = DB::table($this->table)->where($map)->count(); | 23 | $this->allCount = DB::table($this->table)->where($map)->count(); |
| 23 | } | 24 | } |
| 24 | return $lists; | 25 | return $lists; |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 28 | + public function list($map,$order = 'id',$fields = ['*']){ | ||
| 29 | + $lists = $this->select($fields)->where($map)->orderBy($order)->get(); | ||
| 30 | + if (!empty($lists)) { | ||
| 31 | + $lists = $lists->toArray(); | ||
| 32 | + } | ||
| 33 | + return $lists; | ||
| 34 | + } | ||
| 27 | /** | 35 | /** |
| 28 | * @param array:$condition | 36 | * @param array:$condition |
| 29 | * @name :获取单条数据详情 | 37 | * @name :获取单条数据详情 |
| @@ -33,9 +41,8 @@ class Base extends Model | @@ -33,9 +41,8 @@ class Base extends Model | ||
| 33 | */ | 41 | */ |
| 34 | public function read($condition,$files = ['*']) | 42 | public function read($condition,$files = ['*']) |
| 35 | { | 43 | { |
| 36 | - | ||
| 37 | - $info = DB::table($this->table)->select($files)->where($condition)->first(); | ||
| 38 | - return (array)$info; | 44 | + $info = $this->select($files)->where($condition)->first()->toArray(); |
| 45 | + return $info; | ||
| 39 | } | 46 | } |
| 40 | 47 | ||
| 41 | /** | 48 | /** |
| @@ -45,7 +52,9 @@ class Base extends Model | @@ -45,7 +52,9 @@ class Base extends Model | ||
| 45 | * @method post | 52 | * @method post |
| 46 | */ | 53 | */ |
| 47 | public function add($data){ | 54 | public function add($data){ |
| 48 | - return DB::table($this->table)->insert($data); | 55 | + $data['created_at'] = date('Y-m-d H:i:s',time()); |
| 56 | + $data['updated_at'] = date('Y-m-d H:i:s',time()); | ||
| 57 | + return $this->insert($data); | ||
| 49 | } | 58 | } |
| 50 | 59 | ||
| 51 | /** | 60 | /** |
| @@ -58,7 +67,8 @@ class Base extends Model | @@ -58,7 +67,8 @@ class Base extends Model | ||
| 58 | if(isset($data['id']) && !empty($data['id'])){ | 67 | if(isset($data['id']) && !empty($data['id'])){ |
| 59 | unset($data['id']); | 68 | unset($data['id']); |
| 60 | } | 69 | } |
| 61 | - return DB::table($this->table)->where($condition)->update($data); | 70 | + $data['updated_at'] = date('Y-m-d H:i:s',time()); |
| 71 | + return $this->where($condition)->update($data); | ||
| 62 | } | 72 | } |
| 63 | 73 | ||
| 64 | /** | 74 | /** |
| @@ -68,6 +78,6 @@ class Base extends Model | @@ -68,6 +78,6 @@ class Base extends Model | ||
| 68 | * @method | 78 | * @method |
| 69 | */ | 79 | */ |
| 70 | public function del($condition){ | 80 | public function del($condition){ |
| 71 | - return DB::table($this->table)->where($condition)->delete(); | 81 | + return $this->where($condition)->delete(); |
| 72 | } | 82 | } |
| 73 | } | 83 | } |
| @@ -13,6 +13,9 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -13,6 +13,9 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 13 | Route::group([], function () { | 13 | 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('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); | 17 | Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); |
| 17 | Route::any('/project/page_lists', [\App\Http\Controllers\Bside\ProjectController::class, 'page_lists'])->name('page_lists'); | 18 | Route::any('/project/page_lists', [\App\Http\Controllers\Bside\ProjectController::class, 'page_lists'])->name('page_lists'); |
| 19 | + Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add'); | ||
| 20 | + Route::any('/project_role/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit'); | ||
| 18 | }); | 21 | }); |
-
请 注册 或 登录 后发表评论