|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bside;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Models\ProjectRole as ProjectRoleModel;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
|
|
class ProjectRoleController extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @name :用户角色列表()
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function lists(){
|
|
|
|
$projectRoleModel = new ProjectRoleModel();
|
|
|
|
$lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);
|
|
|
|
$this->result($lists);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :添加角色
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function add(){
|
|
|
|
//参数验证
|
|
|
|
$rules = [
|
|
|
|
'name'=>'required|max:11',
|
|
|
|
'role_menu'=>'required|string',
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'name.required'=>'名称必须填写',
|
|
|
|
'name.max' => '号码不大于11字符.',
|
|
|
|
'role_menu.required'=>'密码必须填写',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
|
|
|
|
}
|
|
|
|
$projectRoleModel = new ProjectRoleModel();
|
|
|
|
//验证当前角色是否存在
|
|
|
|
if(!isset($this->param['pid'])){
|
|
|
|
$data['pid'] = 0;
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'name' => $this->param['name'],
|
|
|
|
'pid' => $this->param['pid'],
|
|
|
|
];
|
|
|
|
$info = $projectRoleModel->read($data);
|
|
|
|
if(!empty($info)){
|
|
|
|
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$rs = $projectRoleModel->add($this->param);
|
|
|
|
if($rs === false){
|
|
|
|
$this->response('添加失败',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$this->response('添加成功',Code::SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :编辑角色
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function edit(){
|
|
|
|
//参数验证
|
|
|
|
$rules = [
|
|
|
|
'id'=>'required',
|
|
|
|
'name'=>'required|max:11',
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'id.required'=>'主键必须填写',
|
|
|
|
'name.required'=>'名称必须填写',
|
|
|
|
'name.max' => '号码不大于11字符.',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
|
|
|
|
}
|
|
|
|
//验证当前角色是否存在
|
|
|
|
if(!isset($this->param['pid'])){
|
|
|
|
$data['pid'] = 0;
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'name' => $this->param['name'],
|
|
|
|
'pid' => $this->param['pid'],
|
|
|
|
];
|
|
|
|
$projectRoleModel = new ProjectRoleModel();
|
|
|
|
$info = $projectRoleModel->read($data);
|
|
|
|
if(!empty($info)){
|
|
|
|
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$this->response('编辑成功',Code::SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :修改用户状态
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function status(){
|
|
|
|
//参数验证
|
|
|
|
$rules = [
|
|
|
|
'id'=>'required',
|
|
|
|
'status'=>'required',
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'id.required'=>'主键必须填写',
|
|
|
|
'status.required'=>'状态必须填写',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
|
|
|
|
}
|
|
|
|
$projectRoleModel = new ProjectRoleModel();
|
|
|
|
$rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|