engineering/app/adminapi/validate/supervision_dangerous/SupervisionLargeMechanicalEquipmentValidate.php

230 lines
7.2 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_dangerous;
use app\common\model\dict\DictData;
use app\common\model\supervision_dangerous\SupervisionLargeMechanicalEquipment;
use app\common\model\supervision_dangerous\SupervisionLargeMechanicalEquipmentMaintenanceRecord;
use app\common\model\supervision_project\SupervisionParticipatingUnits;
use app\common\model\supervision_project\SupervisionProject;
use app\common\validate\BaseValidate;
/**
* 大型机械设备及仪器台账验证器
* Class SupervisionLargeMechanicalEquipmentValidate
* @package app\adminapi\validate\supervision_dangerous
*/
class SupervisionLargeMechanicalEquipmentValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_id' => 'require|checkProject',
'name' => 'require',
'entry_time' => 'require|dateFormat:Y-m-d',
'company_id' => 'require|checkCompany',
'approval_date' => 'require|dateFormat:Y-m-d',
'approval_type' => 'checkApprovalType',
'first_audit_opinion' => 'checkFirstAuditOpinion',
'first_audit_time' => 'dateFormat:Y-m-d',
'final_audit_opinion' => 'checkFinalAuditOpinion',
'final_audit_time' => 'dateFormat:Y-m-d',
'annex' => 'checkAnnex',
'maintenance_record' => 'checkMaintenanceRecord'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'sn' => '序号',
'name' => '大型机械设备及仪器具',
'use_site' => '使用部位',
'entry_time' => '进场时间',
'company_id' => '报审单位名称',
'approval_date' => '报审日期',
'approval_result' => '报审结果',
'approval_form_code' => '报审表编号',
'approval_type' => '报审类型',
'first_audit_opinion' => '专监初审意见',
'first_auditor' => '初审人',
'first_audit_time' => '初审时间',
'final_audit_opinion' => '总监审定结论',
'final_audit_time' => '审定时间',
'remark' => '备注',
];
/**
* @notes 添加场景
* @return SupervisionLargeMechanicalEquipmentValidate
* @author likeadmin
* @date 2024/03/02 09:51
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SupervisionLargeMechanicalEquipmentValidate
* @author likeadmin
* @date 2024/03/02 09:51
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SupervisionLargeMechanicalEquipmentValidate
* @author likeadmin
* @date 2024/03/02 09:51
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SupervisionLargeMechanicalEquipmentValidate
* @author likeadmin
* @date 2024/03/02 09:51
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = SupervisionLargeMechanicalEquipment::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 checkCompany($value,$rule,$params){
$data = SupervisionParticipatingUnits::where('id',$value)->where('project_id',$params['project_id'])->findOrEmpty();
if($data->isEmpty()){
return '报审单位信息不存在';
}
return true;
}
public function checkApprovalType($value): bool|string
{
$dict = DictData::where('type_value','approval_type')->column('value');
if(!in_array($value,$dict)){
return '报审类型数据值无效';
}
return true;
}
public function checkFirstAuditOpinion($value): bool|string
{
$dict = DictData::where('type_value','first_audit_opinion')->column('value');
if(!in_array($value,$dict)){
return '专监初审意见数据值无效';
}
return true;
}
public function checkFinalAuditOpinion($value): bool|string
{
$dict = DictData::where('type_value','final_audit_opinion')->column('value');
if(!in_array($value,$dict)){
return '总监审定结论数据值无效';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != '' && !is_array($value)){
return '附件格式错误';
}
return true;
}
public function checkMaintenanceRecord($value): bool|string
{
if(!isset($value) || $value == '') return true;
if(!is_array($value)) return '维修保养记录数据格式错误';
foreach($value as $k=>$v){
if(!empty($v['id'])){
$data = SupervisionLargeMechanicalEquipmentMaintenanceRecord::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '维修保养记录列表第'.($k+1).'行数据不存在';
}
}
if(empty($v['reg_date'])){
return '维修保养记录列表第'.($k+1).'行登记日期为空';
}else{
if(date('Y-m-d',strtotime($v['reg_date'])) != $v['reg_date']){
return '维修保养记录列表第'.($k+1).'行登记日期必须是Y-m-d格式';
}
}
if(empty($v['month_warranty_file'])) return '维修保养记录列表第'.($k+1).'行机械每月维修保养附件为空';
if(empty($v['maintenance_period'])){
return '维修保养记录列表第'.($k+1).'行设备维保有效期为空';
}else{
if(date('Y-m-d',strtotime($v['maintenance_period'])) != $v['maintenance_period']){
return '维修保养记录列表第'.($k+1).'行设备维保有效期必须是Y-m-d格式';
}
}
if(empty($v['accessory_one_validity'])){
return '维修保养记录列表第'.($k+1).'行附配件1有效期为空';
}else{
if(date('Y-m-d',strtotime($v['accessory_one_validity'])) != $v['accessory_one_validity']){
return '维修保养记录列表第'.($k+1).'行附配件1有效期必须是Y-m-d格式';
}
}
if(empty($v['accessory_two_validity'])){
return '维修保养记录列表第'.($k+1).'行附配件2有效期为空';
}else{
if(date('Y-m-d',strtotime($v['accessory_two_validity'])) != $v['accessory_two_validity']){
return '维修保养记录列表第'.($k+1).'行附配件2有效期必须是Y-m-d格式';
}
}
}
return true;
}
}