|
@@ -12,6 +12,7 @@ const auditConst = require('../const/audit');
|
|
|
const officeList = require('../const/cld_office').list;
|
|
|
const maintainConst = require('../const/maintain');
|
|
|
const typeColMap = require('../const/advance').typeColMap;
|
|
|
+const moment = require('moment');
|
|
|
|
|
|
module.exports = app => {
|
|
|
|
|
@@ -207,6 +208,35 @@ module.exports = app => {
|
|
|
ctx.helper.validate(rule);
|
|
|
const result = await ctx.service.message.save(id, ctx.request.body, ctx.session.sessionUser, ctx.session.sessionProject.id);
|
|
|
if (result) {
|
|
|
+ // 新增的项目通知会发送微信模版消息通知客户
|
|
|
+ if (id === 0) {
|
|
|
+ // 获取该项目所有的openid,发送信息
|
|
|
+ const wechats = await ctx.service.projectAccount.getOpenIdListByPid(ctx.session.sessionProject.id);
|
|
|
+ if (wechats.length > 0) {
|
|
|
+ const msgInfo = await ctx.service.message.getDataById(result);
|
|
|
+ const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
|
|
|
+ // 绑定成功通知
|
|
|
+ const templateId = 'VKUo4us4lt2dQY0EaaJxcui2jkjmriN3A0K7i4kpZwY';
|
|
|
+ const url = ctx.protocol + '://' + ctx.host + '/wap/dashboard/msg/' + msgInfo.id;
|
|
|
+ const msgData = {
|
|
|
+ thing21: {
|
|
|
+ value: projectData.code,
|
|
|
+ },
|
|
|
+ thing2: {
|
|
|
+ value: ctx.helper.contentChange(msgInfo.title),
|
|
|
+ },
|
|
|
+ thing8: {
|
|
|
+ value: msgInfo.creator,
|
|
|
+ },
|
|
|
+ time3: {
|
|
|
+ value: moment(msgInfo.release_time * 1000).format('YYYY-MM-DD'),
|
|
|
+ },
|
|
|
+ };
|
|
|
+ for (const wx of wechats) {
|
|
|
+ await app.wechat.api.sendTemplate(wx.wx_openid, templateId, url, '', msgData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
ctx.redirect('/dashboard/msg/list');
|
|
|
}
|
|
|
} catch (error) {
|