捐献
This commit is contained in:
@@ -149,6 +149,9 @@ export const STATUS = {
|
||||
GUILD_ACTIVE_POINT_NOT_REACH: { code: 20919, simStr: '军团活跃值不足' },
|
||||
GUILD_ACTIVE_BOX_HAS_RECEIVED: { code: 20920, simStr: '该活跃宝箱已领取' },
|
||||
GUILD_WEEKLY_SUM: { code: 20921, simStr: '正在周结算中' },
|
||||
GUILD_DONATE_TIMES_NOT_ENOUGH: { code: 20922, simStr: '今日捐献的次数不够' },
|
||||
GUILD_DONATE_BOXS_IS_GOT: { code: 20923, simStr: '该捐献宝箱已领取' },
|
||||
GUILD_DONATE_BOXS_NOT_GOT: { code: 20924, simStr: '该捐献宝箱未达到领取条件' },
|
||||
|
||||
GUILD_SCRIPT_IS_OPENED_TODAY: { code: 20950, simStr: '今日演武场已开启' },
|
||||
GUILD_SCRIPT_NOT_OPENED: { code: 20951, simStr: '演武场未开启' },
|
||||
|
||||
@@ -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>{}
|
||||
@@ -47,6 +47,9 @@ export const ARMY = {
|
||||
ARMY_TRAIN_BUYTIMES: 2, // 练兵场每日可购买次数
|
||||
ARMY_TRAIN_TIMESCOST: 20, // 练兵场购买次数每日
|
||||
ARMY_WEEKHONOUR_LIMIT: 1000, // 军团成员参与职位排名周功勋下限(包含)
|
||||
ARMY_WISH_TIMES: 1, // 单个许愿池每日可许愿次数
|
||||
ARMY_WISH_HELP: 3, // 每日可满足他人心愿的次数
|
||||
ARMY_DONATE_TIMES: 10, // 捐献池每日可捐献的次数
|
||||
};
|
||||
export const TREASURE = {
|
||||
CAPTAIN_DROP: 5, // 普通套装图纸队长必掉落次数
|
||||
|
||||
@@ -80,4 +80,12 @@ export function getCurHourPoint(hour: number) {
|
||||
date.setSeconds(0);
|
||||
var time = Math.floor(date.getTime() / PER_SECOND);
|
||||
return time;
|
||||
}
|
||||
|
||||
export function getTodayZeroDate() {
|
||||
var date = new Date();
|
||||
date.setHours(0);
|
||||
date.setMinutes(0);
|
||||
date.setSeconds(0);
|
||||
return date;
|
||||
}
|
||||
Reference in New Issue
Block a user