<?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_project\SupervisionParticipatingUnits; use app\common\model\supervision_project\SupervisionProject; use app\common\model\supervision_work\SupervisionAccept; use app\common\model\supervision_work\SupervisionAcceptResult; use app\common\model\supervision_work\SupervisionCheckItem; use app\common\model\supervision_work\SupervisionProblem; use app\common\validate\BaseValidate; /** * 工程监理--验收登记验证器 * Class SupervisionAcceptValidate * @package app\adminapi\validate\supervision_work */ class SupervisionAcceptValidate extends BaseValidate { /** * 设置校验规则 * @var string[] */ protected $rule = [ 'id' => 'require|checkData', 'project_id' => 'require|checkProject', 'accept_type' => 'require|checkAcceptType', 'check_item_id' => 'require|checkCheckItem', 'accept_time' => 'require|dateFormat:Y-m-d H:i:s', 'company_id' => 'checkCompany', 'accept_result' => 'require|in:0,1', 'check_item_detail_ids' => 'checkCheckItemDetail', 'annex' => 'checkAnnex', 'accept_check_result' => 'checkAcceptResult', 'accept_check_problem' => 'checkAcceptProblem' ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'project_id' => '项目id', 'accept_code' => '验收编号', 'accept_type' => '验收类型', 'check_item_id' => '单位工程', 'accept_content' => '验收内容', 'accept_position' => '验收位置', 'accept_time' => '验收时间', 'company_id' => '施工单位', 'accept_result' => '验收结果', 'remark' => '备注', 'create_user' => '创建人', ]; /** * @notes 添加场景 * @return SupervisionAcceptValidate * @author likeadmin * @date 2024/02/27 15:23 */ public function sceneAdd() { return $this->remove('id',true); } /** * @notes 编辑场景 * @return SupervisionAcceptValidate * @author likeadmin * @date 2024/02/27 15:23 */ public function sceneEdit() {} /** * @notes 验收场景 * @return SupervisionAcceptValidate * @author likeadmin * @date 2024/02/27 15:23 */ public function sceneAccept() { return $this->only(['id','accept_time','accept_result','remark','annex']); } /** * @notes 删除场景 * @return SupervisionAcceptValidate * @author likeadmin * @date 2024/02/27 15:23 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return SupervisionAcceptValidate * @author likeadmin * @date 2024/02/27 15:23 */ public function sceneDetail() { return $this->only(['id']); } public function checkData($value): bool|string { $data = SupervisionAccept::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 checkAcceptType($value): bool|string { $dict = DictData::where('type_value','accept_type')->column('value'); if(!in_array($value,$dict)){ return '验收类型数据值无效'; } return true; } public function checkCheckItem($value,$rule,$params): bool|string { $data = SupervisionCheckItem::where('id',$value)->where('project_id',$params['project_id'])->where('node_type',2)->findOrEmpty(); if($data->isEmpty()){ return '单位工程数据不存在'; } return true; } public function checkCompany($value,$rule,$params): bool|string { $data = SupervisionParticipatingUnits::where('id',$value)->where('project_id',$params['project_id'])->findOrEmpty(); if($data->isEmpty()){ return '施工单位信息不存在'; } return true; } public function checkCheckItemDetail($value,$rule,$params): bool|string { if(!isset($value) || $value == '') return true; if(!is_array($value)) return '检查表单选择数据格式错误'; foreach($value as $v){ $data = SupervisionCheckItem::where('id',$v)->where('project_id',$params['project_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 checkAcceptResult($value): bool|string { if(!isset($value) || $value == '') return true; if(!is_array($value)) return '验收结果数据格式错误'; foreach($value as $k=>$v){ if(!empty($v['id'])){ $data = SupervisionAcceptResult::where('id',$v['id'])->findOrEmpty(); if($data->isEmpty()){ return '验收结果列表第'.($k+1).'行数据不存在'; } } if(empty($v['check_type'])) return '验收结果列表第'.($k+1).'行检查类别为空'; if(empty($v['check_content'])) return '验收结果列表第'.($k+1).'行检查内容为空'; if(empty($v['check_problem'])) return '验收结果列表第'.($k+1).'行检查问题为空'; if(!isset($v['must_check']) || $v['must_check'] == '') return '验收结果列表第'.($k+1).'行是否必检为空'; if(!in_array($v['must_check'],[0,1])) return '验收结果列表第'.($k+1).'行是否必检数据值无效'; if(!isset($v['check_result']) || $v['check_result'] == '') return '验收结果列表第'.($k+1).'行检查结果为空'; if(!in_array($v['check_result'],[0,1])) return '验收结果列表第'.($k+1).'行检查结果数据值无效'; } return true; } public function checkAcceptProblem($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; } }