engineering/app/adminapi/validate/supervision_project/SupervisionParticipatingUnitsValidate.php
2024-02-23 17:58:24 +08:00

151 lines
3.9 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\supervision_project;
use app\common\model\dict\DictData;
use app\common\model\supervision_project\SupervisionParticipatingUnits;
use app\common\model\supervision_project\SupervisionParticipatingUnitsContacts;
use app\common\model\supervision_project\SupervisionProject;
use app\common\validate\BaseValidate;
/**
* 工程监理--参建单位验证器
* Class SupervisionParticipatingUnitsValidate
* @package app\adminapi\validate\supervision_project
*/
class SupervisionParticipatingUnitsValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_id' => 'require|checkProject',
'unit_name' => 'require',
'unit_type' => 'checkUnitType',
'contacts' => 'checkContacts',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'unit_name' => '单位名称',
'unit_type' => '单位类别',
'qualification_grade' => '资质等级',
'telephone' => '联系电话',
'duty' => '责任范围',
];
/**
* @notes 添加场景
* @return SupervisionParticipatingUnitsValidate
* @author likeadmin
* @date 2024/02/23 13:40
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SupervisionParticipatingUnitsValidate
* @author likeadmin
* @date 2024/02/23 13:40
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SupervisionParticipatingUnitsValidate
* @author likeadmin
* @date 2024/02/23 13:40
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SupervisionParticipatingUnitsValidate
* @author likeadmin
* @date 2024/02/23 13:40
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = SupervisionParticipatingUnits::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkProject($value): bool|string
{
$data = SupervisionProject::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目信息不存在';
}
return true;
}
public function checkUnitType($value): bool|string
{
$dict = DictData::where('type_value','unit_type')->column('value');
if(!in_array($value,$dict)){
return '单位类别数据值无效';
}
return true;
}
public function checkContacts($value): bool|string
{
if(empty($value) || $value == '') return true;
if(!is_array($value)) return '联系人数据格式错误';
foreach($value as $k=>$v){
if(isset($v['id']) && !empty($v['id'])){
$data = SupervisionParticipatingUnitsContacts::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '第'.($k+1).'行联系人信息不存在';
}
}
if(empty($v['name'])){
return '第'.($k+1).'行联系人姓名为空';
}
}
return true;
}
}