engineering/app/adminapi/validate/project/ProjectManagerAppointmentValidate.php
2023-12-18 10:42:33 +08:00

260 lines
7.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\project;
use app\common\model\auth\Admin;
use app\common\model\contract\Contract;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\dict\DictData;
use app\common\model\project\Project;
use app\common\model\project\ProjectManagerAppointment;
use app\common\model\project\ProjectTypeSet;
use app\common\validate\BaseValidate;
/**
* 项目经理委任验证器
* Class ProjectManagerAppointmentValidate
* @package app\adminapi\validate\project
*/
class ProjectManagerAppointmentValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'contract_id' => 'require|checkContract',
'project_type_id' => 'require|checkProjectType',
'project_manager' => 'require|checkUser',
'amount' => 'require|float|egt:0',
'project_approval_date' => 'require|date',
'start_date' => 'require|date',
'delivery_date' => 'require|date',
'process_approval' => 'require|checkProcessApproval'
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
'contract_id.require' => '请选择合同',
'project_type_id.require' => '请选择项目类型',
'project_manager.require' => '请选择项目经理',
'amount.require' => '请填写项目金额',
'amount.float' => '项目金额必须是数字',
'amount.egt' => '项目金额必须大于等于0',
'project_approval_date.require' => '请选择立项日期',
'project_approval_date.date' => '立项日期格式错误',
'start_date.require' => '请选择项目开始日期',
'start_date.date' => '项目开始日期格式错误',
'delivery_date.require' => '请选择项目交付日期',
'delivery_date.date' => '项目交付日期格式错误',
'process_approval.require' => '请填写流程审批信息'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'contract_id' => '合同id',
'org_id' => '组织id',
'dept_id' => '部门id',
'project_type_id' => '项目类型',
'project_manager' => '项目经理',
'amount' => '项目金额',
'project_approval_date' => '立项日期',
'start_date' => '项目开始日期',
'delivery_date' => '项目交付日期',
];
/**
* @notes 添加场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneEdit()
{
return $this->only(['id','project_id','contract_id','project_type_id','project_manager','amount','project_approval_date','start_date','delivery_date']);;
}
/**
* @notes 删除场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = ProjectManagerAppointment::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkOrg($value): bool|string
{
$data = Orgs::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '组织不存在';
}
return true;
}
public function checkDept($value,$rule,$data): bool|string
{
$dept = Dept::where('id',$value)->findOrEmpty();
if($dept->isEmpty()){
return '部门不存在';
}
if($data['org_id'] != $dept['org_id']){
return '部门不属于当前选择的组织';
}
return true;
}
public function checkProject($value): bool|string
{
$data = Project::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkContract($value): bool|string
{
$data = Contract::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '合同不存在';
}
return true;
}
public function checkProjectType($value): bool|string
{
$data = ProjectTypeSet::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目类型不存在';
}
return true;
}
public function checkUser($value): bool|string
{
$data = Admin::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '用户不存在';
}
return true;
}
public function checkProcessApproval($value): bool|string
{
$param = json_decode($value,true);
if(empty($param)){
return '流程审批信息错误';
}
if(empty($param['current_step'])){
return '请选择当前步骤';
}else{
$curr_steps = DictData::where('type_value','project_manager_entrusted_approval_process')->column('value');
if(!in_array($param['current_step'],$curr_steps)){
return '当前步骤无效';
}
}
if(empty($param['action'])){
return '请选择处理动作';
}else{
$action = DictData::where('type_value','approval_process_action')->column('value');
if(!in_array($param['action'],$action)){
return '处理动作无效';
}
}
if(empty($param['submit_step'])){
return '请选择送审步骤';
}else{
$submit_steps = DictData::where('type_value','project_manager_entrusted_approval_process')->column('value');
if(!in_array($param['submit_step'],$submit_steps)){
return '送审步骤无效';
}
}
if(empty($param['check_user'])){
return '请指定处理人';
}else{
$data = Admin::where('id',$param['check_user'])->findOrEmpty();
if($data->isEmpty()){
return '处理人不存在';
}
}
if(isset($param['copy_user']) || $param['copy_user'] != ''){
$copy_user_ids = explode(',',$param['copy_user']);
foreach ($copy_user_ids as $v) {
$data = Admin::where('id',$v)->findOrEmpty();
if($data->isEmpty()){
return '抄送人不存在';
}
}
}
return true;
}
}