|
@@ -61,11 +61,9 @@ class NoticeService extends CrudService {
|
|
|
// 1,判断有没有openid;2有openid的发送消息,添加记录
|
|
|
if (!_.get(user, 'openid')) continue;
|
|
|
const openid = _.get(user, 'openid');
|
|
|
- const remark = '感谢您的使用';
|
|
|
- const date = await this.ctx.service.util.updatedate();
|
|
|
const detail = content;
|
|
|
const tourl = this.ctx.app.config.baseUrl + '/trainnotice/?userid=' + user.uid + '¬iceid=' + res.id;
|
|
|
- this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知,请点击确认您已收到信息!', detail, date, remark, tourl);
|
|
|
+ await this.toSendWithUrl(openid, detail, tourl);
|
|
|
const notified = _.get(res, 'notified', []);
|
|
|
notified.push({ notifiedid: user.uid, username: user.name });
|
|
|
res.notified = notified;
|
|
@@ -134,23 +132,23 @@ class NoticeService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async query({ skip, limit, ...info }) {
|
|
|
- const total = await this.model.count(info);
|
|
|
- const notices = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
|
|
|
- const res = [];
|
|
|
- for (const _notice of notices) {
|
|
|
- const notice = _.cloneDeep(JSON.parse(JSON.stringify(_notice)));
|
|
|
- const { noticeid, content, notified, meta } = notice;
|
|
|
- const elm = [];
|
|
|
- for (const notified of notice.notified) {
|
|
|
- const _notified = _.cloneDeep(JSON.parse(JSON.stringify(notified)));
|
|
|
- const userinfo = await this.findUserInfo(_notified.notifiedid);
|
|
|
- elm.push({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
|
|
|
- }
|
|
|
- res.push({ noticeid, content, meta, notified: elm });
|
|
|
- }
|
|
|
- return { data: res, total };
|
|
|
- }
|
|
|
+ // async query({ skip, limit, ...info }) {
|
|
|
+ // const total = await this.model.count(info);
|
|
|
+ // const notices = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
|
|
|
+ // const res = [];
|
|
|
+ // for (const _notice of notices) {
|
|
|
+ // const notice = _.cloneDeep(JSON.parse(JSON.stringify(_notice)));
|
|
|
+ // const { noticeid, content, notified, meta, _id } = notice;
|
|
|
+ // const elm = [];
|
|
|
+ // for (const notified of notice.notified) {
|
|
|
+ // const _notified = _.cloneDeep(JSON.parse(JSON.stringify(notified)));
|
|
|
+ // const userinfo = await this.findUserInfo(_notified.notifiedid);
|
|
|
+ // elm.push({ ...JSON.parse(JSON.stringify(userinfo)), ..._notified });
|
|
|
+ // }
|
|
|
+ // res.push({ noticeid, content, meta, notified: elm });
|
|
|
+ // }
|
|
|
+ // return { data: res, total };
|
|
|
+ // }
|
|
|
|
|
|
async findUserInfo(userid) {
|
|
|
let userinfo;
|
|
@@ -168,6 +166,35 @@ class NoticeService extends CrudService {
|
|
|
return userinfo;
|
|
|
}
|
|
|
|
|
|
+ async resend({ id }) {
|
|
|
+ const res = await this.model.findById(id);
|
|
|
+ if (res) {
|
|
|
+ const { content, notified } = res;
|
|
|
+ const useridList = notified.filter(f => f.status === '0').map(i => i.notifiedid);
|
|
|
+ const userList = await this.umodel.find({ _id: { $in: useridList } });
|
|
|
+ console.log('in function:');
|
|
|
+ for (const user of userList) {
|
|
|
+ if (!_.get(user, 'openid')) continue;
|
|
|
+ const openid = _.get(user, 'openid');
|
|
|
+ const detail = content;
|
|
|
+ const tourl = this.ctx.app.config.baseUrl + '/trainnotice/?userid=' + user.uid + '¬iceid=' + res.id;
|
|
|
+ await this.toSendWithUrl(openid, detail, tourl);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param {String} openid user表的openid
|
|
|
+ * @param {String} detail 通知内容
|
|
|
+ * @param {String} tourl 确认通知地址
|
|
|
+ */
|
|
|
+ async toSendWithUrl(openid, detail, tourl) {
|
|
|
+ const remark = '感谢您的使用';
|
|
|
+ const date = await this.ctx.service.util.updatedate();
|
|
|
+ this.ctx.service.weixin.sendTemplateDesign(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有未读信息需要确认,请点击确认您已收到信息!', detail, date, remark, tourl);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = NoticeService;
|