wugg 8 months ago
parent
commit
de00692b22

+ 5 - 0
app/admin/model/ActionProcess.php

@@ -31,4 +31,9 @@ class ActionProcess extends Base
         'is_master'       =>'tinyint',//是否主节点,1是,0不是
 
     ];
+    
+    public static function GetProcess($action){
+    	return self::where(['id'=>$action])
+    	->column('id,order_name,status_name');
+    }
 }

+ 1 - 0
app/admin/model/AdminMenu.php

@@ -39,4 +39,5 @@ class AdminMenu extends Base
     	->where(['aid'=>$action])
     	->column("id parent_id,menu_name parent_name,cname menu_name,cid menu_id,action_name,aid action_id");
     }
+    
 }

+ 226 - 0
app/bug/controller/Subscribe.php

@@ -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());
+		}
+		
+	}
+}

+ 0 - 1
app/bug/controller/Work.php

@@ -218,7 +218,6 @@ class Work extends Base{
 		$info= WorkTemplate::where(['work_id'=>$work_id])->findOrEmpty();
 		if($info->isEmpty()) error('未找到数据');
 		$info->actionInfo= (new WorkAction())->GetTreeActionByIdArr($info->action,$info->workInfo->belong);
-		
 		return success('获取成功',$info);
 	}
 }

+ 4 - 2
app/bug/controller/WorkRole.php

