157 lines
4.1 KiB
PHP
157 lines
4.1 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\project\ProjectRoleSet;
|
||
use app\common\model\project\ProjectTypeSet;
|
||
use app\common\model\project\ProjectWbsSet;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 项目WBS设置验证器
|
||
* Class ProjectWbsSetValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectWbsSetValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkWbs',
|
||
'project_type_id' => 'require|checkProjectType',
|
||
'wbs_code' => 'require|unique:'.ProjectWbsSet::class,
|
||
'name' => 'require|unique:'.ProjectWbsSet::class,
|
||
'sort' => 'require|integer',
|
||
'weight' => 'require|integer',
|
||
'sup_wbs_code' => 'checkSupCode|different:wbs_code',
|
||
'project_role_id' => 'integer|checkProjectRole',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'project_type_id.require' => '请选择项目类型',
|
||
'wbs_code.require' => 'WBS编码不能为空',
|
||
'wbs_code.unique' => 'WBS编码不能重复',
|
||
'name.require' => '节点名称不能为空',
|
||
'name.unique' => '节点名称不能重复',
|
||
'sort.require' => '排序号不能为空',
|
||
'sort.integer' => '排序号必须是整数',
|
||
'weight.require' => '权重不能为空',
|
||
'weight.integer' => '权重必须是整数',
|
||
'sup_wbs_code' => '父级WBS编码不能与WBS编码相同',
|
||
'project_role_id.integer' => '项目角色数据格式错误',
|
||
];
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'project_type_id' => '项目类型id',
|
||
'wbs_code' => 'WBS编码',
|
||
'name' => '节点名称',
|
||
'sort' => '排序号',
|
||
'weight' => '权重',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectWbsSetValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/13 15:09
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectWbsSetValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/13 15:09
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectWbsSetValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/13 15:09
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectWbsSetValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/13 15:09
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkProjectType($value): bool|string
|
||
{
|
||
$projectType = ProjectTypeSet::where('id',$value)->findOrEmpty();
|
||
if($projectType->isEmpty()) {
|
||
return '项目类型不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkSupCode($value): bool|string
|
||
{
|
||
$projectWbs = ProjectWbsSet::where('wbs_code',$value)->findOrEmpty();
|
||
if($projectWbs->isEmpty()){
|
||
return '父级WBS编码错误';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProjectRole($value): bool|string
|
||
{
|
||
$projectRole = ProjectRoleSet::where('id',$value)->findOrEmpty();
|
||
if($projectRole->isEmpty()) {
|
||
return '角色不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkWbs($value,$rule, $data): bool|string
|
||
{
|
||
$data = ProjectWbsSet::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '数据不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |