|
@@ -0,0 +1,226 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace app\bug\controller;
|
|
|
+
|
|
|
+
|
|
|
+use app\bug\model\WorkAction;use app\bug\model\WorkSubinfo;use app\bug\model\WorkSubscr;use think\App;use think\Exception;use think\facade\Validate;
|
|
|
+class Subscribe extends Base{
|
|
|
+ public function __construct(App $app) {
|
|
|
+ parent::__construct($app);
|
|
|
+ $this->model=new WorkSubscr();
|
|
|
+ }
|
|
|
+
|
|
|
+ //岗位功能申请新建
|
|
|
+ public function create(){
|
|
|
+ $param=$this->request->param(['action'=>'','belong'=>'',"change_action"=>[]],'post','trim');
|
|
|
+ $valid =Validate::rule([
|
|
|
+ 'action|岗位角色功能'=>'require|array',
|
|
|
+ 'belong|系统归属'=>'require|number|in:1,2,3',
|
|
|
+ 'change_action|岗位角色功能修改记录'=>'require|array'
|
|
|
+ ]);
|
|
|
+ if($valid->check($param)==false)return error($valid->getError());
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'belong'=>$param['belong'],
|
|
|
+ 'action'=>$param['action'],
|
|
|
+ 'role_action'=>WorkAction::where("id","=",$this->roleid)->value("action",""),
|
|
|
+ 'role_id'=>$this->roleid,
|
|
|
+ 'apply_id'=>$this->uid,
|
|
|
+ 'apply_name'=>$this->uname,
|
|
|
+ ];
|
|
|
+ $info=[];
|
|
|
+ if(!empty($param['change_action'])){
|
|
|
+ $valid_item = Validate::rule([
|
|
|
+ 'action_id|岗位功能'=>'require|array',
|
|
|
+ 'type|类型'=>'require|number|in:1,2',
|
|
|
+ 'remark|备注'=>'max:255'
|
|
|
+ ]);
|
|
|
+ $workAction =new WorkAction();
|
|
|
+ foreach ($param['change_action'] as $item){
|
|
|
+ if($valid_item->check($item)==false)return error($valid_item->getError());
|
|
|
+ $temp=[];
|
|
|
+ $temp['sub_id']="";
|
|
|
+ $temp['content']=$workAction->GetInfoById($item['action_id'],$param['belong']);
|
|
|
+ $temp['action_id']=$item['action_id'];
|
|
|
+ $temp['type']=$item['type'];
|
|
|
+ $temp['remark']=$item['remark']??"";
|
|
|
+ $info[]=$temp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->model->startTrans();
|
|
|
+ try{
|
|
|
+ $sub = WorkSubscr::create($data);
|
|
|
+ if($sub->isEmpty())throw new Exception("功能申请创建失败");
|
|
|
+ if(empty($info)==false){
|
|
|
+ foreach ($info as &$item) {
|
|
|
+ $item['sub_id'] = $sub->id;
|
|
|
+ }
|
|
|
+ WorkSubinfo::saveAll($info);
|
|
|
+ }
|
|
|
+ $this->model->commit();
|
|
|
+ return success("功能申请创建成功");
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->model->rollback();
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ ////岗位功能申请编辑
|
|
|
+ public function save(){
|
|
|
+ $param=$this->request->param(['id'=>'','action'=>'','belong'=>'','change_action'=>[]],'post','trim');
|
|
|
+ $valid =Validate::rule([
|
|
|
+ 'id|岗位角色功能申请id'=>'require|number|gt:0',
|
|
|
+ 'action|岗位角色功能'=>'require|array',
|
|
|
+ 'belong|系统归属'=>'require|number|in:1,2,3',
|
|
|
+ 'change_action|岗位角色功能修改记录'=>'require|array'
|
|
|
+ ]);
|
|
|
+ if($valid->check($param)==false)return error($valid->getError());
|
|
|
+ $workInfo= $this->model->findOrEmpty($param['id']);
|
|
|
+ if($workInfo->isEmpty())return error("功能申请未找到数据");
|
|
|
+ if($workInfo->status!=1)return error("功能申请当前状态不可修改");
|
|
|
+ $workInfo->belong= $param['belong'];
|
|
|
+ $workInfo->action= $param['action'];
|
|
|
+ $workInfo->role_action= WorkAction::where('id','=',$this->roleid)->value('action','');
|
|
|
+ $workInfo->role_id= $this->roleid;
|
|
|
+ $workInfo->apply_id= $this->uid;
|
|
|
+ $workInfo->apply_name= $this->uid;
|
|
|
+ $info=[];
|
|
|
+ $keepId=[];
|
|
|
+ if(!empty($param['change_action'])){
|
|
|
+ $valid_item = Validate::rule([
|
|
|
+ 'action_id|岗位功能'=>'require|array',
|
|
|
+ 'type|类型'=>'require|number|in:1,2',
|
|
|
+ 'remark|备注'=>'max:255'
|
|
|
+ ]);
|
|
|
+ $workAction =new WorkAction();
|
|
|
+ foreach ($param['change_action'] as $item){
|
|
|
+ if($valid_item->check($item)==false)return error($valid_item->getError());
|
|
|
+ if(isset($item['id']) &&$item['id']>0){
|
|
|
+ $keepId[]=$item['id'];
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $temp=[];
|
|
|
+ $temp['sub_id']=$workInfo->id;
|
|
|
+ $temp['content']=$workAction->GetInfoById($item['action_id'],$param['belong']);
|
|
|
+ $temp['action_id']=$item['action_id'];
|
|
|
+ $temp['type']=$item['type'];
|
|
|
+ $temp['remark']=$item['remark']??'';
|
|
|
+ $info[]=$temp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->model->startTrans();
|
|
|
+ try{
|
|
|
+ $sub = $workInfo->save();
|
|
|
+ if($sub)throw new Exception('功能申请修改失败');
|
|
|
+ if(empty($keepId)==false){
|
|
|
+ $delete =WorkSubinfo::where([["id","not in",$keepId],["sub_id","=",$workInfo->id]])->select();
|
|
|
+ if($delete->isEmpty()==false){
|
|
|
+ $del=$delete->delete();
|
|
|
+ if($del==false)throw new Exception('功能申请修改失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(empty($info)==false)WorkSubinfo::saveAll($info);
|
|
|
+ $this->model->commit();
|
|
|
+ return success('功能申请修改成功');
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->model->rollback();
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //岗位功能申请删除
|
|
|
+ public function delete(){
|
|
|
+ $id=$this->request->post('id/d');
|
|
|
+ $info = $this->model->findOrEmpty($id);
|
|
|
+ if($info->isEmpty()) error('未找到数据');
|
|
|
+ if($info->status!=1) error('当前状态不可删除');
|
|
|
+ $add = $info->delete();
|
|
|
+ return $add ? success('删除成功'):error('删除失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //岗位功能申请详情
|
|
|
+ public function info(){
|
|
|
+ $id=$this->request->post('id/d');
|
|
|
+ $info = $this->model->with(['roleInfo',"subInfo"])->findOrEmpty($id);
|
|
|
+ if($info->isEmpty()) error('未找到数据');
|
|
|
+ return success('获取成功',$info);
|
|
|
+ }
|
|
|
+ //岗位模板新建
|
|
|
+ public function list(){
|
|
|
+ $param=$this->request->param(['status'=>'','role_id'=>'','apply_id'=>'','belong'=>'','level'=>'','size'=>1,
|
|
|
+ 'page'=>15],'post','trim');
|
|
|
+ $where=[];
|
|
|
+ if($param['status']!='')$where[]=['status','=',$param['status']];
|
|
|
+ if($param['belong']!='')$where[]=['belong','=',$param['belong']];
|
|
|
+ if($param['role_id']!='')$where[]=['role_id','=',$param['role_id']];
|
|
|
+ if($param['apply_id']!='')$where[]=['apply_id','=',$param['apply_id']];
|
|
|
+ $list =$this->model->with(["roleInfo",'subInfo'])->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:1,2,3,4,5'
|
|
|
+ ]);
|
|
|
+ if($valid->check($param)==false)return error($valid->getError());
|
|
|
+ $info = $this->model->findOrEmpty($param['id']);
|
|
|
+ if($info->isEmpty())return error('未找到数据');
|
|
|
+ $info->status= $param['status'];
|
|
|
+ $info->check_id= $this->uid;
|
|
|
+ $info->check_name= $this->uname;
|
|
|
+ $status=WorkSubscr::$statusCn[$param['status']];
|
|
|
+ $add = $info->save();
|
|
|
+ return $add ? success("{$status}成功"):error("{$status}失败");
|
|
|
+ }
|
|
|
+ public function infoStatus(){
|
|
|
+ $param=$this->request->param(['id'=>'','status'=>'','remark'=>''],'post','trim');
|
|
|
+ $valid =Validate::rule([
|
|
|
+ 'id|功能申请ID'=>'require|number|gt:0',
|
|
|
+ 'status|状态'=>'require|number|in:1,2',
|
|
|
+ 'remark|备注'=>'max:255'
|
|
|
+ ]);
|
|
|
+ if($valid->check($param)==false)return error($valid->getError());
|
|
|
+ $info = WorkSubinfo::with(['workSub'])->where("id",$param['id'])->findOrEmpty();
|
|
|
+ if($info->isEmpty())return error('未找到数据');
|
|
|
+ if($info->status!=0)return error('数据已审核');
|
|
|
+ if($info->workSub->status!=1)return error('功能申请状态有误不可审批');
|
|
|
+ $info->status= $param['status'];
|
|
|
+ $info->remark= $param['remark'];
|
|
|
+ $status=WorkSubscr::$statusCn[$param['status']];
|
|
|
+ $this->model->startTrans();
|
|
|
+ try{
|
|
|
+ $add = $info->save();
|
|
|
+ if($add==false)throw new Exception("{$status}失败");
|
|
|
+ $statusArr= WorkSubinfo::where('sub_id',$info->sub_id)->column('status');
|
|
|
+ $statusSub = $info->workSub->status;
|
|
|
+ if(count(array_unique($statusArr))==1){
|
|
|
+ if(in_array(1,$statusArr)){
|
|
|
+ $statusSub = 3;
|
|
|
+ }
|
|
|
+ if(in_array(2,$statusArr)){
|
|
|
+ $statusSub =4;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(in_array(1,$statusArr)){
|
|
|
+ $statusSub = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $info->workSub->status =$statusSub;
|
|
|
+ $info->workSub->check_id =$this->uid;
|
|
|
+ $info->workSub->check_name =$this->uname;
|
|
|
+ $subup=$info->workSub->save();
|
|
|
+ if($subup==false)throw new Exception("{$status}失败");
|
|
|
+ return success("{$status}成功");
|
|
|
+ $this->model->commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->model->rollback();
|
|
|
+ return error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|