捐献
This commit is contained in:
@@ -6,11 +6,11 @@ import { DonationModel } from '../../../db/Donation';
|
|||||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||||
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
||||||
import { GuildModel } from '../../../db/Guild';
|
import { GuildModel } from '../../../db/Guild';
|
||||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
|
||||||
import { findWhere } from 'underscore';
|
|
||||||
import { handleCost, addItems } from '../../../services/rewardService';
|
import { handleCost, addItems } from '../../../services/rewardService';
|
||||||
import { CHAT_SERVER } from '../../../consts';
|
import { CHAT_SERVER } from '../../../consts';
|
||||||
|
import { getDonation } from '../../../services/donateService';
|
||||||
|
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||||
|
import { ARMY } from '../../../pubUtils/dicParam';
|
||||||
export default function(app: Application) {
|
export default function(app: Application) {
|
||||||
return new DonationHandler(app);
|
return new DonationHandler(app);
|
||||||
}
|
}
|
||||||
@@ -22,11 +22,13 @@ export class DonationHandler {
|
|||||||
|
|
||||||
async getDonation(msg: {}, session: BackendSession) {
|
async getDonation(msg: {}, session: BackendSession) {
|
||||||
const roleId: string = session.get('roleId');
|
const roleId: string = session.get('roleId');
|
||||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
const serverId: number = parseInt(session.get('serverId'));
|
||||||
|
|
||||||
|
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||||
if (!userGuild)
|
if (!userGuild)
|
||||||
return resResult(STATUS.WRONG_PARMS);
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
||||||
let { donateFund, reports } = await DonationModel.getDonation(code);
|
let { donateFund, reports } = await getDonation(code, serverId);
|
||||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt });
|
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,22 +38,24 @@ export class DonationHandler {
|
|||||||
const roleName: string = session.get('roleName');
|
const roleName: string = session.get('roleName');
|
||||||
const serverId: number = parseInt(session.get('serverId'));
|
const serverId: number = parseInt(session.get('serverId'));
|
||||||
const sid: string = session.get('sid');
|
const sid: string = session.get('sid');
|
||||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||||
if (!userGuild)
|
if (!userGuild)
|
||||||
return resResult(STATUS.WRONG_PARMS);
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
const { guildCode: code, donateCnt: resdonateCnt } = userGuild;
|
const { guildCode: code, donateCnt: resdonateCnt } = userGuild;
|
||||||
if (resdonateCnt <= 0)
|
if (resdonateCnt >= ARMY.ARMY_DONATE_TIMES)
|
||||||
return resResult(STATUS.SUCCESS);
|
return resResult(STATUS.GUILD_DONATE_TIMES_NOT_ENOUGH);
|
||||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
let { donationLv } = await getDonation(code, serverId);
|
||||||
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
let { donateReward } = getArmyDonateBaseByLv(donationLv);
|
||||||
let { donateReward } = getArmyDonateBaseByLv(lv);
|
|
||||||
let { rewardGood, rewardFund, cosume } = donateReward.get(id);
|
let { rewardGood, rewardFund, cosume } = donateReward.get(id);
|
||||||
let result = await handleCost(roleId, sid, [cosume]);
|
let result = await handleCost(roleId, sid, [cosume]);
|
||||||
if(!result)
|
if(!result)
|
||||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||||
let { donateCnt } = await UserGuildModel.donateFund(roleId, 1);
|
let { donateCnt } = await UserGuildModel.donateFund(roleId, 1);
|
||||||
|
|
||||||
let { donateFund, reports } = await DonationModel.donation(code, rewardFund, { reports: {id, roleName, time: nowSeconds()}});
|
let { donateFund, reports } = await DonationModel.donation(code, rewardFund, { reports: {id, roleName, time: nowSeconds()}});
|
||||||
let goods = await addItems(roleId, roleName, sid, [rewardGood]);
|
let goods = [];
|
||||||
|
if (!!rewardGood)
|
||||||
|
goods = await addItems(roleId, roleName, sid, [rewardGood]);
|
||||||
//增加基金
|
//增加基金
|
||||||
const { fund } = await GuildModel.updateInfo(code, {}, { fund: rewardFund }, 'fund');
|
const { fund } = await GuildModel.updateInfo(code, {}, { fund: rewardFund }, 'fund');
|
||||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { fund });
|
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { fund });
|
||||||
@@ -63,20 +67,24 @@ export class DonationHandler {
|
|||||||
const roleId: string = session.get('roleId');
|
const roleId: string = session.get('roleId');
|
||||||
const roleName: string = session.get('roleName');
|
const roleName: string = session.get('roleName');
|
||||||
const sid: string = session.get('sid');
|
const sid: string = session.get('sid');
|
||||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'donateCnt receiveBoxs guildCode');
|
const serverId: number = parseInt(session.get('serverId'));
|
||||||
|
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||||
if (!userGuild)
|
if (!userGuild)
|
||||||
return resResult(STATUS.WRONG_PARMS);
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
const { guildCode: code, donateCnt: resdonateCnt, receiveBoxs: resReceiveBoxs } = userGuild;
|
const { guildCode: code, receiveBoxs: resReceiveBoxs } = userGuild;
|
||||||
if (resReceiveBoxs.indexOf(id) != -1)
|
if (resReceiveBoxs.indexOf(id) != -1)
|
||||||
return resResult(STATUS.SUCCESS);
|
return resResult(STATUS.GUILD_DONATE_BOXS_IS_GOT);
|
||||||
let { boxRewards, fund } = getArmyDonateBoxBaseById(id);
|
let { boxRewards, fund } = getArmyDonateBoxBaseById(id);
|
||||||
if (resdonateCnt <= 0)
|
let { donateFund, donationLv } = await getDonation(code, serverId);
|
||||||
return resResult(STATUS.SUCCESS);
|
let { boxRewardRatio, requireRewardRatio } = getArmyDonateBaseByLv(donationLv);
|
||||||
|
if (donateFund < fund * (100 + requireRewardRatio) )
|
||||||
|
return resResult(STATUS.GUILD_DONATE_BOXS_NOT_GOT);
|
||||||
|
boxRewards = boxRewards.map(({id, count})=>{
|
||||||
|
return { id, count: count * (boxRewardRatio + 100) };
|
||||||
|
});
|
||||||
resReceiveBoxs.push(id);
|
resReceiveBoxs.push(id);
|
||||||
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs');
|
let { receiveBoxs } = await UserGuildModel.updateInfo(roleId, { receiveBoxs: resReceiveBoxs }, {}, 'receiveBoxs');
|
||||||
let goods = await addItems(roleId, roleName, sid, boxRewards);
|
let goods = await addItems(roleId, roleName, sid, boxRewards);
|
||||||
const { fund: resFund } = await GuildModel.updateInfo(code, {}, { fund }, 'fund');
|
|
||||||
this.app.rpc.chat.guildRemote.updateInfo.toServer(CHAT_SERVER, code, { fund: resFund });
|
|
||||||
return resResult(STATUS.SUCCESS, { receiveBoxs, goods });
|
return resResult(STATUS.SUCCESS, { receiveBoxs, goods });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,8 +38,8 @@ export class GuildRefineHandler {
|
|||||||
return resResult(STATUS.SUCCESS, { scienceTrees: guildRefine.scienceTrees });
|
return resResult(STATUS.SUCCESS, { scienceTrees: guildRefine.scienceTrees });
|
||||||
}
|
}
|
||||||
|
|
||||||
async refineEquip(msg: {eid: number}, session: BackendSession) {
|
async refineEquip(msg: {pid: number}, session: BackendSession) {
|
||||||
let { eid } = msg;
|
let { pid } = msg;
|
||||||
const roleId: string = session.get('roleId');
|
const roleId: string = session.get('roleId');
|
||||||
const sid: string = session.get('sid');
|
const sid: string = session.get('sid');
|
||||||
const roleName: string = session.get('roleName');
|
const roleName: string = session.get('roleName');
|
||||||
@@ -47,13 +47,14 @@ export class GuildRefineHandler {
|
|||||||
if (!userGuild)
|
if (!userGuild)
|
||||||
return resResult(STATUS.WRONG_PARMS);
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
let { guildCode: code } = userGuild;
|
let { guildCode: code } = userGuild;
|
||||||
let equpInfo = getGoodById(eid);
|
let pieceInfo = getGoodById(pid);
|
||||||
|
//判断是否有该装备或物品
|
||||||
let { scienceTrees } = await GuildRefineModel.getRefine(code);
|
let { scienceTrees } = await GuildRefineModel.getRefine(code);
|
||||||
let findDevelopConsume;
|
let findDevelopConsume;
|
||||||
for (let scienceTree of scienceTrees) {
|
for (let scienceTree of scienceTrees) {
|
||||||
if (scienceTree.endTime < nowSeconds()) {
|
if (scienceTree.endTime < nowSeconds()) {
|
||||||
let developConsume = getArmyDevelopConsumeById(scienceTree.id);
|
let developConsume = getArmyDevelopConsumeById(scienceTree.id);
|
||||||
if (developConsume.quality && developConsume.levelMax >= equpInfo.lvLimited && equpInfo.lvLimited <= developConsume.levelMin) {
|
if (developConsume.quality && developConsume.levelMax >= pieceInfo.lvLimited && pieceInfo.lvLimited <= developConsume.levelMin) {
|
||||||
findDevelopConsume = developConsume;
|
findDevelopConsume = developConsume;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -65,7 +66,7 @@ export class GuildRefineHandler {
|
|||||||
let result = await handleCost(roleId, sid, findDevelopConsume.honourConsume);
|
let result = await handleCost(roleId, sid, findDevelopConsume.honourConsume);
|
||||||
if(!result)
|
if(!result)
|
||||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||||
let goods = await addItems(roleId, roleName, sid, [{id: eid, count: 1}]);
|
let goods = await addItems(roleId, roleName, sid, [{id: pid, count: 1}]);
|
||||||
return resResult(STATUS.SUCCESS, { goods });
|
return resResult(STATUS.SUCCESS, { goods });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { Application, BackendSession } from 'pinus';
|
||||||
|
import { UserGuildModel } from '../../../db/UserGuild';
|
||||||
|
import { GuildModel } from '../../../db/Guild';
|
||||||
|
import { resResult } from '../../../pubUtils/util';
|
||||||
|
import { STATUS } from '../../../consts';
|
||||||
|
import { DonationModel } from '../../../db/Donation';
|
||||||
|
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||||
|
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
|
||||||
|
import { handleCost, addItems } from '../../../services/rewardService';
|
||||||
|
import { CHAT_SERVER } from '../../../consts';
|
||||||
|
import { getDonation } from '../../../services/donateService';
|
||||||
|
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||||
|
import { ARMY } from '../../../pubUtils/dicParam';
|
||||||
|
export default function(app: Application) {
|
||||||
|
return new WishPoolHandler(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class WishPoolHandler {
|
||||||
|
constructor(private app: Application) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async getWishPool(msg: {}, session: BackendSession) {
|
||||||
|
const roleId: string = session.get('roleId');
|
||||||
|
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||||
|
if (!userGuild)
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
|
||||||
|
let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods');
|
||||||
|
let list = [];
|
||||||
|
userGuilds.map(({ wishGoods })=>{
|
||||||
|
wishGoods.map(({ type, goodId, count, receiveCnt, drawCnt, _id })=>{
|
||||||
|
list.push({ type, goodId, count, receiveCnt, drawCnt, id: _id })
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods });
|
||||||
|
}
|
||||||
|
|
||||||
|
async wishGoods(msg: {roleId: string, id: number}, session: BackendSession) {
|
||||||
|
const roleId: string = session.get('roleId');
|
||||||
|
const serverId: number = parseInt(session.get('serverId'));
|
||||||
|
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||||
|
if (!userGuild)
|
||||||
|
return resResult(STATUS.WRONG_PARMS);
|
||||||
|
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
|
||||||
|
const { wishPoolLv } = await GuildModel.findGuild(code, serverId);
|
||||||
|
|
||||||
|
if (wishDntCnt >= 0)
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import { DonationModel } from '../db/Donation';
|
||||||
|
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||||
|
import { GuildModel } from '../db/Guild';
|
||||||
|
import { findWhere } from 'underscore';
|
||||||
|
import { GUILD_STRUCTURE } from '../consts/constModules/guildConst';
|
||||||
|
export async function getDonation(code: string, serverId: number) {
|
||||||
|
let donation = await DonationModel.getDonation(code);
|
||||||
|
if (!donation) {
|
||||||
|
donation = await createDonation(code, serverId);
|
||||||
|
}
|
||||||
|
if (donation.refTime < nowSeconds()) {
|
||||||
|
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||||
|
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
||||||
|
donation = await DonationModel.updateDonation(code, { donateFund:0, reports:[], refTime: nowSeconds(), donationLv: lv});
|
||||||
|
}
|
||||||
|
return donation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function createDonation(code: string, serverId: number) {
|
||||||
|
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||||
|
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
||||||
|
let donation = await DonationModel.createDonation(code, lv);
|
||||||
|
return donation;
|
||||||
|
}
|
||||||
@@ -161,7 +161,7 @@ export async function addActive(roleId: string, serverId: number, id: number, ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户公会表并刷新活跃
|
* 获取用户公会表并刷新活跃和每日捐赠以及每日许愿数据
|
||||||
* @param roleId 用户id
|
* @param roleId 用户id
|
||||||
* @param select 筛选字段
|
* @param select 筛选字段
|
||||||
*/
|
*/
|
||||||
@@ -175,8 +175,8 @@ export async function getUserGuildWithRefActive(roleId: string, select: string)
|
|||||||
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
|
||||||
if(isRefDaily) {
|
if(isRefDaily) {
|
||||||
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = [];
|
receivedActive = []; refTimeDaily = now; activeDaily = 0; activeRecord = [];
|
||||||
|
let wishGoods = [], receiveBoxs = [], wishDntCnt = 0, donateCnt = 0;
|
||||||
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord }, {}, select);
|
userGuild = await UserGuildModel.updateInfo(roleId, { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods, receiveBoxs, wishDntCnt, donateCnt }, {}, select);
|
||||||
if(!userGuild) return false;
|
if(!userGuild) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ export const STATUS = {
|
|||||||
GUILD_ACTIVE_POINT_NOT_REACH: { code: 20919, simStr: '军团活跃值不足' },
|
GUILD_ACTIVE_POINT_NOT_REACH: { code: 20919, simStr: '军团活跃值不足' },
|
||||||
GUILD_ACTIVE_BOX_HAS_RECEIVED: { code: 20920, simStr: '该活跃宝箱已领取' },
|
GUILD_ACTIVE_BOX_HAS_RECEIVED: { code: 20920, simStr: '该活跃宝箱已领取' },
|
||||||
GUILD_WEEKLY_SUM: { code: 20921, 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_IS_OPENED_TODAY: { code: 20950, simStr: '今日演武场已开启' },
|
||||||
GUILD_SCRIPT_NOT_OPENED: { code: 20951, simStr: '演武场未开启' },
|
GUILD_SCRIPT_NOT_OPENED: { code: 20951, simStr: '演武场未开启' },
|
||||||
|
|||||||
+12
-3
@@ -1,5 +1,6 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
import { getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||||
|
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||||
|
|
||||||
class Report {
|
class Report {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
@@ -29,9 +30,13 @@ export default class Donation extends BaseModel {
|
|||||||
@prop({ required: true, default: 0})
|
@prop({ required: true, default: 0})
|
||||||
refTime: number;
|
refTime: number;
|
||||||
|
|
||||||
public static async createDonation(guildCode: string, lean = true) {
|
@prop({ required: true })
|
||||||
const doc = new Donation();
|
donationLv: number;
|
||||||
const result: DonationType = await DonationModel.findOneAndUpdate({ guildCode }, {$set:doc}, {upsert: true, new: true}).lean(lean);
|
|
||||||
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +50,10 @@ export default class Donation extends BaseModel {
|
|||||||
return result;
|
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);
|
export const DonationModel = getModelForClass(Donation);
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ export default class Guild extends BaseModel {
|
|||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
resetTrainTime: number;//上次刷新挑战训练场次数的时间
|
resetTrainTime: number;//上次刷新挑战训练场次数的时间
|
||||||
|
|
||||||
|
@prop({ required: true, default: 1 })
|
||||||
|
wishPoolLv: number; // 许愿池等级
|
||||||
|
|
||||||
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
||||||
const doc = new GuildModel();
|
const doc = new GuildModel();
|
||||||
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId });
|
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId });
|
||||||
|
|||||||
+11
-9
@@ -2,7 +2,7 @@ import BaseModel from './BaseModel';
|
|||||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||||
import Role, { RoleType } from './Role';
|
import Role, { RoleType } from './Role';
|
||||||
import { GUILD_AUTH, USER_GUILD_STATUS, GUILD_JOB } from '../consts';
|
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';
|
import { ARMY } from '../pubUtils/dicParam';
|
||||||
class ActiveRecord {
|
class ActiveRecord {
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
@@ -12,8 +12,6 @@ class ActiveRecord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WishGood {
|
class WishGood {
|
||||||
@prop({ required: true })
|
|
||||||
id: number;
|
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
type: number;
|
type: number;
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
@@ -77,7 +75,7 @@ export default class UserGuild extends BaseModel {
|
|||||||
@prop({ required: true, default: [] })
|
@prop({ required: true, default: [] })
|
||||||
trainRewards: Array<number>;//领取过的进阶等级
|
trainRewards: Array<number>;//领取过的进阶等级
|
||||||
|
|
||||||
@prop({ required: true, default: [], type: WishGood })
|
@prop({ required: true, default: [], type: WishGood, _id: false })
|
||||||
wishGoods:Array<WishGood>;
|
wishGoods:Array<WishGood>;
|
||||||
|
|
||||||
@prop({ required: true, default: [], type: Number })
|
@prop({ required: true, default: [], type: Number })
|
||||||
@@ -143,7 +141,7 @@ export default class UserGuild extends BaseModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async dismiss(guildCode: string) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -161,13 +159,13 @@ export default class UserGuild extends BaseModel {
|
|||||||
|
|
||||||
public static async receiveTrainRewards(roleId: string, trainId: number, lean = true) {
|
public static async receiveTrainRewards(roleId: string, trainId: number, lean = true) {
|
||||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async addTrainCount(roleId: string, trainCount: number, lean = true) {
|
public static async addTrainCount(roleId: string, trainCount: number, lean = true) {
|
||||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,11 +176,15 @@ export default class UserGuild extends BaseModel {
|
|||||||
|
|
||||||
public static async donateFund(roleId: string, donateCnt: number, lean = true) {
|
public static async donateFund(roleId: string, donateCnt: number, lean = true) {
|
||||||
const result = await UserGuildModel.findOneAndUpdate({ roleId, status: USER_GUILD_STATUS.ON},
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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_BUYTIMES: 2, // 练兵场每日可购买次数
|
||||||
ARMY_TRAIN_TIMESCOST: 20, // 练兵场购买次数每日
|
ARMY_TRAIN_TIMESCOST: 20, // 练兵场购买次数每日
|
||||||
ARMY_WEEKHONOUR_LIMIT: 1000, // 军团成员参与职位排名周功勋下限(包含)
|
ARMY_WEEKHONOUR_LIMIT: 1000, // 军团成员参与职位排名周功勋下限(包含)
|
||||||
|
ARMY_WISH_TIMES: 1, // 单个许愿池每日可许愿次数
|
||||||
|
ARMY_WISH_HELP: 3, // 每日可满足他人心愿的次数
|
||||||
|
ARMY_DONATE_TIMES: 10, // 捐献池每日可捐献的次数
|
||||||
};
|
};
|
||||||
export const TREASURE = {
|
export const TREASURE = {
|
||||||
CAPTAIN_DROP: 5, // 普通套装图纸队长必掉落次数
|
CAPTAIN_DROP: 5, // 普通套装图纸队长必掉落次数
|
||||||
|
|||||||
@@ -81,3 +81,11 @@ export function getCurHourPoint(hour: number) {
|
|||||||
var time = Math.floor(date.getTime() / PER_SECOND);
|
var time = Math.floor(date.getTime() / PER_SECOND);
|
||||||
return time;
|
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