model=new \app\bug\model\Work(); } //岗位模板新建 public function create(){ $param=$this->request->param([ "work_name"=>"", "belong"=>"", "level"=>"", "actionInfo"=>[] ],"post","trim"); $valid =Validate::rule([ "work_name|岗位名称"=>"require|max:200|unique:\app\bug\model\Work,work_name^belong", "belong|系统归属"=>"require|number|in:1,2,3", "level|账户等级"=>"require|number|in:1,2,3", "action|功能权限"=>"array" ]); if($valid->check($param)==false)return error($valid->getError()); $data = [ 'work_name'=>$param['work_name'], 'belong'=>$param['belong'], 'level'=>$param['level'], 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, ]; $action=[]; if(!empty($param['actionInfo'])){ $valid_action =Validate::rule([ 'belong_action|系统功能集合'=>'require|array', 'belong_process|系统流程集合'=>'array', 'belong_private|系统私有功能集合'=>'array', 'menu_id|菜单页面Id'=>'require|number', 'action_name|岗位功能名称'=>'require|max:255', ]); foreach ($param['actionInfo'] as $item){ if($valid_action->check($item)==false)return error($valid_action->getError()); $item['belong']=$param['belong']; $item['apply_id']=$this->uid; $item['apply_name']=$this->uname; $action[]=$item; } } $this->model->startTrans(); try { $add = \app\bug\model\Work::create($data); if($add->isEmpty()) throw new Exception("岗位创建失败"); if(!empty($action)){ $tempAction = (new WorkAction())->CreateByArray($action); $Template = [ "work_id"=>$add->id, "action"=>$tempAction, 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, ]; $temp=WorkTemplate::create($Template); if($temp->isEmpty()) throw new Exception('岗位创建失败'); } $this->model->commit(); return success('创建成功'); }catch (\Exception $exception){ $this->model->rollback(); return error($exception->getMessage()); } } //岗位模板新建 public function save(){ $param=$this->request->param(["id"=>"",'work_name'=>'','belong'=>'','action'=>[],'level'=>''],'post','trim'); $valid =Validate::rule([ 'id|岗位ID'=>'require|number|gt:0', 'work_name|岗位名称'=>'require|max:200|unique:\app\bug\model\Work,work_name^belong', 'belong|系统归属'=>'require|number|in:1,2,3', 'action|功能权限'=>'array', 'level|账户等级'=>'require|number|in:1,2,3' ]); if($valid->check($param)==false)return error($valid->getError()); $info = $this->model->with(['workTemplate'])->findOrEmpty($param['id']); if($info->isEmpty()) error("未找到数据"); $info->work_name= $param['work_name']; $info->belong= $param['belong']; $info->level= $param['level']; $info->work_name= $param['work_name']; $this->model->startTrans(); try { $add = $info->save(); if($add==false) throw new Exception('岗位编辑失败'); if(is_null($info->workTemplate)){ $up=$info->workTemplate() ->save([ 'action'=>$param['action'], 'work_id'=>$info->id, 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, ]); }else{ $info->workTemplate->action=$param['action']; $info->workTemplate->apply_id=$this->uid; $info->workTemplate->apply_name=$this->uname; $up=$info->workTemplate->save(); } if($up==false) throw new Exception('岗位编辑失败'); $this->model->commit(); return success('岗位编辑成功'); }catch (\Exception $exception){ $this->model->rollback(); return error($exception->getMessage()); } } public function info(){ $id=$this->request->post("id/d"); $info = $this->model->with(['workTemplate'])->findOrEmpty($id); if($info->isEmpty()) error("未找到数据"); if(!is_null($info->workTemplate))$info->workTemplate->actionInfo= (new WorkAction())->GetTreeActionByIdArr ($info->workTemplate->action,$info->belong); return success('查询成功',$info); } //岗位模板新建 public function delete(){ $id=$this->request->post("id/d"); $info = $this->model->findOrEmpty($id); if($info->isEmpty())return error('未找到数据'); $used = \app\bug\model\WorkRole::where('work_id','=',$id)->findOrEmpty(); if(!$used->isEmpty())return error('该岗位已使用,不能删除'); $add = $info->delete(); return $add ? success('删除成功'):error('删除失败'); } //岗位模板新建 public function list(){ $param=$this->request->param(['work_name'=>'','belong'=>'','status'=>'','level'=>'','size'=>1,'page'=>15],'post','trim'); $where=[]; if($param['level']!='')$where[]=['level','=',$param['level']]; if($param['belong']!='')$where[]=['belong','=',$param['belong']]; if($param['status']!='')$where[]=['status','=',$param['status']]; if($param['work_name']!='')$where[]=['work_name','like',"%{$param['work_name']}%"]; $list =$this->model->where($where)->order('id desc')->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]); return success('获取成功',['list'=>$list->items(),'count'=>$list->total()]); } //岗位模板新建 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']; $status=\app\bug\model\Work::$statusCn[$param['status']]; $add = $info->save(); return $add ? success("{$status}成功"):error("{$status}失败"); } public function WorkActionCreate(){ $param=$this->request->param([ 'belong_action'=>[], 'belong_process'=>[], 'belong_private'=>[], 'menu_id'=>'', 'work_id'=>'', 'belong'=>0, 'action_name'=>''],'post','trim'); $valid =Validate::rule([ 'belong_action|系统功能集合'=>'require|array', 'belong_process|系统流程集合'=>'array', 'belong_private|系统流程集合'=>'array', 'menu_id|菜单页面Id'=>'require|number', 'work_id|岗位Id'=>'require|number', 'belong|系统归属'=>'number|in:0,1,2,3', 'action_name|功能名称'=>'require|max:255', ]); if($valid->check($param)==false)return error($valid->getError()); $work = $this->model->with(["workTemplate"])->findOrEmpty($param['work_id']); if($work->isEmpty())return error("岗位信息不存在"); $this->model->startTrans(); try{ $data = [ 'action_name'=>$param['action_name'], 'belong'=>$param['belong'], 'menu_id'=>$param['menu_id'], 'belong_action'=>$param['belong_action'], 'belong_process'=>$param['belong_process'], 'belong_private'=>$param['belong_private'], 'apply_id'=>$this->uid, 'apply_name'=>$this->uname, ]; $add = WorkAction::create($data); if($add->isEmpty()) return error("功能新建失败"); if(is_null($work->workTemplate)){ $up=$work->workTemplate() ->save([ "action"=>[$add->id], "work_id"=>$param['work_id'], "apply_id"=>$this->uid, "apply_name"=>$this->uname, ]); }else{ $action = $work->workTemplate->action; array_push($action,$add->id); $work->workTemplate->action=$action; $work->workTemplate->apply_id=$this->uid; $work->workTemplate->apply_name=$this->uname; $up=$work->workTemplate->save(); } if($up==false) return error('功能新建失败'); $this->model->commit(); return success("创建成功"); }catch (\Exception $e){ $this->model->rollback(); return error($e->getMessage()); } } public function WorkActionSave(){ $param=$this->request->param([ "id"=>"", 'belong_action'=>[], 'belong_process'=>[], 'belong_private'=>[], 'menu_id'=>'', 'belong'=>0, 'action_name'=>''],'post','trim'); $valid =Validate::rule([ 'id|岗位功能ID'=>'require|number', 'belong_action|系统功能集合'=>'require|array', 'belong_process|系统流程集合'=>'array', 'belong_private|系统私有功能集合'=>'array', 'menu_id|菜单页面Id'=>'require|number', 'belong|系统归属'=>'number|in:0,1,2,3', 'action_name|岗位功能名称'=>'require|max:255', ]); if($valid->check($param)==false)return error($valid->getError()); $info= WorkAction::where(["id"=>$param['id']])->findOrEmpty(); if($info->isEmpty())return error("数据为找到"); $info->action_name=$param['action_name']; $info->belong=$param['belong']; $info->menu_id=$param['menu_id']; $info->belong_action=$param['belong_action']; $info->belong_process=$param['belong_process']; $info->belong_private=$param['belong_private']; $add = $info->save(); return $add ? success('岗位功能修改成功'):error('岗位功能修改失败'); } public function WorkActionDelete(){ $id=$this->request->post('id/d'); $info = WorkAction::where(['id'=>$id])->findOrEmpty(); if($info->isEmpty()) error('未找到数据'); $add = $info->delete(); return $add ? success('删除成功'):error('删除失败'); } public function WorkActionInfo(){ $id=$this->request->post('id/d'); $info = WorkAction::where(['id'=>$id])->findOrEmpty(); if($info->isEmpty()) error('未找到数据'); $meun = $info->GetMenuList($info->menu_id,$info->belong); $info->belong_action_info = $info->GetActionList($info->belong_action,$info->belong); $info->belong_private_info = $info->GetActionList($info->belong_private,$info->belong); $info->belong_process_info = $info->GetProcessList($info->belong_process,$info->belong); return success('获取成功',array_merge($info->toArray(),$meun)); } public function WorkActionList(){ $param=$this->request->param(['menu_id'=>'','belong'=>0,'action_name'=>'',"page"=>1,"size"=>15],'post','trim'); $where=[]; if($param['menu_id']!="")$where[]=["menu_id","=",$param['menu_id']]; if($param['belong']!="")$where[]=["belong","=",$param['belong']]; if($param['action_name']!="")$where[]=["action_name","like","%{$param['action_name']}%"]; $list = WorkAction::where($where)->order("id desc")->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]); return success("获取成功",["list"=>$list->items(),"count"=>$list->total()]); } public function WorkTemplateSave(){ $param=$this->request->param(["work_id"=>"","action"=>[]],"post","trim"); $valid =Validate::rule([ 'work_id|岗位ID'=>'require|number', 'action|岗位功能集合'=>'require|array' ]); if($valid->check($param)==false)return error($valid->getError()); $info= WorkTemplate::where(['work_id'=>$param['work_id']])->findOrEmpty(); $info->work_id=$param['work_id']; $info->action=$param['action']; $add = $info->save(); return $add ? success('岗位模板修改成功'):error('岗位模板修改失败'); } public function WorkTemplateInfo(){ $work_id=$this->request->post('work_id/d'); $info= WorkTemplate::with(["workInfo"])->where(['work_id'=>$work_id])->findOrEmpty(); if(!$info->isEmpty()) { $info->actionInfo= (new WorkAction())->GetTreeActionByIdArr($info->action,$info->workInfo->belong); } return success('获取成功',$info); } }