engineering/app/adminapi/validate/supervision_work/SupervisionMaterialParallelTestingDetailValidate.php
2024-02-29 16:19:38 +08:00

186 lines
5.7 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_work;
use app\common\model\dict\DictData;
use app\common\model\supervision_work\SupervisionMaterialEntryDetail;
use app\common\model\supervision_work\SupervisionMaterialParallelTesting;
use app\common\model\supervision_work\SupervisionMaterialParallelTestingDetail;
use app\common\model\supervision_work\SupervisionProblem;
use app\common\validate\BaseValidate;
/**
* 工程监理--材料平行检验明细验证器
* Class SupervisionMaterialParallelTestingDetailValidate
* @package app\adminapi\validate\supervision_work
*/
class SupervisionMaterialParallelTestingDetailValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'material_parallel_testing_id' => 'require|checkMaterialParallelTesting',
'material_entry_detail_id' => 'require|checkMaterialEntryDetail',
'num' => 'require|float',
'check_code' => 'require',
'check_result' => 'require|in:1,2',
'check_time' => 'require|dateFormat:Y-m-d',
'check_user' => 'require',
'check_annex' => 'checkAnnex',
'check_problem' => 'checkProblem'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'material_parallel_testing_id' => '材料平行检验id',
'material_entry_detail_id' => '材料进场明细id',
'num' => '检验数量',
'check_code' => '报告编号',
'check_result' => '检验结果',
'check_time' => '获得日期',
'check_user' => '操作人',
'check_remark' => '备注',
];
/**
* @notes 添加场景
* @return SupervisionMaterialParallelTestingDetailValidate
* @author likeadmin
* @date 2024/02/29 15:00
*/
public function sceneAdd()
{
return $this->only(['material_parallel_testing_id','material_entry_detail_id','num']);
}
/**
* @notes 编辑场景
* @return SupervisionMaterialParallelTestingDetailValidate
* @author likeadmin
* @date 2024/02/29 15:00
*/
public function sceneEdit()
{
return $this->only(['id','material_parallel_testing_id','material_entry_detail_id','num']);
}
/**
* @notes 检验场景
* @return SupervisionMaterialParallelTestingDetailValidate
* @author likeadmin
* @date 2024/02/29 09:22
*/
public function sceneCheck()
{
return $this->only(['id','check_code','check_result','check_time','check_user','check_remark','check_annex','check_problem']);
}
/**
* @notes 删除场景
* @return SupervisionMaterialParallelTestingDetailValidate
* @author likeadmin
* @date 2024/02/29 15:00
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SupervisionMaterialParallelTestingDetailValidate
* @author likeadmin
* @date 2024/02/29 15:00
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = SupervisionMaterialParallelTestingDetail::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkMaterialParallelTesting($value): bool|string
{
$data = SupervisionMaterialParallelTesting::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '材料平行检验信息不存在';
}
return true;
}
public function checkMaterialEntryDetail($value,$rule,$params): bool|string
{
$witness_sampling = SupervisionMaterialParallelTesting::where('id',$params['material_parallel_testing_id'])->findOrEmpty();
$data = SupervisionMaterialEntryDetail::where('id',$value)->where('material_entry_id',$witness_sampling['material_entry_id'])->findOrEmpty();
if($data->isEmpty()){
return '材料信息不存在';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != '' && !is_array($value)){
return '附件格式错误';
}
return true;
}
public function checkProblem($value): bool|string
{
if(!isset($value) || $value == '') return true;
if(!is_array($value)) return '检验问题数据格式错误';
foreach($value as $k=>$v){
if(!empty($v['id'])){
$data = SupervisionProblem::where('id',$v['id'])->findOrEmpty();
if($data->isEmpty()){
return '检验问题列表第'.($k+1).'行数据不存在';
}
}
if(empty($v['problem_cate'])){
return '检验问题列表第'.($k+1).'行问题分类为空';
}else{
$dict = DictData::where('type_value','problem_cate')->column('value');
if(!in_array($v['problem_cate'],$dict)) return '检验问题列表第'.($k+1).'行问题分类数据值无效';
}
if(empty($v['problem_description'])) return '检验问题列表第'.($k+1).'行问题说明为空';
if(empty($v['problem_name'])) return '检验问题列表第'.($k+1).'行问题名称为空';
}
return true;
}
}