@@ -18,7 +18,7 @@ class WorkRole extends Base{
 	public function create(){
         $param = $this->request->param(["role_name"=>"","companyNo"=>"","work_id"=>"","action"=>[]],"post","trim");
         $valid=Validate::rule([
-        	"role_name|角色名称"=>"require|max:255|unique:",
+        	"role_name|角色名称"=>"require|max:255|unique:\app\bug\model\WorkRole,role_name^companyNo^belong",
         	"companyNo|业务公司"=>"require|max:255",
         	"work_id|岗位模板id"=>"require|number",
         	"action|角色权限集合"=>"require|array"
@@ -27,6 +27,7 @@ class WorkRole extends Base{
         $template = \app\bug\model\Work::with(["workTemplate"])->findOrEmpty($param['work_id']);
         if($template->isEmpty()) return error("岗位模板不存在");
         if($template->status==0)return error('岗位模板已禁用');
+         if(empty($template->action??[]))return error('岗位模板权限不能为空');
         if(empty(array_diff($param['action'],$template->action))==false)return error('选择权限超出模板权限范围');
         $data=[
         	"role_name"=>$param['role_name'],
@@ -46,7 +47,7 @@ class WorkRole extends Base{
         $param = $this->request->param(["id"=>"",'role_name'=>'','companyNo'=>'','work_id'=>'','action'=>[]],'post','trim');
         $valid=Validate::rule([
         	'id|岗位角色id'=>'require|number|gt:0',
-        	'role_name|角色名称'=>'require|max:255|unique:',
+        	'role_name|角色名称'=>'require|max:255|unique:\app\bug\model\WorkRole,role_name^companyNo^belong',
         	'companyNo|业务公司'=>'require|max:255',
         	'work_id|岗位模板id'=>'require|number',
         	'action|角色权限集合'=>'require|array'
@@ -57,6 +58,7 @@ class WorkRole extends Base{
         $template = \app\bug\model\Work::with(['workTemplate'])->findOrEmpty($param['work_id']);
         if($template->isEmpty()) return error('岗位模板不存在');
         if($template->status==0)return error('岗位模板已禁用');
+         if(empty($template->action??[]))return error('岗位模板权限不能为空');
         if(empty(array_diff($param['action'],$template->action))==false)return error('选择权限超出模板权限范围');
         $user = WorkUser::where(['role_id'=>$param['id'],"status"=>[1,2]])->findOrEmpty();
         if($user->isEmpty()==false)return error('岗位角色有账户正在使用中无法修改');

+ 1 - 1
app/bug/model/Moudel.php

@@ -3,7 +3,7 @@ namespace app\bug\model;
 
 class Moudel extends Base
 {
-	protected $name="Model";
+//	protected $name="Model";
 //设置字段信息
     protected $schema = [
         'id'       =>'int',//

+ 28 - 1
app/bug/model/WorkAction.php

@@ -41,11 +41,12 @@ class WorkAction extends Base
     }
     
     public function GetTreeActionByIdArr($idArr,$belong=0){
-    	$list = $this->whereIn("id",$idArr)->field("id,action_name,menu_id,belong_action")->select();
+    	$list = $this->whereIn("id",$idArr)->field("id,action_name,menu_id,belong_action,belong_process")->select();
     	$temp=[];
     	foreach ($list as $item){
     		$meun = $this->GetMenuList($item->menu_id,$belong);
     		$item->belong_action_info = $this->GetActionList($item->belong_action,$belong);
+    		$item->belong_process_info = $this->GetProcessList($item->belong_process,$belong);
 		    $temp[]=array_merge($item->toArray(),$meun);
     	}
     	return $temp;
@@ -82,4 +83,30 @@ class WorkAction extends Base
             }
             return$act;
     }
+  
+    public function GetProcessList($action,$belong){
+        	$act=[];
+            switch ($belong){
+            	case 1:
+            		$act=\app\admin\model\ActionProcess::GetProcess($action);
+            		break;
+            		case 2:
+            		$act=\app\admin\model\ActionProcess::GetProcess($action);
+            		break;
+            		case 3:
+            		$act=\app\admin\model\ActionProcess::GetProcess($action);
+            		break;
+            }
+            return$act;
+    }
+    public function GetInfoById($id,$belong=0){
+        $list = $this->where('id',$id)->field('id,action_name,menu_id,belong_action')->findOrEmpty();
+    	$temp=[];
+    	foreach ($list as $item){
+    		$meun = $this->GetMenuList($item->menu_id,$belong);
+    		$item->belong_action_info = $this->GetActionList($item->belong_action,$belong);
+		    $temp[]=array_merge($item->toArray(),$meun);
+    	}
+    	return $temp;
+    }
 }

+ 2 - 1
app/bug/model/WorkRole.php

@@ -1,7 +1,8 @@
 <?php
 namespace app\bug\model;
 
-use app\user\model\Headquarters;use think\model\concern\SoftDelete;class WorkRole extends Base
+use app\user\model\Headquarters;use think\model\concern\SoftDelete;
+class WorkRole extends Base
 {
 	use SoftDelete;
     protected $schema = [

+ 27 - 0
app/bug/model/WorkSubinfo.php

@@ -0,0 +1,27 @@
+<?php
+namespace app\bug\model;
+
+use think\model\concern\SoftDelete;
+class WorkSubinfo extends Base
+{	use SoftDelete;
+//设置字段信息
+    protected $schema = [
+        'id'  =>'bigint',//
+        'sub_id'  =>'int',//岗位申请id
+        'content'  =>'varchar',//功能内容
+        'action_id'  =>'int',//功能id
+        'type'  =>'tinyint',//类型 1添加2删除
+        'status'  =>'tinyint',//状态 0待审批 1同意2驳回
+        'remark'  =>'varchar',//
+        'createTime'  =>'datetime',//
+        'updateTime'  =>'datetime',//
+        'delete_time'  =>'datetime',//
+       ];
+    protected $updateTime='updateTime';
+    protected $createTime='createTime';
+    protected $deleteTime = 'delete_time';
+    
+    public function WorkSub(){
+    	return $this->belongsTo(WorkSubscr::class,"sub_id","id");
+    }
+}

+ 32 - 0
app/bug/model/WorkSubscr.php

@@ -0,0 +1,32 @@
+<?php
+namespace app\bug\model;
+
+use think\model\concern\SoftDelete;class WorkSubscr extends Base
+{
+//设置字段信息
+	use SoftDelete;
+    protected $schema = [
+        'id'  =>'int',//
+        'belong'  =>'tinyint',//系统归属
+        'role_id'  =>'int',//角色id
+        'action'  =>'text',//选中的岗位功能
+        'apply_id'  =>'int',//申请人id
+        'apply_name'  =>'varchar',//申请人名称
+        'check_id'  =>'int',//审核人
+        'check_name'  =>'varchar',//审核人
+        'status'  =>'tinyint',//状态
+        'createTime'  =>'datetime',//
+        'updateTime'  =>'datetime',//
+        'delete_time'  =>'datetime',//
+       ];
+    protected $updateTime='updateTime';
+    protected $createTime='createTime';
+    protected $deleteTime = 'delete_time';
+    public static $statusCn=['无状态',"待审批","部分通过", "全部通过" ,"全部驳回","废弃"];
+    public function RoleInfo(){
+    	return $this->belongsTo(WorkRole::class,"role_id","id")->bind(["role_name","work_id","work_name","companyNo",'companyName']);
+    }
+    public function subInfo(){
+    	return $this->hasMany(WorkSubinfo::class,'sub_id','id');
+    }
+}

+ 3 - 3
app/command/makeModel.php

@@ -17,9 +17,9 @@ class makeModel extends Command
         $this->setName('makemodel')
             ->setDescription('the makemodel command');
     }
-	static $schema = 'cxinv_v2_pre_release';
-	static $prefix = 'Cfp';
-	static $epp = 'cxinv';
+	static $schema = 'bugonline';
+	static $prefix = 'Devcloud';
+	static $epp = 'bug';
     protected function execute(Input $input, Output $output)
     {
     	

+ 19 - 0
app/middleware/checkLog.php

@@ -0,0 +1,19 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\middleware;
+
+class checkLog
+{
+    /**
+     * 处理请求
+     *
+     * @param \think\Request $request
+     * @param \Closure       $next
+     * @return Response
+     */
+    public function handle($request, \Closure $next)
+    {
+        //
+    }
+}