diff --git a/game-server/app/services/gmService.ts b/game-server/app/services/gmService.ts index 63eebd310..9d5defc00 100644 --- a/game-server/app/services/gmService.ts +++ b/game-server/app/services/gmService.ts @@ -1,5 +1,5 @@ import { MarqueeType, MarqueeModel } from "../db/Marquee"; -import { GM_MAIL_STATUS, MAIL_TIME_TYPE, MARQUEE_TYPE, REF_CIRCLE_MAIL_TIME, SERVER_STATUS } from "../consts"; +import { GM_MAIL_STATUS, GM_MAIL_TYPE, MAIL_TIME_TYPE, MARQUEE_TYPE, REF_CIRCLE_MAIL_TIME, SERVER_STATUS } from "../consts"; import { scheduleJob, scheduledJobs, Job } from 'node-schedule'; import { createMarqueeMsg as sysCreateMarqueeMsg, pushMarqueeMsg as sysPushMarqueeMsg } from './sysChatService'; import { GroupMessageType } from "../db/GroupMessage"; @@ -13,6 +13,7 @@ import moment = require("moment"); import { getSeconds, nowSeconds } from "../pubUtils/timeUtil"; import { CreateServerParam } from "../domain/backEndField/params"; import { RegionModel, RegionType } from "../db/Region"; +import { GMMail as StategyMail } from "../db/ServerStategy"; // —————————————— 跑马灯 —————————————— // // 初始 @@ -104,16 +105,9 @@ export async function cancelMarquee(code: string) { return true } -export async function sendOpenServerMail(type: 'openMail'|'circleMail', mail: GMMail, newServer: ServerlistType, uid: number) { - let receivers = [{ - env: newServer.env, - serverId: newServer.id - }]; - let addParam = {...mail, receivers, status: GM_MAIL_STATUS.PASS }; - if(type == 'openMail') { - addParam.timeType = MAIL_TIME_TYPE.DELAY; - addParam.startTime = newServer.openTime; - } +export async function sendOpenServerMail(type: 'openMail'|'circleMail', mail: StategyMail, newServer: ServerlistType, uid: number) { + let addParam = new GMMail(); + addParam.setByRegionStategy(type, mail, newServer, uid); let gmmail = await GMMailModel.addMail(addParam, uid); let needSend = false; if(mail.timeType == MAIL_TIME_TYPE.CIRCLE) { diff --git a/shared/db/GMMail.ts b/shared/db/GMMail.ts index a341f2cd0..98b11f98d 100644 --- a/shared/db/GMMail.ts +++ b/shared/db/GMMail.ts @@ -6,6 +6,9 @@ import { getModelForClass, prop, DocumentType, mongoose, ReturnModelType } from import { GM_MAIL_STATUS, GM_MAIL_TYPE, MAIL_TIME_TYPE } from '../consts'; import { SearchMailParam } from '../domain/backEndField/search'; import { getCurDay, nowSeconds } from '../pubUtils/timeUtil'; +import { GMMail as StategyMail } from './ServerStategy'; +import { ServerlistType } from './Serverlist'; +import moment = require('moment'); class Reward { @prop({ required: true }) @@ -87,6 +90,39 @@ export default class GMMail extends BaseModel { @prop({ required: true }) sendTime: string; // 发送时间 + public setByRegionStategy(type: 'openMail'|'circleMail', gmmail: StategyMail, newServer: ServerlistType, uid) { + this.hasGoods = !!gmmail.goods?.length; + this.goods = gmmail.goods; + this.timeType = type == 'openMail'? MAIL_TIME_TYPE.DELAY: MAIL_TIME_TYPE.CIRCLE; + this.expire = gmmail.expire; + if(type == 'openMail') { + this.startTime = nowSeconds(); + } else { + this.circleStart = nowSeconds(); + this.circleEnd = nowSeconds() + gmmail.circleContinueDay * 24 * 60 * 60; + this.circleDay = gmmail.circleDay; + this.circleHour = gmmail.circleHour; + } + this.title = gmmail.title; + this.content = gmmail.content; + this.sendName = gmmail.sendName; + this.mailType = GM_MAIL_TYPE.SERVER; + this.receivers = [{ + env: newServer.env, + serverId: newServer.id + }]; + this.reason = gmmail.reason; + this.isSp = gmmail.isSp; + this.status = GM_MAIL_STATUS.PASS; + this.viewBy = uid; + this.viewAt = new Date(); + if (type == 'openMail') { + this.sendTime = moment(this.startTime * 1000).format('YYYY-MM-DD HH:mm:ss'); + } else { + this.sendTime = (this.circleDay == 0?'每天': '每周'+this.circleDay) + ' ' + this.circleHour; + } + } + public static async addMail(params: GMMailTypeParam, uid = 1) { const doc = new GMMailModel(); let mail = Object.assign(doc.toJSON(), params); diff --git a/shared/db/ServerStategy.ts b/shared/db/ServerStategy.ts index a37569da0..92a58fc35 100644 --- a/shared/db/ServerStategy.ts +++ b/shared/db/ServerStategy.ts @@ -1,5 +1,55 @@ import { prop, DocumentType, } from '@typegoose/typegoose'; -import GMMail from './GMMail'; +import { GM_MAIL_TYPE, MAIL_TIME_TYPE } from '../consts'; + +class Reward { + @prop({ required: true }) + id: number; + @prop({ required: true }) + count: number; +} + +export class GMMail { + + @prop({ required: false}) + hasGoods: boolean; // 有效时间,单位小时 + + @prop({ required: true, type: Reward, default: [], _id: false }) + goods: Reward[]; + + @prop({ required: true, default: true }) + timeType: MAIL_TIME_TYPE; // 邮件时间类型 + + @prop({ required: false}) + expire: number; // 有效时间,单位小时 + + @prop({ required: true }) + circleContinueDay: number; // 循环邮件持续天数 + + @prop({ required: true }) + circleDay: number; // 循环时间,每周几,0表示每天 + + @prop({ required: true }) + circleHour: string; // 几点发送 + + @prop({ required: true }) + title: string; + + @prop({ required: true }) + content: string; + + @prop({ required: true }) + sendName: string; + + @prop({ required: true }) + mailType: GM_MAIL_TYPE; // 收件人类型 + + @prop({ required: true }) + reason: string; // 原因 + + @prop({ required: true, default: false }) + isSp: boolean; // 特殊邮件 +} + export default class ServerStategy { diff --git a/shared/domain/backEndField/params.ts b/shared/domain/backEndField/params.ts index b78f92049..43567aee3 100644 --- a/shared/domain/backEndField/params.ts +++ b/shared/domain/backEndField/params.ts @@ -1,7 +1,6 @@ import { GM_MAIL_TYPE, MAIL_TIME_TYPE, SERVER_TIMER } from "../../consts"; import { isArray } from 'underscore'; -import GMMail from "../../db/GMMail"; -import ServerStategy from "../../db/ServerStategy"; +import ServerStategy, { GMMail } from "../../db/ServerStategy"; import { RegionType } from "../../db/Region"; export class UpdateMailParams {