123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 'use strict';
- /**
- * 审批信息重新发送modal
- *
- * @author EllisRan
- * @date 2024/01/18
- * @version
- */
- const smsTypeConst = require('../const/sms_type');
- module.exports = app => {
- class NoticeAgain extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'notice_again';
- }
- // 入库并判断
- async addNoticeAgain(transaction, type, datas) {
- // 判断用户是否已绑定公众号或者企业微信, 并判断用户是否开启了重新发送并且钩上对应的审批
- const userInfo = await this.ctx.service.projectAccount.getDataById(datas.uid);
- if (!userInfo.wx_type || userInfo.wx_type === '') return;
- const wxType = JSON.parse(userInfo.wx_type);
- // 没开启发送功能不应该生成重新发送入库数据
- if (wxType[type] && wxType[type].indexOf(smsTypeConst.judge.approval.toString()) !== -1) {
- datas.status = 0;
- const notice_again = userInfo.notice_again ? JSON.parse(userInfo.notice_again) : null;
- if ((userInfo.wx_openid || userInfo.qywx_userid) && notice_again && notice_again.checked && notice_again.sp[datas.sp_type]) {
- datas.status = 1;
- }
- datas.in_time = new Date();
- datas.last_time = this.ctx.helper.dateTran(new Date(), 'YYYY-MM-DD HH:mm');
- datas.times = 0;
- datas.wx_data = JSON.stringify(datas.wx_data);
- datas.sms_type = type;
- await transaction.insert(this.tableName, datas);
- }
- }
- async stopNoticeAgain(transaction, table_name, sp_id, status = 2) {
- // 判断sp_id是字符还是数组
- // if (sp_id instanceof Array) {
- // for (const id of sp_id) {
- // await transaction.update(this.tableName, { status }, { where: { table_name, sp_id: id } });
- // }
- // } else {
- await transaction.update(this.tableName, { status }, { where: { table_name, sp_id } });
- // }
- }
- // 针对撤回删除对应的重新发送数据
- async deleteNoticeAgain(transaction, table_name, sp_id) {
- // 判断sp_id是字符还是数组
- await transaction.delete(this.tableName, { table_name, sp_id });
- }
- async getSpResult(table_name, sp_id) {
- const sql = 'SELECT * FROM ?? WHERE id = ?';
- const sqlParam = [table_name, sp_id];
- return await this.db.queryOne(sql, sqlParam);
- }
- }
- return NoticeAgain;
- };
|