129 lines
2.9 KiB
PHP
129 lines
2.9 KiB
PHP
<?php
|
|
namespace app\adminapi\validate\quality;
|
|
|
|
use app\common\model\dept\Dept;
|
|
use app\common\model\dept\Orgs;
|
|
use app\common\model\project\Project;
|
|
use app\common\validate\BaseValidate;
|
|
|
|
/**
|
|
* 质量检测验证器
|
|
* Class QualityDetectionValidate
|
|
* @package app\adminapi\validate\quality
|
|
*/
|
|
class QualityDetectionValidate extends BaseValidate
|
|
{
|
|
|
|
/**
|
|
* 设置校验规则
|
|
* @var string[]
|
|
*/
|
|
protected $rule = [
|
|
'id' => 'require',
|
|
'org_id' => 'require|checkOrg',
|
|
'dept_id' => 'require|checkDept',
|
|
'project_id' => 'require|checkProject',
|
|
'scheduled_start_time' => 'dateFormat:Y-m-d',
|
|
'scheduled_end_time' => 'dateFormat:Y-m-d',
|
|
'actual_start_time' => 'dateFormat:Y-m-d',
|
|
'actual_end_time' => 'dateFormat:Y-m-d',
|
|
'file' => 'checkFile',
|
|
];
|
|
|
|
protected $message = [
|
|
'id.require' => '缺少必要参数',
|
|
'org_id.require' => '请选择组织',
|
|
'dept_id.require' => '请选择部门',
|
|
'project_id.require' => '请选择项目',
|
|
'scheduled_start_time.dateFormat' => '计划开始时间格式错误',
|
|
'scheduled_end_time.dateFormat' => '计划结束时间格式错误',
|
|
'actual_start_time.dateFormat' => '实际开始式错误',
|
|
'actual_end_time.dateFormat' => '实际结束格式错误',
|
|
];
|
|
|
|
/**
|
|
* @notes 添加场景
|
|
* @return QualityDetectionValidate
|
|
* @author likeadmin
|
|
* @date 2023/12/21 16:14
|
|
*/
|
|
public function sceneAdd()
|
|
{
|
|
return $this->remove('id',true);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑场景
|
|
* @return QualityDetectionValidate
|
|
* @author likeadmin
|
|
* @date 2023/12/21 16:14
|
|
*/
|
|
public function sceneEdit()
|
|
{}
|
|
|
|
|
|
/**
|
|
* @notes 删除场景
|
|
* @return QualityDetectionValidate
|
|
* @author likeadmin
|
|
* @date 2023/12/21 16:14
|
|
*/
|
|
public function sceneDelete()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 详情场景
|
|
* @return QualityDetectionValidate
|
|
* @author likeadmin
|
|
* @date 2023/12/21 16:14
|
|
*/
|
|
public function sceneDetail()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
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($dept['org_id'] != $data['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 checkFile($value): bool|string
|
|
{
|
|
if(!empty($value) && $value != ''){
|
|
if(!is_array($value)){
|
|
return '附件必须是json数组';
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} |