|
@@ -92,7 +92,7 @@ class SupplementRecord extends API {
|
|
`;
|
|
`;
|
|
const records = await db.query(sqlCheckRecords, [project_id, userUUID]);
|
|
const records = await db.query(sqlCheckRecords, [project_id, userUUID]);
|
|
|
|
|
|
- if (records.some(record => this.hasRecord(item, record))) {
|
|
|
|
|
|
+ if (records.some(record => this.hasRecord(item, record, user))) {
|
|
return res.json({
|
|
return res.json({
|
|
...BaseStdResponse.ERR,
|
|
...BaseStdResponse.ERR,
|
|
endpoint: 513523,
|
|
endpoint: 513523,
|
|
@@ -132,23 +132,36 @@ class SupplementRecord extends API {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- hasRecord(attendanceData, record) {
|
|
|
|
|
|
+ hasRecord(attendanceData, records, uuid) {
|
|
const { day_of_week, begintime, loopy } = attendanceData;
|
|
const { day_of_week, begintime, loopy } = attendanceData;
|
|
|
|
+ if (!loopy) {
|
|
|
|
+ return records.some(record => record.uuid === uuid);
|
|
|
|
+ }
|
|
const now = new Date();
|
|
const now = new Date();
|
|
|
|
+ const dayOfWeek = now.getDay();
|
|
const nowTime = now.getTime();
|
|
const nowTime = now.getTime();
|
|
|
|
|
|
- if (!loopy) {
|
|
|
|
- return record.time >= nowTime;
|
|
|
|
|
|
+ function getTimestamp() {
|
|
|
|
+ // 计算今天与目标星期几的差值
|
|
|
|
+ // 目标星期几应当是从0到6的范围,0是星期日,6是星期六
|
|
|
|
+ const daysUntilTarget = (day_of_week - dayOfWeek + 7) % 7;
|
|
|
|
+ // 计算目标日期
|
|
|
|
+ const targetDate = new Date(now);
|
|
|
|
+ targetDate.setDate(now.getDate() + daysUntilTarget);
|
|
|
|
+ const [hours, minutes, seconds] = begintime.split(':').map(Number);
|
|
|
|
+ targetDate.setHours(hours, minutes, seconds, 0);
|
|
|
|
+ return targetDate.getTime();
|
|
}
|
|
}
|
|
|
|
|
|
- const targetDay = (day_of_week + 7 - now.getDay()) % 7;
|
|
|
|
- const targetDate = new Date(now);
|
|
|
|
- targetDate.setDate(now.getDate() + targetDay);
|
|
|
|
- const [hours, minutes, seconds] = begintime.split(':').map(Number);
|
|
|
|
- targetDate.setHours(hours, minutes, seconds, 0);
|
|
|
|
|
|
+ const begin = getTimestamp();
|
|
|
|
|
|
- return record.time >= targetDate.getTime() - 604800000;
|
|
|
|
|
|
+ if (nowTime >= begin) {
|
|
|
|
+ return records.some(record => record.time >= begin && record.uuid === uuid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return records.some(record => record.time >= begin - 604800000 && record.uuid === uuid);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
module.exports.SupplementRecord = SupplementRecord;
|
|
module.exports.SupplementRecord = SupplementRecord;
|