'require', 'project_id' => 'require|checkProject', 'attendance_date' => 'require|dateFormat:Y-m-d', 'attendance_detail' => 'require|checkAttendanceDetail', 'annex' => 'checkAnnex', ]; protected $message = [ 'id.require' => '缺少必要参数', 'project_id.require' => '请选择项目', 'attendance_date.require' => '请选择考勤日期', 'attendance_date.dateFormat' => '考勤日期格式错误', 'attendance_detail.require' => '考勤记录清单信息不能为空', ]; /** * @notes 添加场景 * @return ProjectAttendanceRecordValidate * @author likeadmin * @date 2023/12/26 09:44 */ public function sceneAdd() { return $this->remove('id', true); } /** * @notes 编辑场景 * @return ProjectAttendanceRecordValidate * @author likeadmin * @date 2023/12/26 09:44 */ public function sceneEdit() { return $this->only(['id', 'attendance_date']); } /** * @notes 删除场景 * @return ProjectAttendanceRecordValidate * @author likeadmin * @date 2023/12/26 09:44 */ public function sceneDelete() { return $this->only(['id'])->remove('id', 'checkData'); } /** * @notes 详情场景 * @return ProjectAttendanceRecordValidate * @author likeadmin * @date 2023/12/26 09:44 */ public function sceneDetail() { return $this->only(['id']); } public function checkProject($value): bool|string { $data = Project::where('id', $value)->findOrEmpty(); if ($data->isEmpty()) { return '项目不存在'; } return true; } public function checkAttendanceDetail($value, $rule, $data): bool|string { $attendance_detail = $value;//json_decode($value,true); if (empty($attendance_detail) || !is_array($attendance_detail)) { return '考勤记录清单数据格式错误'; } foreach ($attendance_detail as $v) { if (isset($v['id']) && $v['id'] != '') { $data_detail = ProjectAttendanceDetail::where('id', $v['id'])->findOrEmpty(); if ($data_detail->isEmpty()) { return '考勤记录明细信息不存在'; } } if (empty($v['person_id'])) { return '请选择项目人员'; } else { $person = ProjectPersonnel::where('id', $v['person_id'])->findOrEmpty(); if ($person->isEmpty() || $person['project_id'] != $data['project_id']) { return '项目人员不存在'; } } if (isset($v['work_start_time']) && $v['work_start_time'] != '') { if (date('H:i', strtotime($v['work_start_time'])) != $v['work_start_time']) { return '上班时间格式错误'; } } if (isset($v['work_end_time']) && $v['work_end_time'] != '') { if (date('H:i', strtotime($v['work_end_time'])) != $v['work_end_time']) { return '下班时间格式错误'; } if (strtotime($v['work_end_time']) - strtotime($v['work_start_time']) < 0) { return '下班时间不能小于上班时间'; } } if (empty($v['work_record_num'])) { return '记工数量不能为空'; } else { if (!is_numeric($v['work_record_num']) || $v['work_record_num'] < 0) { return '记工数量必须是大于0的数字'; } } if (empty($v['daily_salary'])) { return '日工资不能为空'; } else { if (!is_numeric($v['daily_salary']) || $v['daily_salary'] < 0) { return '日工资必须是大于0的数字'; } } if (empty($v['daily_living'])) { return '日生活费不能为空'; } else { if (!is_numeric($v['daily_living']) || $v['daily_living'] < 0) { return '日生活费必须是大于0的数字'; } } if (isset($v['daily_subsidy']) && $v['daily_subsidy'] != '') { if (!is_numeric($v['daily_subsidy']) || $v['daily_subsidy'] < 0) { return '日补贴必须是大于等于0的数字'; } } if (isset($v['daily_other']) && $v['daily_other'] != '') { if (!is_numeric($v['daily_other']) || $v['daily_other'] < 0) { return '日其它必须是大于等于0的数字'; } } if (empty($v['daily_income'])) { return '日收入不能为空'; } else { if (!is_numeric($v['daily_income']) || $v['daily_income'] < 0) { return '日收入必须是大于0的数字'; } } } return true; } }