65 lines
2.7 KiB
TypeScript
65 lines
2.7 KiB
TypeScript
import { GM_MAIL_TYPE, MAIL_TIME_TYPE } from "../../consts";
|
||
import { isArray } from 'underscore';
|
||
|
||
export class UpdateMailParams {
|
||
hasGoods: boolean = false; // 是否有道具
|
||
goods: {id: number; count: number}[];
|
||
timeType: MAIL_TIME_TYPE; // 邮件时间类型
|
||
expire: number; // 有效时间,单位小时
|
||
startTime: number; // 发送时间,延时邮件使用
|
||
circleStart: number; // 循环邮件开始循环时间
|
||
circleEnd: number; // 循环邮件结束循环时间
|
||
circleDay: number; // 循环时间,每周几,0表示每天
|
||
circleHour: string; // 几点发送
|
||
title: string;
|
||
content: string;
|
||
sendName: string;
|
||
mailType: GM_MAIL_TYPE; // 收件人类型
|
||
receivers: {env: string; serverId: number; roleId: string; roleName: string; }[];
|
||
reason: string; // 原因
|
||
isSp: boolean = false; // 特殊邮件
|
||
isSingle: boolean;
|
||
|
||
constructor(obj: UpdateMailParams) {
|
||
this.goods = obj.goods;
|
||
this.hasGoods = obj.goods?.length > 0;
|
||
this.timeType = obj.timeType;
|
||
this.expire = obj.expire;
|
||
this.startTime = obj.startTime;
|
||
this.circleStart = obj.circleStart;
|
||
this.circleEnd = obj.circleEnd;
|
||
this.circleDay = obj.circleDay;
|
||
this.circleHour = obj.circleHour;
|
||
this.title = obj.title;
|
||
this.content = obj.content;
|
||
this.sendName = obj.sendName;
|
||
if(obj.isSingle == true) {
|
||
this.mailType = GM_MAIL_TYPE.SINGLE;
|
||
} else if (obj.isSingle == false) {
|
||
this.mailType = GM_MAIL_TYPE.SERVER;
|
||
}
|
||
this.receivers = obj.receivers;
|
||
this.reason = obj.reason;
|
||
}
|
||
|
||
checkParams() {
|
||
if(!this.title || !this.content || !this.sendName || !this.reason) return false;
|
||
if(this.timeType == MAIL_TIME_TYPE.IMMEDIATE) {
|
||
if(!this.expire) return false;
|
||
} else if (this.timeType == MAIL_TIME_TYPE.DELAY) {
|
||
if(!this.expire || !this.startTime) return false;
|
||
} else if (this.timeType == MAIL_TIME_TYPE.CIRCLE) {
|
||
if(!this.expire || !this.circleStart || !this.circleEnd || this.circleDay == undefined || !this.circleHour)
|
||
return false;
|
||
}
|
||
if(!this.receivers || !isArray(this.receivers)) return false;
|
||
if(!this.mailType) return false;
|
||
for(let { serverId, roleId, roleName } of this.receivers) {
|
||
if(!serverId) return false;
|
||
if(this.mailType == GM_MAIL_TYPE.SINGLE||this.mailType == GM_MAIL_TYPE.GROUP) {
|
||
if(!roleId || !roleName) return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
} |