engineering/app/adminapi/validate/manage_communication/ManageInfoReportValidate.php
2024-03-08 13:47:30 +08:00

160 lines
4.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\manage_communication;
use app\common\model\dict\DictData;
use app\common\model\manage_basic\ManageProject;
use app\common\model\manage_communication\ManageInfoReport;
use app\common\validate\BaseValidate;
/**
* 项目管理--项目信息上报验证器
* Class ManageInfoReportValidate
* @package app\adminapi\validate\manage_communication
*/
class ManageInfoReportValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_id' => 'require|checkProject',
'abstract' => 'require',
'happen_date' => 'require|dateFormat:Y-m-d',
'severity' => 'checkSeverity',
'info_cate' => 'checkInfoCate',
'create_user' => 'require',
'create_time' => 'require|dateFormat:Y-m-d H:i:s',
'annex' => 'checkAnnex'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'abstract' => '信息摘要',
'happen_date' => '发生日期',
'severity' => '严重程度',
'content' => '信息内容',
'opinions' => '项目部意见',
'giver' => '主送人',
'create_user' => '创建人',
'create_time' => '创建时间',
];
/**
* @notes 添加场景
* @return ManageInfoReportValidate
* @author likeadmin
* @date 2024/03/08 13:33
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ManageInfoReportValidate
* @author likeadmin
* @date 2024/03/08 13:33
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ManageInfoReportValidate
* @author likeadmin
* @date 2024/03/08 13:33
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ManageInfoReportValidate
* @author likeadmin
* @date 2024/03/08 13:33
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = ManageInfoReport::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkProject($value): bool|string
{
$data = ManageProject::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目信息不存在';
}
return true;
}
public function checkSeverity($value): bool|string
{
$dict = DictData::where('type_value','severity')->column('value');
if(!in_array($value,$dict)){
return '严重程度数据值无效';
}
return true;
}
public function checkInfoCate($value): bool|string
{
if(empty($value)) return true;
if(!is_array($value)) return '信息类别数据格式错误';
$dict = DictData::where('type_value','info_cate')->column('value');
foreach($value as $v){
if(!in_array($v,$dict)){
return '信息类别数据值无效';
}
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != '' && !is_array($value)){
return '附件格式错误';
}
return true;
}
}