'require', 'plan_id' => 'require|checkPlan', 'person_detail' => 'require|checkDetail', 'scene_file' => 'require|checkFile', 'report_workload' => 'require|float|egt:0', 'report_amount' => 'require|float|egt:0' ]; protected $message = [ 'id.require' => '缺少必要参数', 'plan_id.require' => '请选择施工计划', 'person_detail.require' => '请填写人工明细', 'scene_file.require' => '请上传现场照片', 'report_workload.require' => '请填写完工量', 'report_workload.float' => '完工量值必须是数字', 'report_workload.egt' => '完工量值必须大于等于0', 'report_amount.require' => '请填写金额', 'report_amount.float' => '金额值必须是数字', 'report_amount.egt' => '金额值必须大于等于0', ]; /** * @notes 添加场景 * @return BuildReportValidate * @author likeadmin * @date 2023/12/22 16:08 */ public function sceneAdd() { return $this->remove('id', true); } /** * @notes 编辑场景 * @return BuildReportValidate * @author likeadmin * @date 2023/12/22 16:08 */ public function sceneEdit() { } /** * @notes 删除场景 * @return BuildReportValidate * @author likeadmin * @date 2023/12/22 16:08 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return BuildReportValidate * @author likeadmin * @date 2023/12/22 16:08 */ public function sceneDetail() { return $this->only(['id']); } public function checkPlan($value): bool|string { $data = BuildPlan::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '施工计划不存在'; } return true; } public function checkFile($value): bool|string { $file = $value;//json_decode($value,true); if (empty($file)) { return '附件必须是json数组'; } return true; } public function checkDetail($value, $rule, $data): bool|string { $person_detail = $value;// json_decode($value,true); if (empty($person_detail) || !is_array($person_detail)) { return '人工明细数据格式错误'; } foreach ($person_detail as $v) { if (empty($v['person_id'])) { return '人工明细缺少必要参数'; } else { $person = ProjectPersonnel::where('id', $v['person_id'])->findOrEmpty(); if ($person->isEmpty()) { return '项目人员不存在'; } $plan = BuildPlan::field('project_id')->where('id', $data['plan_id'])->findOrEmpty(); if ($plan['project_id'] != $person['project_id']) { return '项目人员无效'; } } if (empty($v['work_num'])) { return '请填写项目人员完工量'; } else { if (!is_numeric($v['work_num']) || $v['work_num'] < 0) { return '项目人员完工量值必须是大于等于0的数字'; } } } return true; } }