|
@@ -4,7 +4,10 @@
|
|
namespace app\bug\controller;
|
|
namespace app\bug\controller;
|
|
|
|
|
|
|
|
|
|
-use app\bug\model\WorkUser;use app\user\model\Account;use think\App;use think\facade\Validate;
|
|
|
|
|
|
+use app\bug\model\WorkUser;
|
|
|
|
+use app\user\model\Account;
|
|
|
|
+use think\App;
|
|
|
|
+use think\facade\Validate;
|
|
class WorkRole extends Base{
|
|
class WorkRole extends Base{
|
|
public function __construct(App $app) {
|
|
public function __construct(App $app) {
|
|
parent::__construct($app);
|
|
parent::__construct($app);
|
|
@@ -69,11 +72,26 @@ class WorkRole extends Base{
|
|
if($info->isEmpty()) return error('岗位角色不存在');
|
|
if($info->isEmpty()) return error('岗位角色不存在');
|
|
return success('获取成功',$info);
|
|
return success('获取成功',$info);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ public function status(){
|
|
|
|
+ $param = $this->request->param(['id'=>'','status'=>''],'post','trim');
|
|
|
|
+ $valid = Validate::rule([
|
|
|
|
+ 'id|账户角色ID'=>'require|number|gt:0',
|
|
|
|
+ 'status|状态'=>'require|number|in:0,1'
|
|
|
|
+ ]);
|
|
|
|
+ if($valid->check($param)==false) return error($valid->getError());
|
|
|
|
+ $info = $this->model->findOrEmpty($param['id']);
|
|
|
|
+ if($info->isEmpty())return error('岗位角色信息不存在');
|
|
|
|
+ $info->status=$param['status'];
|
|
|
|
+ $add = $info->save();
|
|
|
|
+ $messg= WorkRole::$statusCn[$param['status']];
|
|
|
|
+ return $add ? success("岗位角色{$messg}成功"):error("岗位角色{$messg}失败");
|
|
|
|
+ }
|
|
public function delete(){
|
|
public function delete(){
|
|
$id = $this->request->post('id/d');
|
|
$id = $this->request->post('id/d');
|
|
$info = $this->model->findOrEmpty($id);
|
|
$info = $this->model->findOrEmpty($id);
|
|
if($info->isEmpty()) return error('岗位角色不存在');
|
|
if($info->isEmpty()) return error('岗位角色不存在');
|
|
|
|
+ $user = WorkUser::where(["role_id"=>$id])->findOrEmpty();
|
|
|
|
+ if($user->isEmpty()==false)return error('岗位角色有账户正在使用无法删除');
|
|
$delete = $info->delete();
|
|
$delete = $info->delete();
|
|
return $delete ? success('删除成功'):error('删除失败');
|
|
return $delete ? success('删除成功'):error('删除失败');
|
|
}
|
|
}
|
|
@@ -86,6 +104,9 @@ class WorkRole extends Base{
|
|
if($param['role_name']!='')$where[]=['role_name','like',"%{$param['role_name']}%"];
|
|
if($param['role_name']!='')$where[]=['role_name','like',"%{$param['role_name']}%"];
|
|
if($param['work_id']!='')$where[]=['work_id','=',$param['work_id']];
|
|
if($param['work_id']!='')$where[]=['work_id','=',$param['work_id']];
|
|
$list =$this->model->where($where)->order('id desc')->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
|
|
$list =$this->model->where($where)->order('id desc')->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
|
|
|
|
+ foreach ($list->items() as &$item){
|
|
|
|
+ $item["usedNum"] = WorkUser::where(['role_id'=>$item->id])->count();
|
|
|
|
+ }
|
|
return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
|
|
return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -130,4 +151,48 @@ class WorkRole extends Base{
|
|
$add = $info->save();
|
|
$add = $info->save();
|
|
return $add ? success('账户角色设置成功'):error('账户角色设置失败');
|
|
return $add ? success('账户角色设置成功'):error('账户角色设置失败');
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function WorkRoleStatus(){
|
|
|
|
+ $param=$this->request->param(['id'=>'','status'=>''],'post','trim');
|
|
|
|
+ $valid = Validate::rule([
|
|
|
|
+ 'id|账户角色ID'=>'require|number|gt:0',
|
|
|
|
+ 'status|状态'=>'require|number|in:0,1,4'
|
|
|
|
+ ]);
|
|
|
|
+ if($valid->check($param)==false) return error($valid->getError());
|
|
|
|
+ $info = WorkUser::where(['id'=>$param['id']])->findOrEmpty();
|
|
|
|
+ if($info->isEmpty())return error('账户角色信息不存在');
|
|
|
|
+ $info->status=$param['status'];
|
|
|
|
+ $add = $info->save();
|
|
|
|
+ $messg= WorkUser::$statusCn[$param['status']];
|
|
|
|
+ return $add ? success("账户角色{$messg}成功"):error("账户角色{$messg}失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function WorkRoleInfo(){
|
|
|
|
+ $id=$this->request->post("id/d");
|
|
|
|
+ $info = WorkUser::where(['id'=>$id])->findOrEmpty();
|
|
|
|
+ if($info->isEmpty())return error('账户角色信息不存在');
|
|
|
|
+ $info->statusCn= WorkUser::$statusCn[$info->status];
|
|
|
|
+ return success("获取成功",$info);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function WorkRoleDelete(){
|
|
|
|
+ $id=$this->request->post('id/d');
|
|
|
|
+ $info = WorkUser::where(['id'=>$id])->findOrEmpty();
|
|
|
|
+ if($info->isEmpty())return error('账户角色信息不存在');
|
|
|
|
+ if($info->status==1 || $info->status==2 )return error('账户角色状态不可删除');
|
|
|
|
+ return success('获取成功',$info);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function WorkRoleList(){
|
|
|
|
+ $param = $this->request->param(['role_name'=>'','companyNo'=>'','belong'=>'','account_id'=>'','page'=>1,
|
|
|
|
+ 'size'=>15],'post','trim');
|
|
|
|
+ $where=[];
|
|
|
|
+ if($param['companyNo']!='')$where[]=['companyNo','=',$param['companyNo']];
|
|
|
|
+ if($param['belong']!='')$where[]=['belong','=',$param['belong']];
|
|
|
|
+ if($param['role_name']!='')$where[]=['role_name','like',"%{$param['role_name']}%"];
|
|
|
|
+ if($param['work_id']!='')$where[]=['work_id','=',$param['work_id']];
|
|
|
|
+ $list =WorkUser::with(["account"])->withJoin(["workRole"],"left")->where($where)->order('workUser.id desc')
|
|
|
|
+ ->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
|
|
|
|
+ return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
|
|
|
|
+ }
|
|
}
|
|
}
|