166 lines
4.3 KiB
PHP
166 lines
4.3 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\auth\Admin;
|
||
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\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 项目计划验证器
|
||
* Class ProjectPlanValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectPlanValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'project_id' => 'require|checkProject',
|
||
'project_manage' => 'require|checkUser',
|
||
'start_time' => 'require|date',
|
||
'deliver_time' => 'require|date',
|
||
'declare_time' => 'require|date',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.require' => '请选择部门',
|
||
'project_id.require' => '请选择项目',
|
||
'project_manage.require' => '请选择项目经理',
|
||
'start_time.require' => '请选择项目开始日期',
|
||
'start_time.date' => '项目开始日期格式错误',
|
||
'deliver_time.require' => '请选择项目交付日期',
|
||
'deliver_time.date' => '项目交付日期格式错误',
|
||
'declare_time.require' => '请选择填报日期',
|
||
'declare_time.date' => '填报日期格式错误',
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'org_id' => '组织id',
|
||
'dept_id' => '部门id',
|
||
'project_id' => '项目id',
|
||
'project_manage' => '项目经理',
|
||
'start_time' => '项目开始日期',
|
||
'deliver_time' => '项目交付日期',
|
||
'declare_time' => '填报日期',
|
||
'add_user' => '添加人',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectPlanValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/18 11:40
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectPlanValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/18 11:40
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id','project_id','project_manage','start_time','deliver_time','declare_time','remark','annex']);
|
||
}
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectPlanValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/18 11:40
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectPlanValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/18 11:40
|
||
*/
|
||
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($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 checkUser($value): bool|string
|
||
{
|
||
$data = Admin::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '用户不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |