|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
|
import BaseModel from './BaseModel';
|
|
|
|
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
|
|
|
|
import { getTodayZeroDate } from '../pubUtils/timeUtil';
|
|
|
|
|
import { getCurWeekDate} from '../pubUtils/timeUtil';
|
|
|
|
|
|
|
|
|
|
@index({ serverId: 1, cityId: 1, createdAt: 1 })
|
|
|
|
|
export default class GuildActivityCity extends BaseModel {
|
|
|
|
@@ -23,34 +23,47 @@ export default class GuildActivityCity extends BaseModel {
|
|
|
|
|
@prop({ required: true })
|
|
|
|
|
guardGuildName: string; // 占领的军团名
|
|
|
|
|
|
|
|
|
|
@prop({ required: true })
|
|
|
|
|
guardTime: Date; // 占领日期
|
|
|
|
|
|
|
|
|
|
// 每天宣战一次
|
|
|
|
|
public static async getAllCities(serverId: number) {
|
|
|
|
|
let today = getTodayZeroDate();
|
|
|
|
|
let rec: GuildActivityCityType[] = await GuildActivityCityModel.find({ serverId, createdAt: { $gte: today }}).lean();
|
|
|
|
|
|
|
|
|
|
let curWeek = getCurWeekDate(1, 0);
|
|
|
|
|
let rec: GuildActivityCityType[] = await GuildActivityCityModel.find({ serverId, createdAt: { $gte: curWeek }}).lean();
|
|
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查是否宣战过
|
|
|
|
|
public static async checkDeclartion(serverId: number, guildCode: string) {
|
|
|
|
|
let today = getTodayZeroDate();
|
|
|
|
|
let curWeek = getCurWeekDate(1, 0);
|
|
|
|
|
let rec: GuildActivityCityType = await GuildActivityCityModel.findOne(
|
|
|
|
|
{ serverId, createdAt: { $gte: today }, declareGuilds: { $in: [guildCode]}}).lean();
|
|
|
|
|
{ serverId, createdAt: { $gte: curWeek }, declareGuilds: { $in: [guildCode]}}).lean();
|
|
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 每天宣战一次
|
|
|
|
|
// 宣言
|
|
|
|
|
public static async declare(serverId: number, cityId: number, guildCode: string) {
|
|
|
|
|
let today = getTodayZeroDate();
|
|
|
|
|
let curWeek = getCurWeekDate(1, 0);
|
|
|
|
|
let rec: GuildActivityCityType = await GuildActivityCityModel.findOneAndUpdate(
|
|
|
|
|
{ serverId, cityId, createdAt: { $gte: today } },
|
|
|
|
|
{ $setOnInsert: { cityId }, $push: { declareGuilds: guildCode }, $inc: {declareCount: 1 } },
|
|
|
|
|
{ serverId, cityId, createdAt: { $gte: curWeek } },
|
|
|
|
|
{ $setOnInsert: { serverId, cityId }, $push: { declareGuilds: guildCode }, $inc: {declareCount: 1 } },
|
|
|
|
|
{new: true, upsert: true}).lean();
|
|
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 占领
|
|
|
|
|
public static async guard(serverId: number, cityId: number, guildCode: string, guildName: string) {
|
|
|
|
|
let curWeek = getCurWeekDate(1, 0);
|
|
|
|
|
let rec: GuildActivityCityType = await GuildActivityCityModel.findOneAndUpdate(
|
|
|
|
|
{ serverId, cityId, createdAt: { $gte: curWeek } },
|
|
|
|
|
{ $set: { declareCount: 0, declareGuilds: [], guardGuildCode: guildCode, guardGuildName: guildName, guardTime: new Date()} },
|
|
|
|
|
{ new: true }).lean();
|
|
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const GuildActivityCityModel = getModelForClass(GuildActivityCity);
|
|
|
|
|