From 4f24ba31002ee8cf4bf8ad97327d1de26db6c6d8 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Thu, 12 Oct 2023 02:55:12 +0800 Subject: [PATCH] fix attendance retroactive --- app/Repositories/AttendanceRepository.php | 4 ++-- include/constants.php | 2 +- public/ajax.php | 2 +- public/attendance.php | 12 ++++-------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/Repositories/AttendanceRepository.php b/app/Repositories/AttendanceRepository.php index a3003581..63d2f529 100644 --- a/app/Repositories/AttendanceRepository.php +++ b/app/Repositories/AttendanceRepository.php @@ -281,7 +281,7 @@ class AttendanceRepository extends BaseRepository } - public function retroactive($user, $timestampMs) + public function retroactive($user, $dateStr) { if (!$user instanceof User) { $user = User::query()->findOrFail((int)$user); @@ -290,7 +290,7 @@ class AttendanceRepository extends BaseRepository if (!$attendance) { throw new \LogicException(nexus_trans('attendance.have_not_attendance_yet')); } - $date = Carbon::createFromTimestampMs($timestampMs); + $date = Carbon::parse($dateStr); $now = Carbon::now(); if ($date->gte($now) || $now->diffInDays($date) > Attendance::MAX_RETROACTIVE_DAYS) { throw new \LogicException(nexus_trans('attendance.target_date_can_no_be_retroactive', ['date' => $date->format('Y-m-d')])); diff --git a/include/constants.php b/include/constants.php index 93f8b677..e9438c66 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ retroactive($CURUSER['id'], $params['timestamp']); + return $rep->retroactive($CURUSER['id'], $params['date']); } public static function getPtGen($params) diff --git a/public/attendance.php b/public/attendance.php index c86d56aa..e98e90b2 100644 --- a/public/attendance.php +++ b/public/attendance.php @@ -89,23 +89,19 @@ document.addEventListener('DOMContentLoaded', function() { eventClick: function(info) { console.log(info.event); if (info.event.groupId == 'to_do') { - retroactive(info.event.start) + retroactive(info.event.startStr) } } }); calendar.render(); }); -function retroactive(start) { - let year = start.getFullYear() - let month = start.getMonth() + 1 - let day = start.getDate() - let date = year + '-' + month + '-' + day - if (!window.confirm(confirmText + date + ' ?')) { +function retroactive(dateStr) { + if (!window.confirm(confirmText + dateStr + ' ?')) { console.log("cancel") return } - jQuery.post('ajax.php', {params: {timestamp: start.getTime()}, action: 'attendanceRetroactive'}, function (response) { + jQuery.post('ajax.php', {params: {date: dateStr}, action: 'attendanceRetroactive'}, function (response) { console.log(response); if (response.ret != 0) { alert(response.msg)