const { Service } = require('egg'); class NotificationService extends Service { constructor(ctx) { super(ctx); // 设置全局变量 oldAction this.oldreceivingUrl = 'http://ye4s.wms.gztbyc.com/index/wms/wms/receiving_notic'; } /** * 发送通知 * @param {Object} options - 通知参数 * @param {string} options.type - 通知类型,如 'email', 'sms', 'system' * @param {string} options.title - 通知标题 * @param {string} options.content - 通知内容 * @param {string} options.bussinessType - 业务类型,如 'receiving' * @param {string[]} [options.receivers] - 接收人列表 * @param {string} options.bussinessId - 业务ID * @return {Promise} 发送结果 */ async send(options) { const { type, title, content, bussinessType, bussinessId, receivers = [] } = options; switch (bussinessType) { case 'receiving': // 发送接收通知 await this.ctx.curl(this.oldreceivingUrl, { method: 'POST', data: { id: bussinessId, }, dataType: 'json', }); break; } return { success: true, message: '通知已发送', data: { type, title, content, receivers, }, }; } } module.exports = NotificationService;