后台:发送邮件
This commit is contained in:
@@ -84,8 +84,13 @@ export class SendMailFun {
|
||||
let gmmail = await GMMailModel.getGmMailById(gmmailId);
|
||||
if(gmmail) {
|
||||
this.gmmail = gmmail;
|
||||
this.sendTime = gmmail.sendTime;
|
||||
this.endTime = gmmail.endTime;
|
||||
if(gmmail.useTempTime) {
|
||||
this.sendTime = gmmail.sendTime;
|
||||
this.endTime = gmmail.endTime;
|
||||
} else {
|
||||
this.sendTime = nowSeconds();
|
||||
this.endTime = this.sendTime + (gmmail.continueHour||0) * 60 * 60;
|
||||
}
|
||||
this.setParam({ ...gmmail });
|
||||
}
|
||||
}
|
||||
@@ -166,19 +171,17 @@ export class SendMailFun {
|
||||
}
|
||||
}
|
||||
|
||||
if (uids.length > 0) {//下发邮件,对应前端红点提示
|
||||
if(mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
let mails = await this.createSingleMails(roleIds);
|
||||
for(let { uid, sid } of uids) {
|
||||
let mail = mails.get(uid);
|
||||
if(mail && !this.notPush) pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: [mail] }), [{ uid, sid }]);
|
||||
}
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
let mail = await this.createGroupMails(roleIds);
|
||||
if(!this.notPush) pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: [mail] }), uids);
|
||||
} else { // mailType错误
|
||||
return false;
|
||||
if(mailType == GM_MAIL_TYPE.SINGLE) {
|
||||
let mails = await this.createSingleMails(roleIds);
|
||||
for(let { uid, sid } of uids) {
|
||||
let mail = mails.get(uid);
|
||||
if(uids.length > 0 && mail && !this.notPush) pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: [mail] }), [{ uid, sid }]);
|
||||
}
|
||||
} else if (mailType == GM_MAIL_TYPE.GROUP) {
|
||||
let mail = await this.createGroupMails(roleIds);
|
||||
if(uids.length > 0 && !this.notPush) pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails: [mail] }), uids);
|
||||
} else { // mailType错误
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
24
gm-server/app/controller/mail.ts
Normal file
24
gm-server/app/controller/mail.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Controller } from 'egg';
|
||||
import { STATUS } from '@consts';
|
||||
|
||||
export default class MailController extends Controller {
|
||||
public async getGMMailList() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.mail.getGMMailList(page, pageSize, sortField, sortOrder, form);
|
||||
return
|
||||
}
|
||||
|
||||
public async updateGMMail() {
|
||||
const { ctx } = this;
|
||||
const { _id, content, sendName, sendTime, endTime, useTempTime, continueHour } = ctx.request.body;
|
||||
if(!_id) return ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if(useTempTime) {
|
||||
if(!sendTime || !endTime) return ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
} else {
|
||||
if(!continueHour) return ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
ctx.body = await ctx.service.mail.updateGMMail(_id, content, sendName, useTempTime, sendTime, endTime, continueHour);
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -72,4 +72,7 @@ export default (app: Application) => {
|
||||
router.post('/api/activity/deleteactivitygrouptype', controller.activity.deleteActivityGroupType);
|
||||
router.post('/api/activity/saveactivitygrouptype', controller.activity.saveGroupTypeToActivityGroup);
|
||||
router.post('/api/activity/getgroupdatabyid', controller.activity.getGroupDataById);
|
||||
|
||||
router.post('/api/mail/getgmmaillist', controller.mail.getGMMailList);
|
||||
router.post('/api/mail/updategmmail', controller.mail.updateGMMail);
|
||||
};
|
||||
|
||||
26
gm-server/app/service/Mail.ts
Normal file
26
gm-server/app/service/Mail.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
import { Service } from 'egg';
|
||||
import { GMMailModel } from '@db/GMMail';
|
||||
import { STATUS } from '@consts';
|
||||
|
||||
export default class Mail extends Service {
|
||||
|
||||
public async getGMMailList(page: number, pageSize: number, sortField: string, sortOrder: string, form: {}) {
|
||||
const { ctx } = this;
|
||||
const list = await GMMailModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GMMailModel.countByCondition( form )
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list, total
|
||||
});
|
||||
}
|
||||
|
||||
public async updateGMMail(_id: string, content: string, sendName: string, useTempTime: boolean, sendTime: number, endTime: number, continueHour: number) {
|
||||
const { ctx } = this;
|
||||
if(_id == 'new') {
|
||||
await GMMailModel.addMail({ content, sendName, useTempTime, sendTime, endTime, continueHour });
|
||||
} else {
|
||||
await GMMailModel.updateMailById(_id, { content, sendName, useTempTime, sendTime, endTime, continueHour });
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
}
|
||||
2
gm-server/typings/app/controller/index.d.ts
vendored
2
gm-server/typings/app/controller/index.d.ts
vendored
@@ -7,6 +7,7 @@ import ExportGame from '../../../app/controller/game';
|
||||
import ExportGmaccount from '../../../app/controller/gmaccount';
|
||||
import ExportHome from '../../../app/controller/home';
|
||||
import ExportLogin from '../../../app/controller/login';
|
||||
import ExportMail from '../../../app/controller/mail';
|
||||
import ExportUpload from '../../../app/controller/upload';
|
||||
import ExportUsers from '../../../app/controller/users';
|
||||
|
||||
@@ -17,6 +18,7 @@ declare module 'egg' {
|
||||
gmaccount: ExportGmaccount;
|
||||
home: ExportHome;
|
||||
login: ExportLogin;
|
||||
mail: ExportMail;
|
||||
upload: ExportUpload;
|
||||
users: ExportUsers;
|
||||
}
|
||||
|
||||
2
gm-server/typings/app/service/index.d.ts
vendored
2
gm-server/typings/app/service/index.d.ts
vendored
@@ -9,6 +9,7 @@ type AutoInstanceType<T, U = T extends CanExportFunc ? T : T extends AnyFunc ? R
|
||||
import ExportActivity from '../../../app/service/Activity';
|
||||
import ExportGame from '../../../app/service/Game';
|
||||
import ExportGmUser from '../../../app/service/GmUser';
|
||||
import ExportMail from '../../../app/service/Mail';
|
||||
import ExportTest from '../../../app/service/Test';
|
||||
import ExportUtils from '../../../app/service/Utils';
|
||||
import ExportUsers from '../../../app/service/users';
|
||||
@@ -18,6 +19,7 @@ declare module 'egg' {
|
||||
activity: AutoInstanceType<typeof ExportActivity>;
|
||||
game: AutoInstanceType<typeof ExportGame>;
|
||||
gmUser: AutoInstanceType<typeof ExportGmUser>;
|
||||
mail: AutoInstanceType<typeof ExportMail>;
|
||||
test: AutoInstanceType<typeof ExportTest>;
|
||||
utils: AutoInstanceType<typeof ExportUtils>;
|
||||
users: AutoInstanceType<typeof ExportUsers>;
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { GM_MAIL_TYPE } from '../consts/constModules/mailConst';
|
||||
|
||||
class Reward {
|
||||
@prop({ required: true })
|
||||
@@ -18,11 +17,17 @@ export default class GMMail extends BaseModel {
|
||||
@prop({ required: true, type: Reward, default: [], _id: false })
|
||||
goods: Reward[];
|
||||
|
||||
@prop({ required: true, default: nowSeconds() })
|
||||
sendTime: number;
|
||||
@prop({ required: true, default: true })
|
||||
useTempTime: boolean; // 生成邮件是否按照模板时间
|
||||
|
||||
@prop({ required: false})
|
||||
continueHour: number; // 如果不按模板时间,sendTime为生成单独邮件的时候,endTime为sendTime+continueHour,单位小时
|
||||
|
||||
@prop({ required: true })
|
||||
endTime: number;
|
||||
sendTime: number; // 如果按照模板时间,发送时间,10位时间戳
|
||||
|
||||
@prop({ required: true })
|
||||
endTime: number; // 如果按照模板时间,过期时间,10位时间戳
|
||||
|
||||
@prop({ required: true })
|
||||
content: string;
|
||||
@@ -30,13 +35,15 @@ export default class GMMail extends BaseModel {
|
||||
@prop({ required: true })
|
||||
sendName: string;
|
||||
|
||||
@prop({ required: true, enum: GM_MAIL_TYPE })
|
||||
mailType: GM_MAIL_TYPE; // 1-单人邮件 2-多人邮件 3-全服邮件
|
||||
|
||||
public static async addMail(params: GMMailTypeParam) {
|
||||
public static async addMail(params: GMMailTypeParam, uid = 1) {
|
||||
const doc = new GMMailModel();
|
||||
let mail = Object.assign(doc.toJSON(), params);
|
||||
mail = await GMMailModel.findOneAndUpdate({ _id: mail._id }, { $set: mail }, {upsert: true, new: true}).lean();
|
||||
let result: GMMailType = await GMMailModel.findOneAndUpdate({ _id: mail._id }, { $set: {...mail, updatedBy: uid}, $setOnInsert: { createdBy: uid } }, {upsert: true, new: true}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateMailById(_id: string, params: GMMailTypeParam, uid: number = 1) {
|
||||
let mail: GMMailType = await GMMailModel.findByIdAndUpdate(_id, { $set: {...params, updatedBy: uid}}, {new: true}).lean();
|
||||
return mail;
|
||||
}
|
||||
|
||||
@@ -55,6 +62,38 @@ export default class GMMail extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static getSearchObj(form: {_id?: string, content?: string}) {
|
||||
let searchObj = {};
|
||||
if(form['_id']) searchObj['_id'] = form._id;
|
||||
if(form['content']) searchObj['context'] = { $regex: new RegExp(form.content.toString(), 'i') }
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, pageSize: number, sortField: string, sortOrder: string, form: {_id?: string, content?: string} = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
let sort = {};
|
||||
if(sortField && sortOrder) {
|
||||
if(sortOrder == 'ascend') {
|
||||
sort[sortField] = 1;
|
||||
} else if (sortOrder == 'descend') {
|
||||
sort[sortField] = -1;
|
||||
}
|
||||
}
|
||||
const result: GMMailType[] = await GMMailModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: {_id?: string, content?: string} = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await GMMailModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
export const GMMailModel = getModelForClass(GMMail);
|
||||
|
||||
Reference in New Issue
Block a user