115 lines
2.9 KiB
PHP
115 lines
2.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\custom;
|
||
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\project\Project;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 客户需求验证器
|
||
* Class CustomerDemandValidate
|
||
* @package app\adminapi\validate\custom
|
||
*/
|
||
class CustomerDemandValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'project_id' => 'require|checkProject',
|
||
'theme' => 'require',
|
||
'importance' => 'require|checkImportance',
|
||
'recording_time' => 'require|dateFormat:Y-m-d',
|
||
'annex' => 'checkAnnex'
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'project_id.require' => '请选择项目',
|
||
'theme.require' => '请填写需求主题',
|
||
'importance.require' => '请选择重要程度',
|
||
'recording_time.require' => '请选择记录时间',
|
||
'recording_time.dateFormat' => '记录时间数据格式错误',
|
||
];
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return CustomerDemandValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:18
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return CustomerDemandValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:18
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return CustomerDemandValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:18
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return CustomerDemandValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:18
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkProject($value): bool|string
|
||
{
|
||
$project = Project::where('id', $value)->findOrEmpty();
|
||
if ($project->isEmpty()) {
|
||
return '项目不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkImportance($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value', 'importance')->column('value');
|
||
if (!in_array($value, $dictData)) {
|
||
return '类型无效';
|
||
}
|
||
return true;
|
||
}
|
||
} |