You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.3 KiB
82 lines
2.3 KiB
'use strict';
|
|
const moment = require('moment')
|
|
const request = require('superagent');
|
|
|
|
module.exports = function (app, opts) {
|
|
|
|
async function judgeHoliday (dayStr, coolDown) {
|
|
const { timorApiUrl } = opts
|
|
const { models } = app.fs.dc
|
|
let dayStr_ = dayStr || moment().format('YYYY-MM-DD')
|
|
let holidayData = null
|
|
const dbRes = await models.Holiday.findOne({
|
|
where: {
|
|
day: dayStr_
|
|
}
|
|
})
|
|
let needCreate = false
|
|
if (dbRes) {
|
|
holidayData = dbRes.dataValues.holiday
|
|
} else {
|
|
needCreate = true
|
|
console.log("提莫 HOLIDAY 请求" + dayStr_);
|
|
let holidayRes = await request.get(
|
|
timorApiUrl + `holiday/info/${dayStr_}`
|
|
)
|
|
// 冷却一下
|
|
if (coolDown)
|
|
await new Promise(resolve => setTimeout(() => resolve(), 3000));
|
|
holidayData = holidayRes.body || {}
|
|
}
|
|
|
|
if (holidayData && holidayData.code == 0) {
|
|
let returnD = {
|
|
workday: false,
|
|
dayoff: false,
|
|
festivals: false,
|
|
params: holidayData.type
|
|
}
|
|
let dayType = null
|
|
let holidayType = holidayData.type.type
|
|
if (
|
|
holidayType == 2
|
|
&& holidayData.holiday
|
|
&& holidayData.holiday.wage == 3
|
|
) {
|
|
// 正经节假日 3倍工资那种
|
|
// festivals
|
|
returnD.festivals = true
|
|
dayType = 'festivals'
|
|
} else if (
|
|
holidayType == 1
|
|
|| (
|
|
holidayType == 2
|
|
&& holidayData.holiday
|
|
&& holidayData.holiday.wage < 3
|
|
)
|
|
) {
|
|
// 普假 休息日非节假日
|
|
returnD.dayoff = true
|
|
dayType = 'dayoff'
|
|
} else if (holidayType == 0 || holidayType == 3) {
|
|
// 工作日或补班
|
|
returnD.workday = true
|
|
dayType = 'workday'
|
|
}
|
|
if (needCreate && dayType) {
|
|
await models.Holiday.create({
|
|
day: dayStr_,
|
|
holiday: holidayData,
|
|
type: dayType
|
|
})
|
|
}
|
|
return returnD
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return {
|
|
judgeHoliday
|
|
}
|
|
}
|