$params['project_id'], 'attendance_code' => data_unique_code('项目考勤记录'), 'attendance_date' => strtotime($params['attendance_date']), 'remark' => $params['remark'], 'annex' => $params['annex'] ? json_encode($params['annex']) : null, ]); foreach ($params['attendance_detail'] as $v) { ProjectAttendanceDetail::create([ 'attendance_id' => $ProjectAttendanceRecordRes->id, 'project_id' => $params['project_id'], 'person_id' => $v['person_id'], 'attendance_date' => strtotime($params['attendance_date']), 'work_start_time' => strtotime($v['work_start_time']), 'work_end_time' => strtotime($v['work_end_time']), 'work_record_num' => $v['work_record_num'], 'daily_salary' => $v['daily_salary'], 'daily_living' => $v['daily_living'], 'daily_subsidy' => $v['daily_subsidy'], 'daily_other' => $v['daily_other'], 'daily_income' => $v['daily_income'], 'remark' => $v['work_num'] ?? '', ]); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑考勤记录 * @param array $params * @return bool * @author likeadmin * @date 2023/12/26 09:44 */ public static function edit(array $params): bool { Db::startTrans(); try { ProjectAttendanceRecord::where('id', $params['id'])->update([ 'project_id' => $params['project_id'], 'attendance_date' => strtotime($params['attendance_date']), 'remark' => $params['remark'], 'annex' => $params['annex'] ? json_encode($params['annex']) : null, ]); foreach ($params['attendance_detail'] as $v) { if (!empty($v['id'])) { ProjectAttendanceDetail::where('id', $v['id'])->update([ 'attendance_id' => $params['id'], 'project_id' => $params['project_id'], 'person_id' => $v['person_id'], 'attendance_date' => strtotime($params['attendance_date']), 'work_start_time' => strtotime($v['work_start_time']), 'work_end_time' => strtotime($v['work_end_time']), 'work_record_num' => $v['work_record_num'], 'daily_salary' => $v['daily_salary'], 'daily_living' => $v['daily_living'], 'daily_subsidy' => $v['daily_subsidy'], 'daily_other' => $v['daily_other'], 'daily_income' => $v['daily_income'], 'remark' => $v['work_num'] ?? '', ]); } else { ProjectAttendanceDetail::create([ 'attendance_id' => $params['id'], 'project_id' => $params['project_id'], 'person_id' => $v['person_id'], 'attendance_date' => strtotime($params['attendance_date']), 'work_start_time' => strtotime($v['work_start_time']), 'work_end_time' => strtotime($v['work_end_time']), 'work_record_num' => $v['work_record_num'], 'daily_salary' => $v['daily_salary'], 'daily_living' => $v['daily_living'], 'daily_subsidy' => $v['daily_subsidy'], 'daily_other' => $v['daily_other'], 'daily_income' => $v['daily_income'], 'remark' => $v['work_num'] ?? '', ]); } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除考勤记录 * @param array $params * @return bool * @author likeadmin * @date 2023/12/26 09:44 */ public static function delete(array $params): bool { $detail = ProjectAttendanceDetail::where('attendance_id', 'in', $params['id'])->findOrEmpty(); if (!$detail->isEmpty()) { self::setError('此数据关联了考勤明细内容,需删除考勤明细内容'); return false; } return ProjectAttendanceRecord::destroy($params['id']); } /** * @notes 获取考勤记录详情 * @param $params * @return array * @author likeadmin * @date 2023/12/26 09:44 */ public static function detail($params): array { $data = ProjectAttendanceRecord::field(['id', 'attendance_code', 'project_id', 'attendance_date', 'remark', 'annex'])->findOrEmpty($params['id'])->toArray(); $project = Project::field('name,project_code')->where('id', $data['project_id'])->findOrEmpty(); $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['attendance_num'] = ProjectAttendanceDetail::field('id')->where('attendance_id', $data['id'])->count(); $data['attendance_detail'] = ProjectAttendanceDetail::field(['id', 'person_id', 'work_start_time', 'work_end_time', 'work_record_num', 'daily_salary', 'daily_living', 'daily_subsidy', 'daily_other', 'daily_income', 'remark'])->where('attendance_id', $data['id']) ->select()->each(function ($item) { $person = ProjectPersonnel::field('name,idcard,work_type')->where('id', $item['person_id'])->findOrEmpty(); $item['name'] = $person['name']; $item['idcard'] = $person['idcard']; $item['work_type_text'] = $person->work_type_text; return $item; }) ->toArray(); return $data; } }