正在显示
8 个修改的文件
包含
118 行增加
和
62 行删除
| @@ -4,13 +4,14 @@ namespace App\Http\Controllers\Bside; | @@ -4,13 +4,14 @@ namespace App\Http\Controllers\Bside; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | -use App\Utils\EncryptUtils; | 7 | +use App\Models\ProjectMenu; |
| 8 | +use App\Models\ProjectRole as ProjectRoleModel; | ||
| 8 | use \Illuminate\Http\Request; | 9 | use \Illuminate\Http\Request; |
| 9 | use Illuminate\Http\Response; | 10 | use Illuminate\Http\Response; |
| 10 | use Illuminate\Http\Exceptions\HttpResponseException; | 11 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 11 | use Illuminate\Support\Facades\Cache; | 12 | use Illuminate\Support\Facades\Cache; |
| 12 | 13 | ||
| 13 | -class BaseController extends Controller | 14 | +class BaseController extends Controller |
| 14 | { | 15 | { |
| 15 | protected $param = [];//所有请求参数 | 16 | protected $param = [];//所有请求参数 |
| 16 | protected $token = ''; //token | 17 | protected $token = ''; //token |
| @@ -33,6 +34,7 @@ class BaseController extends Controller | @@ -33,6 +34,7 @@ class BaseController extends Controller | ||
| 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(); |
| 37 | + $this->auth_role(); | ||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | /** | 40 | /** |
| @@ -43,40 +45,20 @@ class BaseController extends Controller | @@ -43,40 +45,20 @@ class BaseController extends Controller | ||
| 43 | */ | 45 | */ |
| 44 | public function auth_token(){ | 46 | public function auth_token(){ |
| 45 | $info = Cache::get($this->token); | 47 | $info = Cache::get($this->token); |
| 46 | - if(isset($info) && !empty($info)){ | ||
| 47 | - $this->user = $info; | ||
| 48 | - $this->uid = $info['id']; | 48 | + $this->user = $info; |
| 49 | + $this->uid = $info['id']; | ||
| 50 | + //操作权限设置 | ||
| 51 | + $projectRoleModel = new ProjectRoleModel(); | ||
| 52 | + $role_info = $projectRoleModel->read(['id'=>$this->user['role_id']]); | ||
| 53 | + //获取当前操作的控制器与方法 | ||
| 54 | + $action = $this->request->route()->getAction(); | ||
| 55 | + //查询当前用户是否拥有权限操作 | ||
| 56 | + $projectMenuModel = new ProjectMenu(); | ||
| 57 | + $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']); | ||
| 58 | + if($menu_id !== false && strpos($role_info['role_menu'], $menu_id['id']) === false){ | ||
| 59 | + $this->response('拦截',Code::USER_PERMISSION_ERROE); | ||
| 49 | } | 60 | } |
| 50 | } | 61 | } |
| 51 | - /** | ||
| 52 | - * 成功返回 | ||
| 53 | - * @param array $data | ||
| 54 | - * @param string $code | ||
| 55 | - * @param bool $objectData | ||
| 56 | - * @return JsonResponse | ||
| 57 | - * @throws \Psr\Container\ContainerExceptionInterface | ||
| 58 | - * @throws \Psr\Container\NotFoundExceptionInterface | ||
| 59 | - */ | ||
| 60 | - function success(array $data = [], string $code = Code::SUCCESS, bool $objectData = false): JsonResponse | ||
| 61 | - { | ||
| 62 | - if ($objectData) { | ||
| 63 | - $data = (object)$data; | ||
| 64 | - } | ||
| 65 | - $code = Code::fromValue($code); | ||
| 66 | - $response = [ | ||
| 67 | - 'code' => $code->value, | ||
| 68 | - 'data' => $data, | ||
| 69 | - 'msg' => $code->description, | ||
| 70 | - ]; | ||
| 71 | - //加密-返回数据 | ||
| 72 | - if (config('app.params_encrypt')) { | ||
| 73 | - $k = config('app.params_encrypt_key'); | ||
| 74 | - $i = config('app.params_encrypt_iv'); | ||
| 75 | - $response = [ | ||
| 76 | - 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | ||
| 77 | - } | ||
| 78 | - return response()->json($response,200,$this->header); | ||
| 79 | - } | ||
| 80 | 62 | ||
| 81 | /** | 63 | /** |
| 82 | * @name 参数过滤 | 64 | * @name 参数过滤 |
| @@ -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 = $this->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get(); | 61 | + $lists = $this->where(['status'=>0,'is_role'=>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){ |
| @@ -103,4 +103,24 @@ class ComController extends BaseController | @@ -103,4 +103,24 @@ class ComController extends BaseController | ||
| 103 | } | 103 | } |
| 104 | $this->response('success',Code::SUCCESS,[$info]); | 104 | $this->response('success',Code::SUCCESS,[$info]); |
| 105 | } | 105 | } |
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * @name :登录用户编辑资料/修改密码 | ||
| 109 | + * @return void | ||
| 110 | + * @author :liyuhang | ||
| 111 | + * @method | ||
| 112 | + */ | ||
| 113 | + public function edit_info(){ | ||
| 114 | + | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + /** | ||
| 118 | + * @name :退出登录 | ||
| 119 | + * @return void | ||
| 120 | + * @author :liyuhang | ||
| 121 | + * @method :post | ||
| 122 | + */ | ||
| 123 | + public function logout(){ | ||
| 124 | + | ||
| 125 | + } | ||
| 106 | } | 126 | } |
| @@ -25,7 +25,6 @@ class ProjectRoleController extends BaseController | @@ -25,7 +25,6 @@ class ProjectRoleController extends BaseController | ||
| 25 | $this->allCount = $projectRoleModel->allCount; | 25 | $this->allCount = $projectRoleModel->allCount; |
| 26 | $this->result($lists); | 26 | $this->result($lists); |
| 27 | } | 27 | } |
| 28 | - | ||
| 29 | /** | 28 | /** |
| 30 | * @name :添加角色 | 29 | * @name :添加角色 |
| 31 | * @return void | 30 | * @return void |
| @@ -20,7 +20,8 @@ class UserController extends BaseController | @@ -20,7 +20,8 @@ class UserController extends BaseController | ||
| 20 | public function lists(){ | 20 | public function lists(){ |
| 21 | //TODO::搜索参数处理 | 21 | //TODO::搜索参数处理 |
| 22 | $userModel = new UserModel(); | 22 | $userModel = new UserModel(); |
| 23 | - $lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']); | 23 | + $this->map['project_id'] = $this->user['project_id']; |
| 24 | + $lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile','created_at']); | ||
| 24 | if(empty($lists)){ | 25 | if(empty($lists)){ |
| 25 | $this->response('请求失败',Code::USER_ERROR,[]); | 26 | $this->response('请求失败',Code::USER_ERROR,[]); |
| 26 | } | 27 | } |
| @@ -39,6 +40,7 @@ class UserController extends BaseController | @@ -39,6 +40,7 @@ class UserController extends BaseController | ||
| 39 | 'mobile'=>'required|string|max:11', | 40 | 'mobile'=>'required|string|max:11', |
| 40 | 'password'=>'required|string|min:5', | 41 | 'password'=>'required|string|min:5', |
| 41 | 'name'=>'required|max:20', | 42 | 'name'=>'required|max:20', |
| 43 | + 'role_id'=>'required' | ||
| 42 | ]; | 44 | ]; |
| 43 | //验证的提示信息 | 45 | //验证的提示信息 |
| 44 | $message = [ | 46 | $message = [ |
| @@ -50,13 +52,15 @@ class UserController extends BaseController | @@ -50,13 +52,15 @@ class UserController extends BaseController | ||
| 50 | 'password.min' => '密码不小于5字符.', | 52 | 'password.min' => '密码不小于5字符.', |
| 51 | 'name.required'=>'名称必须填写', | 53 | 'name.required'=>'名称必须填写', |
| 52 | 'name.min' => '名称不小于5字符.', | 54 | 'name.min' => '名称不小于5字符.', |
| 55 | + 'role_id.required'=>'角色必须填写', | ||
| 53 | ]; | 56 | ]; |
| 54 | $validate = Validator::make($this->param, $rules, $message); | 57 | $validate = Validator::make($this->param, $rules, $message); |
| 55 | if($validate->fails()){ | 58 | if($validate->fails()){ |
| 56 | return $this->response($validate->errors()->first(),Code::USER_LOGIN_ERROE,$this->param); | 59 | return $this->response($validate->errors()->first(),Code::USER_LOGIN_ERROE,$this->param); |
| 57 | } | 60 | } |
| 58 | - $userLogic = new UserLogic(); | ||
| 59 | - $rs = $userLogic->add($this->param); | 61 | + $userModel = new UserModel(); |
| 62 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 63 | + $rs = $userModel->adds($this->param); | ||
| 60 | if($rs === false){ | 64 | if($rs === false){ |
| 61 | $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); | 65 | $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); |
| 62 | } | 66 | } |
| @@ -92,8 +96,14 @@ class UserController extends BaseController | @@ -92,8 +96,14 @@ class UserController extends BaseController | ||
| 92 | if($validate->fails()){ | 96 | if($validate->fails()){ |
| 93 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | 97 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); |
| 94 | } | 98 | } |
| 95 | - $userLogic = new UserLogic(); | ||
| 96 | - $rs = $userLogic->edits($this->param); | 99 | + $userModel = new UserModel(); |
| 100 | + //TODO::查询当前手机号码是否重复 | ||
| 101 | + $info = $userModel->where('id','<>',$this->param['id']) | ||
| 102 | + ->where(['mobile'=>$this->param['mobile']])->first(); | ||
| 103 | + if(!empty($info)){ | ||
| 104 | + $this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE); | ||
| 105 | + } | ||
| 106 | + $rs = $userModel->edits($this->param); | ||
| 97 | if($rs === false){ | 107 | if($rs === false){ |
| 98 | $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); | 108 | $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); |
| 99 | } | 109 | } |
| @@ -17,22 +17,7 @@ class UserLogic extends BaseLogic | @@ -17,22 +17,7 @@ class UserLogic extends BaseLogic | ||
| 17 | return $lists; | 17 | return $lists; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | - //新增用户 | ||
| 21 | - public function add($param){ | ||
| 22 | - $userModel = new UserModel(); | ||
| 23 | - //验证当前用户是否存在 | ||
| 24 | - $info = $userModel->read(['mobile'=>$param['mobile']]); | ||
| 25 | - if(!empty($info)){ | ||
| 26 | - return false; | ||
| 27 | - } | ||
| 28 | - //密码加密 | ||
| 29 | - $param['password'] = base64_encode(md5($param['password'])); | ||
| 30 | - $rs = $userModel->add($param); | ||
| 31 | - if($rs === false){ | ||
| 32 | - return false; | ||
| 33 | - } | ||
| 34 | - return true; | ||
| 35 | - } | 20 | + |
| 36 | 21 | ||
| 37 | /** | 22 | /** |
| 38 | * @param $param | 23 | * @param $param |
| @@ -9,6 +9,8 @@ class Base extends Model | @@ -9,6 +9,8 @@ class Base extends Model | ||
| 9 | { | 9 | { |
| 10 | protected $table = ''; | 10 | protected $table = ''; |
| 11 | public $allCount = 0; | 11 | public $allCount = 0; |
| 12 | + //自动维护create_at创建时间 updated_at修改时间 | ||
| 13 | + public $timestamps = true; | ||
| 12 | //统一设置 | 14 | //统一设置 |
| 13 | protected $casts = [ | 15 | protected $casts = [ |
| 14 | 'created_at' => 'datetime:Y-m-d H:i:s', | 16 | 'created_at' => 'datetime:Y-m-d H:i:s', |
| @@ -74,6 +76,8 @@ class Base extends Model | @@ -74,6 +76,8 @@ class Base extends Model | ||
| 74 | * @method post | 76 | * @method post |
| 75 | */ | 77 | */ |
| 76 | public function add($data){ | 78 | public function add($data){ |
| 79 | + $data['created_at'] = date('Y-m-d H:i:s'); | ||
| 80 | + $data['updated_at'] = date('Y-m-d H:i:s'); | ||
| 77 | return $this->insert($data); | 81 | return $this->insert($data); |
| 78 | } | 82 | } |
| 79 | 83 | ||
| @@ -84,9 +88,7 @@ class Base extends Model | @@ -84,9 +88,7 @@ class Base extends Model | ||
| 84 | * @method post | 88 | * @method post |
| 85 | */ | 89 | */ |
| 86 | public function edit($data,$condition){ | 90 | public function edit($data,$condition){ |
| 87 | - if(isset($data['id']) && !empty($data['id'])){ | ||
| 88 | - unset($data['id']); | ||
| 89 | - } | 91 | + $data['updated_at'] = date('Y-m-d H:i:s'); |
| 90 | return $this->where($condition)->update($data); | 92 | return $this->where($condition)->update($data); |
| 91 | } | 93 | } |
| 92 | 94 |
| @@ -4,6 +4,7 @@ namespace App\Models; | @@ -4,6 +4,7 @@ namespace App\Models; | ||
| 4 | 4 | ||
| 5 | //use Illuminate\Contracts\Auth\MustVerifyEmail; | 5 | //use Illuminate\Contracts\Auth\MustVerifyEmail; |
| 6 | use App\Models\ProjectRole as ProjectRoleModel; | 6 | use App\Models\ProjectRole as ProjectRoleModel; |
| 7 | +use App\Models\User as UserModel; | ||
| 7 | use Illuminate\Database\Eloquent\Factories\HasFactory; | 8 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 8 | use Illuminate\Database\Eloquent\Model; | 9 | use Illuminate\Database\Eloquent\Model; |
| 9 | //use Illuminate\Foundation\Auth\User as Authenticatable; | 10 | //use Illuminate\Foundation\Auth\User as Authenticatable; |
| @@ -16,7 +17,8 @@ class User extends Base | @@ -16,7 +17,8 @@ class User extends Base | ||
| 16 | use HasApiTokens, HasFactory, Notifiable; | 17 | use HasApiTokens, HasFactory, Notifiable; |
| 17 | 18 | ||
| 18 | protected $table = 'gl_project_user'; | 19 | protected $table = 'gl_project_user'; |
| 19 | - | 20 | + //自动维护create_at创建时间 updated_at修改时间 |
| 21 | + public $timestamps = true; | ||
| 20 | /** | 22 | /** |
| 21 | * The attributes that are mass assignable. | 23 | * The attributes that are mass assignable. |
| 22 | * | 24 | * |
| @@ -34,7 +36,7 @@ class User extends Base | @@ -34,7 +36,7 @@ class User extends Base | ||
| 34 | * @var array<int, string> | 36 | * @var array<int, string> |
| 35 | */ | 37 | */ |
| 36 | protected $hidden = [ | 38 | protected $hidden = [ |
| 37 | - 'password', | 39 | +// 'password', |
| 38 | 'remember_token', | 40 | 'remember_token', |
| 39 | ]; | 41 | ]; |
| 40 | 42 | ||
| @@ -88,4 +90,44 @@ class User extends Base | @@ -88,4 +90,44 @@ class User extends Base | ||
| 88 | } | 90 | } |
| 89 | return $info; | 91 | return $info; |
| 90 | } | 92 | } |
| 93 | + | ||
| 94 | + //新增用户 | ||
| 95 | + public function adds($param){ | ||
| 96 | + //验证当前用户是否存在 | ||
| 97 | + $info = $this->read(['mobile'=>$param['mobile']]); | ||
| 98 | + if(!empty($info)){ | ||
| 99 | + return false; | ||
| 100 | + } | ||
| 101 | + //密码加密 | ||
| 102 | + $param['password'] = base64_encode(md5($param['password'])); | ||
| 103 | + $rs = $this->add($param); | ||
| 104 | + if($rs === false){ | ||
| 105 | + return false; | ||
| 106 | + } | ||
| 107 | + return true; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * @param $param | ||
| 112 | + * @name :编辑管理员 | ||
| 113 | + * @return bool | ||
| 114 | + * @author :liyuhang | ||
| 115 | + * @method | ||
| 116 | + */ | ||
| 117 | + public function edits($param){ | ||
| 118 | + //查看密码是否修改 | ||
| 119 | + $info = $this->read(['id'=>$param['id']]); | ||
| 120 | + if($param['password'] == $info['password']){ | ||
| 121 | + unset($param['password']); | ||
| 122 | + } | ||
| 123 | + //密码加密 | ||
| 124 | + $param['password'] = base64_encode(md5($param['password'])); | ||
| 125 | + $rs = $this->edit($param,['id'=>$param['id']]); | ||
| 126 | + if($rs === false){ | ||
| 127 | + return false; | ||
| 128 | + } | ||
| 129 | + //清空当前用户登录缓存 | ||
| 130 | + Cache::pull($info['token']); | ||
| 131 | + return true; | ||
| 132 | + } | ||
| 91 | } | 133 | } |
-
请 注册 或 登录 后发表评论