40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
import { RewardInter, pushMail } from "../pubUtils/interface";
|
|
import { MailModel, MailType } from "../db/Mail";
|
|
import { getRedis } from "./redisService";
|
|
import { pinus } from "pinus";
|
|
import { gameData } from "../pubUtils/data";
|
|
import { nowSeconds } from '../pubUtils/timeUtil';
|
|
import { STATUS } from '../consts/statusCode';
|
|
import { resResult } from '../pubUtils/util';
|
|
|
|
export async function sendMail(operate: number, toRoleId: string, sendName: string = '系统', params: string[] = [], goods: RewardInter[] = []) {
|
|
let content = getContent( operate, params);
|
|
let mail = await MailModel.addMail({roleId: toRoleId, goods, sendName, mailId: 1, content});
|
|
|
|
let key = 'login_roleId_' + toRoleId;
|
|
let sid = await getRedis(key);
|
|
if (!!sid) {
|
|
pinus.app.channelService.pushMessageByUids('onMailsAdd', resResult(STATUS.SUCCESS, { mails:[mail] }), [{uid: toRoleId, sid}]);
|
|
}
|
|
}
|
|
|
|
export function getContent(operate: number, params: string[]) {
|
|
let content = gameData.mail.get(operate)||'%d';
|
|
for(let p of params) {
|
|
content = content.replace(/%d/, p);
|
|
}
|
|
return content
|
|
}
|
|
export async function getMailContent(roleId: string, operate: number, params: string[], goods:RewardInter[], mails:MailType[], pushMessage:pushMail[], sendName: string = '系统') {
|
|
const doc = new MailModel();
|
|
let content = getContent( operate, params);
|
|
|
|
const mail = Object.assign(doc.toJSON(), {roleId, goods, sendName, mailId: 1, sendTime: nowSeconds(), content});
|
|
mails.push(mail);
|
|
let key = 'login_roleId_' + roleId;
|
|
let sid = await getRedis(key);
|
|
if (!!sid) {
|
|
pushMessage.push({route: 'onMailsAdd', data:[mail], uids: [{uid:roleId, sid}]});
|
|
}
|
|
}
|