'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 } }