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.
65 lines
1.7 KiB
65 lines
1.7 KiB
2 years ago
|
'use strict';
|
||
|
const moment = require('moment')
|
||
|
const request = require('superagent');
|
||
|
|
||
|
module.exports = function (app, opts) {
|
||
|
|
||
|
async function judgeHoliday (dayStr) {
|
||
|
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_
|
||
|
}
|
||
|
})
|
||
|
if (dbRes) {
|
||
|
holidayData = dbRes.dataValues.holiday
|
||
|
} else {
|
||
|
let holidayRes = await request.get(
|
||
|
timorApiUrl + `holiday/info/${dayStr_}`
|
||
|
)
|
||
|
holidayData = holidayRes.body || {}
|
||
|
}
|
||
|
|
||
|
if (holidayData && holidayData.code == 0) {
|
||
|
let returnD = {
|
||
|
workday: false,
|
||
|
dayoff: false,
|
||
|
festivals: false,
|
||
|
params: holidayData.type
|
||
|
}
|
||
|
let holidayType = holidayData.type.type
|
||
|
if (
|
||
|
holidayType == 2
|
||
|
&& holidayData.holiday
|
||
|
&& holidayData.holiday.wage == 3
|
||
|
) {
|
||
|
// 正经节假日 3倍工资那种
|
||
|
// festivals
|
||
|
returnD.festivals = true
|
||
|
} else if (
|
||
|
holidayType == 1
|
||
|
|| (
|
||
|
holidayType == 2
|
||
|
&& holidayData.holiday
|
||
|
&& holidayData.holiday.wage < 3
|
||
|
)
|
||
|
) {
|
||
|
// 普假 休息日非节假日
|
||
|
returnD.dayoff = true
|
||
|
} else if (holidayType == 0 || holidayType == 3) {
|
||
|
// 工作日或补班
|
||
|
returnD.workday = true
|
||
|
}
|
||
|
return returnD
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
judgeHoliday
|
||
|
}
|
||
|
}
|