'require', 'project_id' => 'require|checkProject', 'attendance_date' => 'require|dateFormat:Y-m-d', 'attendance_detail' => 'require|checkAttendanceDetail', 'process_approval' => 'require|checkProcessApproval', 'file' => 'checkFile', ]; protected $message = [ 'id.require' => '缺少必要参数', 'project_id.require' => '请选择项目', 'attendance_date.require' => '请选择考勤日期', 'attendance_date.dateFormat' => '考勤日期格式错误', 'attendance_detail.require' => '考勤记录清单信息不能为空', 'process_approval.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']); } /** * @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 checkFile($value): bool|string { if($value != ''){ $file = json_decode($value,true); if(empty($file)){ return '附件必须是json数组'; } } return true; } public function checkAttendanceDetail($value,$rule,$data): bool|string { $attendance_detail = json_decode($value,true); if(empty($attendance_detail) || !is_array($attendance_detail)){ return '考勤记录清单数据格式错误'; } foreach($attendance_detail as $v) { 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('Y-m-d H:i:s',strtotime($v['work_start_time'])) != $v['work_start_time']){ return '上班时间格式错误'; } } if(isset($v['work_end_time']) && $v['work_end_time'] != ''){ if(date('Y-m-d H:i:s',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; } public function checkProcessApproval($value): bool|string { $param = json_decode($value,true); if(empty($param)){ return '流程审批信息错误'; } if(empty($param['current_step'])){ return '请选择当前步骤'; }else{ $curr_steps = DictData::where('type_value','project_person_attendance_approval_process')->column('value'); if(!in_array($param['current_step'],$curr_steps)){ return '当前步骤无效'; } } if(empty($param['action'])){ return '请选择处理动作'; }else{ $action = DictData::where('type_value','approval_process_action')->column('value'); if(!in_array($param['action'],$action)){ return '处理动作无效'; } } if(empty($param['submit_step'])){ return '请选择送审步骤'; }else{ $submit_steps = DictData::where('type_value','project_manager_entrusted_approval_process')->column('value'); if(!in_array($param['submit_step'],$submit_steps)){ return '送审步骤无效'; } } if(empty($param['check_user'])){ return '请指定处理人'; }else{ $data = Admin::where('id',$param['check_user'])->findOrEmpty(); if($data->isEmpty()){ return '处理人不存在'; } } if(isset($param['copy_user']) || $param['copy_user'] != ''){ $copy_user_ids = explode(',',$param['copy_user']); foreach ($copy_user_ids as $v) { $data = Admin::where('id',$v)->findOrEmpty(); if($data->isEmpty()){ return '抄送人不存在'; } } } return true; } }