module.exports = () => { const schedule = require('node-schedule') // 发送定时短信,每个整点以及半点执行 schedule.scheduleJob('0 0,30 * * * *', async () => { const dayjs = require('dayjs') const db = require('../data') const now = dayjs().add(1, 'minute').format('YYYY-MM-DD HH:mm:ss') const rs = await db.select(`select id,mobile,content from mobile_sms_timing where datetime<='${now}'`) if (rs.length) { const id = [] const Message = require('../controllers/message') rs.forEach(item => { id.push(item.id) Message.SendSMS(item.mobile, item.content) }) db.execute('delete from mobile_sms_timing where id in (' + id.join() + ')') } }) } /** * 时间设置(https://qqe2.com/cron): * 6项第一个为秒,5项第一个为分 */