173 lines
4.9 KiB
PHP
173 lines
4.9 KiB
PHP
<?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\dict\DictData;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectPersonnel;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 劳动合同验证器
|
||
* Class ProjectLaborContractValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectLaborContractValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'project_id' => 'require|checkProject',
|
||
'project_person_id' => 'require|checkProjectPerson',
|
||
'contract_status' => 'require|checkContractStatus',
|
||
'contract_type' => 'require|checkContractType',
|
||
'contract_title' => 'require|checkContractTitle',
|
||
'signing_date' => 'require|dateFormat:Y-m-d',
|
||
'start_date' => 'require|dateFormat:Y-m-d',
|
||
'end_date' => 'require|dateFormat:Y-m-d',
|
||
'trial_start_date' => 'dateFormat:Y-m-d',
|
||
'trial_end_date' => 'dateFormat:Y-m-d',
|
||
'release_time' => 'dateFormat:Y-m-d',
|
||
'annex' => 'checkAnnex',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'project_id.require' => '请选择项目',
|
||
'project_person_id.require' => '请选择项目人员',
|
||
'contract_status.require' => '请选择合同状态',
|
||
'contract_type.require' => '请选择合同类别',
|
||
'contract_title.require' => '请选择合同名称',
|
||
'signing_date.require' => '请选择合同签定日期',
|
||
'signing_date.dateFormat' => '合同签定日期格式错误',
|
||
'start_date.require' => '请选择起始时间',
|
||
'start_date.dateFormat' => '起始时间格式错误',
|
||
'end_date.require' => '请选择终止时间',
|
||
'end_date.dateFormat' => '终止时间格式错误',
|
||
'trial_start_date.dateFormat' => '试用期起始日期格式错误',
|
||
'trial_end_date.dateFormat' => '试用期结束日期格式错误',
|
||
'release_time.dateFormat' => '解除时间格式错误',
|
||
];
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectLaborContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/25 14:35
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectLaborContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/25 14:35
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectLaborContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/25 14:35
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectLaborContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/25 14:35
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkProject($value): bool|string
|
||
{
|
||
$data = Project::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '项目不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProjectPerson($value,$rule,$data): bool|string
|
||
{
|
||
$person = ProjectPersonnel::where('id',$value)->findOrEmpty();
|
||
if($person->isEmpty()){
|
||
return '项目人员不存在';
|
||
}
|
||
if($person['project_id'] != $data['project_id']){
|
||
return '项目人员无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkContractStatus($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','labor_contract_status')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '合同状态无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkContractType($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','labor_contract_type')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '合同类别无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkContractTitle($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','labor_contract_name')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '合同名称无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
if(!is_array($value)){
|
||
return '附件必须是json数组';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |