'use strict'; const moment = require('moment') const { pushBySms } = require('../../../../utils/push.js'); async function getAnspectionNotificationPhone(ctx) { try { const models = ctx.fs.dc.models; let findOption = { where: { }, order: [['id', 'DESC']] } const roadRes = await models.AnspectionNotificationPhone.findAll(findOption) ctx.status = 200; ctx.body = roadRes } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined } } } async function addAnspectionNotificationPhone(ctx) { try { // const transaction = await ctx.fs.dc.orm.transaction(); const models = ctx.fs.dc.models; const data = ctx.request.body; await models.AnspectionNotificationPhone.destroy({ where: {} }) let dataList = [] data.phone && data.phone.map(e => { dataList.push({ phone: e }) }) await models.AnspectionNotificationPhone.bulkCreate(dataList); // await transaction.commit(); ctx.status = 204 } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined } } } function pushAppointSMS(opts) { return async function (ctx) { try { const { phone = [] } = ctx.request.body if (phone.length) { await pushBySms({ accessKey: opts.sms.accessKey, accessSecret: opts.sms.accessSecret, phone: phone, templateCode: 'SMS_273640525', }) } else { throw '缺少请求参数'; } ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : '短信推送失败' } } } } module.exports = { getAnspectionNotificationPhone, addAnspectionNotificationPhone, pushAppointSMS };