作者 root

gx

  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +
  6 +
  7 +class MenuController extends BaseController
  8 +{
  9 + public function lists(){
  10 + //TODO::搜索参数处理
  11 + $userLogic = new UserLogic();
  12 + $lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
  13 + if(empty($lists)){
  14 + $this->response('请求失败','b00001',[]);
  15 + }
  16 + $this->result($lists);
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +class ProjectMenuController extends BaseController
  6 +{
  7 + /**
  8 + * @name :菜单列表
  9 + * @return void
  10 + * @author :liyuhang
  11 + * @method
  12 + */
  13 + public function lists(){
  14 + //根据角色获取菜单列表
  15 +
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\ProjectRole as ProjectRoleModel;
  7 +use Illuminate\Support\Facades\Validator;
  8 +
  9 +class ProjectRoleController extends BaseController
  10 +{
  11 + /**
  12 + * @name :用户角色列表()
  13 + * @return void
  14 + * @author :liyuhang
  15 + * @method
  16 + */
  17 + public function lists(){
  18 + $projectRoleModel = new ProjectRoleModel();
  19 + $lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);
  20 + $this->result($lists);
  21 + }
  22 +
  23 + /**
  24 + * @name :添加角色
  25 + * @return void
  26 + * @author :liyuhang
  27 + * @method
  28 + */
  29 + public function add(){
  30 + //参数验证
  31 + $rules = [
  32 + 'name'=>'required|max:11',
  33 + 'role_menu'=>'required|string',
  34 + ];
  35 + //验证的提示信息
  36 + $message = [
  37 + 'name.required'=>'名称必须填写',
  38 + 'name.max' => '号码不大于11字符.',
  39 + 'role_menu.required'=>'密码必须填写',
  40 + ];
  41 + $validate = Validator::make($this->param, $rules, $message);
  42 + if($validate->fails()){
  43 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  44 + }
  45 + $projectRoleModel = new ProjectRoleModel();
  46 + //验证当前角色是否存在
  47 + if(!isset($this->param['pid'])){
  48 + $data['pid'] = 0;
  49 + }
  50 + $data = [
  51 + 'name' => $this->param['name'],
  52 + 'pid' => $this->param['pid'],
  53 + ];
  54 + $info = $projectRoleModel->read($data);
  55 + if(!empty($info)){
  56 + $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
  57 + }
  58 + $rs = $projectRoleModel->add($this->param);
  59 + if($rs === false){
  60 + $this->response('添加失败',Code::USER_PARAMS_ERROE);
  61 + }
  62 + $this->response('添加成功',Code::SUCCESS);
  63 + }
  64 +
  65 + /**
  66 + * @name :编辑角色
  67 + * @return void
  68 + * @author :liyuhang
  69 + * @method
  70 + */
  71 + public function edit(){
  72 + //参数验证
  73 + $rules = [
  74 + 'id'=>'required',
  75 + 'name'=>'required|max:11',
  76 + ];
  77 + //验证的提示信息
  78 + $message = [
  79 + 'id.required'=>'主键必须填写',
  80 + 'name.required'=>'名称必须填写',
  81 + 'name.max' => '号码不大于11字符.',
  82 + ];
  83 + $validate = Validator::make($this->param, $rules, $message);
  84 + if($validate->fails()){
  85 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  86 + }
  87 + //验证当前角色是否存在
  88 + if(!isset($this->param['pid'])){
  89 + $data['pid'] = 0;
  90 + }
  91 + $data = [
  92 + 'name' => $this->param['name'],
  93 + 'pid' => $this->param['pid'],
  94 + ];
  95 + $projectRoleModel = new ProjectRoleModel();
  96 + $info = $projectRoleModel->read($data);
  97 + if(!empty($info)){
  98 + $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
  99 + }
  100 + $rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);
  101 + if($rs === false){
  102 + $this->response('编辑失败',Code::USER_PARAMS_ERROE);
  103 + }
  104 + $this->response('编辑成功',Code::SUCCESS);
  105 + }
  106 +
  107 + /**
  108 + * @name :修改用户状态
  109 + * @return void
  110 + * @author :liyuhang
  111 + * @method
  112 + */
  113 + public function status(){
  114 + //参数验证
  115 + $rules = [
  116 + 'id'=>'required',
  117 + 'status'=>'required',
  118 + ];
  119 + //验证的提示信息
  120 + $message = [
  121 + 'id.required'=>'主键必须填写',
  122 + 'status.required'=>'状态必须填写',
  123 + ];
  124 + $validate = Validator::make($this->param, $rules, $message);
  125 + if($validate->fails()){
  126 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  127 + }
  128 + $projectRoleModel = new ProjectRoleModel();
  129 + $rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
  130 + if($rs === false){
  131 + $this->response('编辑失败',Code::USER_PARAMS_ERROE);
  132 + }
  133 + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
  134 + }
  135 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class Menu extends Base
  6 +{
  7 + protected $table = 'gl_menu';
  8 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class ProjectMenu extends Base
  6 +{
  7 + //设置关联表名
  8 + protected $table = 'gl_project_Menu';
  9 + //自动维护create_at创建时间 updated_at修改时间
  10 + public $timestamps = true;
  11 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class ProjectRole extends Base
  6 +{
  7 + //设置关联表名
  8 + protected $table = 'gl_project_role';
  9 + //自动维护create_at创建时间 updated_at修改时间
  10 + public $timestamps = true;
  11 +}