捐献
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
|
||||
class Report {
|
||||
@prop({ required: true })
|
||||
@@ -29,9 +30,13 @@ export default class Donation extends BaseModel {
|
||||
@prop({ required: true, default: 0})
|
||||
refTime: number;
|
||||
|
||||
public static async createDonation(guildCode: string, lean = true) {
|
||||
const doc = new Donation();
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:doc}, {upsert: true, new: true}).lean(lean);
|
||||
@prop({ required: true })
|
||||
donationLv: number;
|
||||
|
||||
public static async createDonation(guildCode: string, donationLv: number, lean = true) {
|
||||
const doc = new DonationModel();
|
||||
const update = Object.assign(doc.toJSON(), {refTime: nowSeconds(), reports:[], hisDonateFund: 0, donateFund: 0, donationLv});
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:update}, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -45,6 +50,10 @@ export default class Donation extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateDonation(guildCode: string, update: DonationUpdateParam, lean = true) {
|
||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, { $set:update }, {upsert: true, new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const DonationModel = getModelForClass(Donation);
|
||||
|
||||
@@ -90,6 +90,9 @@ export default class Guild extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
resetTrainTime: number;//上次刷新挑战训练场次数的时间
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
wishPoolLv: number; // 许愿池等级
|
||||
|
||||
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
||||
const doc = new GuildModel();
|
||||
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId });
|
||||
|
||||
@@ -2,7 +2,7 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
import Role, { RoleType } from './Role';
|
||||
import { GUILD_AUTH, USER_GUILD_STATUS, GUILD_JOB } from '../consts';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { getTodayZeroDate, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { ARMY } from '../pubUtils/dicParam';
|
||||
class ActiveRecord {
|
||||
@prop({ required: true })
|
||||
@@ -12,8 +12,6 @@ class ActiveRecord {
|
||||
}
|
||||
|
||||
class WishGood {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
@prop({ required: true })
|
||||
type: number;
|
||||
@prop({ required: true })
|
||||
@@ -77,7 +75,7 @@ export default class UserGuild extends BaseModel {
|
||||
@prop({ required: true, default: [] })
|
||||
trainRewards: Array<number>;//领取过的进阶等级
|
||||
|
||||
@prop({ required: true, default: [], type: WishGood })
|
||||
@prop({ required: true, default: [], type: WishGood, _id: false })
|
||||
wishGoods:Array<WishGood>;
|
||||
|
||||
@prop({ required: true, default: [], type: Number })
|
||||
@@ -143,7 +141,7 @@ export default class UserGuild extends BaseModel {
|
||||
}
|
||||
|
||||
public static async dismiss(guildCode: string) {
|
||||
const result = await UserGuildModel.updateMany({guildCode}, {status: USER_GUILD_STATUS.DISMISSED});
|
||||
const result = await UserGuildModel.updateMany({ guildCode }, { status: USER_GUILD_STATUS.DISMISSED });
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -161,13 +159,13 @@ export default class UserGuild extends BaseModel {
|
||||
|
||||
public static async receiveTrainRewards(roleId: string, trainId: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{$push:{trainRewards: trainId} },{new: true}).lean(lean);
|
||||
{ $push:{trainRewards: trainId} },{new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async addTrainCount(roleId: string, trainCount: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{$inc: {trainCount, buyTrainCount: trainCount}}, {new: true}).lean(lean);
|
||||
{ $inc: { trainCount, buyTrainCount: trainCount } }, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -178,11 +176,15 @@ export default class UserGuild extends BaseModel {
|
||||
|
||||
public static async donateFund(roleId: string, donateCnt: number, lean = true) {
|
||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
||||
{$inc: {donateCnt :-1*donateCnt}}, {new: true}).lean(lean);
|
||||
{$inc: { donateCnt }}, {new: true}).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async getWishPoolGoods(guildCode: string, select?: string, lean = true) {
|
||||
const userGuilds: UserGuildType[] = await UserGuildModel.find({ guildCode, status: USER_GUILD_STATUS.ON, refTimeDaily: { $gte: getTodayZeroDate() } })
|
||||
.select(select).lean(lean);
|
||||
return userGuilds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
48
shared/db/WishPoolReport.ts
Normal file
48
shared/db/WishPoolReport.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { nowSeconds, getTodayZeroPoint } from '../pubUtils/timeUtil';
|
||||
|
||||
@index({ guildCode: 1 })
|
||||
|
||||
export default class WishPoolReport extends BaseModel {
|
||||
@prop({ required: true })
|
||||
guildCode: string; // 角色 id
|
||||
|
||||
@prop({ required: true })
|
||||
dntTime: number; //捐献时间
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; //被捐献人
|
||||
|
||||
@prop({ required: true })
|
||||
roleName: string; //捐赠人
|
||||
|
||||
@prop({ required: true })
|
||||
goodId: number; //捐献物品
|
||||
|
||||
@prop({ required: true })
|
||||
count: number; //捐献物品数量
|
||||
|
||||
@prop({ required: true })
|
||||
dntRoleId: string; //捐赠人
|
||||
|
||||
@prop({ required: true })
|
||||
dntRoleName: string; //捐赠人
|
||||
|
||||
public static async addReport(guildCode: string, roleId: string, roleName: string, dntRoleId: string, dntRoleName: string, goodId: number, count: number, lean = true) {
|
||||
const doc = new WishPoolReportModel();
|
||||
const report = Object.assign(doc.toJSON(), { guildCode, roleId, roleName, dntRoleId, dntRoleName, goodId, dntTime: nowSeconds(), count });
|
||||
await WishPoolReportModel.create(report);
|
||||
return report;
|
||||
}
|
||||
//获得day天之前的许愿池战报
|
||||
public static async getReportsByTime(guildCode: string, day: number, lean = true) {
|
||||
let time = getTodayZeroPoint() - day * 24 * 60;
|
||||
const reports = await WishPoolReportModel.find({ guildCode, dntTime: {$gte: time}});
|
||||
return reports;
|
||||
}
|
||||
}
|
||||
|
||||
export const WishPoolReportModel = getModelForClass(WishPoolReport);
|
||||
|
||||
export interface WishPoolReportType extends Pick<DocumentType<WishPoolReport>, keyof WishPoolReport>{}
|
||||
Reference in New Issue
Block a user