24 lines
914 B
TypeScript
24 lines
914 B
TypeScript
import { RewardInter } from "../pubUtils/interface";
|
|
import { MailModel } from "../db/Mail";
|
|
import { getRedis } from "./redisService";
|
|
import { pinus } from "pinus";
|
|
import { gameData } from "../pubUtils/data";
|
|
|
|
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.rpc.connector.connectorRemote.pushMessage.toServer(sid, toRoleId, 'onMailsAdd', [mail]);
|
|
}
|
|
}
|
|
|
|
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
|
|
} |