62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
const Service = require('egg').Service;
|
|
const validateUtil = require('@jianghujs/jianghu/app/common/validateUtil');
|
|
const { BizError, errorInfoEnum } = require('../constant/error');
|
|
const _ = require('lodash');
|
|
const idGenerateUtil = require("@jianghujs/jianghu/app/common/idGenerateUtil");
|
|
const dayjs = require('dayjs')
|
|
|
|
class NoticeService extends Service {
|
|
|
|
async insertAffiche() {
|
|
const { jianghuKnex } = this.app;
|
|
const { actionData } = this.ctx.request.body.appData;
|
|
const { afficheId, afficheMemberIdList, afficheStatus } = actionData
|
|
|
|
let noticeInsertData = null
|
|
|
|
if (afficheStatus === "已发送") {
|
|
// TODO:待完善
|
|
noticeInsertData = {
|
|
noticeId: await idGenerateUtil.uuid(),
|
|
noticeName: "通知-公告-" + afficheId,
|
|
noticeContent: afficheMemberIdList,
|
|
pushContent: '{}',
|
|
pushStatus: "success",
|
|
pushAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
|
|
}
|
|
}
|
|
|
|
await jianghuKnex.transaction(async trx => {
|
|
await trx("affiche", this.ctx).jhInsert(actionData);
|
|
|
|
if (noticeInsertData) await trx("notice_push", this.ctx).jhInsert(noticeInsertData);
|
|
})
|
|
}
|
|
async updateAffiche() {
|
|
const { jianghuKnex } = this.app;
|
|
const { actionData } = this.ctx.request.body.appData;
|
|
const { afficheId, afficheMemberIdList, afficheStatus } = actionData
|
|
|
|
let noticeInsertData = null
|
|
|
|
if (afficheStatus === "已发送") {
|
|
// TODO:待完善
|
|
noticeInsertData = {
|
|
noticeId: await idGenerateUtil.uuid(),
|
|
noticeName: "通知-公告-" + afficheId,
|
|
noticeContent: afficheMemberIdList,
|
|
pushContent: '{}',
|
|
pushStatus: "success",
|
|
pushAt: dayjs().format("YYYY-MM-DD HH:mm:ss")
|
|
}
|
|
}
|
|
|
|
console.log('appData_+_+_+_+', actionData);
|
|
await jianghuKnex.transaction(async trx => {
|
|
await trx("affiche", this.ctx).jhUpdate(actionData);
|
|
if (noticeInsertData) await trx("notice_push", this.ctx).jhInsert(noticeInsertData);
|
|
})
|
|
}
|
|
}
|
|
|
|
module.exports = NoticeService; |