158 lines
4.0 KiB
PHP
158 lines
4.0 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\custom\CustomerDemand;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\model\project\Project;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 解决方案验证器
|
||
* Class CustomerDemandSolutionValidate
|
||
* @package app\adminapi\validate\custom
|
||
*/
|
||
class CustomerDemandSolutionValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'project_id' => 'require|checkProject',
|
||
'customer_demand_id' => 'require|checkCustomerDemand',
|
||
'theme' => 'require',
|
||
'submission_time' => 'require|dateFormat:Y-m-d',
|
||
'annex' => 'checkAnnex',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.require' => '请选择部门',
|
||
'project_id.require' => '请选择项目',
|
||
'customer_demand_id.require' => '请选择客户需求',
|
||
'theme.require' => '请填写需求主题',
|
||
'submission_time.require' => '请选择提交时间',
|
||
'submission_time.dateFormat' => '提交时间数据格式错误',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return CustomerDemandSolutionValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:32
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return CustomerDemandSolutionValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:32
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return CustomerDemandSolutionValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:32
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return CustomerDemandSolutionValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/24 21:32
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkOrg($value): bool|string
|
||
{
|
||
$org = Orgs::where('id',$value)->findOrEmpty();
|
||
if($org->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
|
||
{
|
||
$project = Project::where('id',$value)->findOrEmpty();
|
||
if($project->isEmpty()){
|
||
return '项目不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkCustomerDemand($value,$rule,$data): bool|string
|
||
{
|
||
$customDemand = CustomerDemand::where('id',$value)->findOrEmpty();
|
||
if($customDemand->isEmpty()){
|
||
return '客户需求不存在';
|
||
}
|
||
if($customDemand['project_id'] != $data['project_id']){
|
||
return '客户需求与项目信息不一致';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
$annex = $value;//json_decode($value,true);
|
||
if(empty($annex) || !is_array($annex)){
|
||
return '附件格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |