试炼调试数据

This commit is contained in:
mamengke01
2021-02-01 14:08:45 +08:00
parent 8770fd9ea7
commit 67668097d6
16 changed files with 206 additions and 97 deletions

View File

@@ -1,16 +1,17 @@
import { Application, BackendSession } from 'pinus';
import { UserGuildModel } from '../../../db/UserGuild';
import { GuildModel } from '../../../db/Guild';
import { resResult } from '../../../pubUtils/util';
import { WishPoolReportModel } from '../../../db/WishPoolReport';
import { resResult, genCode } from '../../../pubUtils/util';
import { STATUS } from '../../../consts';
import { DonationModel } from '../../../db/Donation';
import { nowSeconds } from '../../../pubUtils/timeUtil';
import { getArmyDonateBaseByLv, getArmyDonateBoxBaseById } from '../../../pubUtils/data';
import { getArmyWishPoolBaseByLv, getGoodById } from '../../../pubUtils/data';
import { handleCost, addItems } from '../../../services/rewardService';
import { CHAT_SERVER } from '../../../consts';
import { getDonation } from '../../../services/donateService';
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
import { getUserGuildWithRefActive } from '../../../services/guildService';
import { ARMY } from '../../../pubUtils/dicParam';
import { findIndex, findWhere } from 'underscore';
export default function(app: Application) {
return new WishPoolHandler(app);
}
@@ -29,23 +30,92 @@ export class WishPoolHandler {
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 })
// });
wishGoods.map(({ type, goodId, count, receiveCnt, drawCnt, id })=>{
list.push({ type, goodId, count, receiveCnt, drawCnt, id })
});
});
return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods });
}
async wishGoods(msg: {roleId: string, id: number}, session: BackendSession) {
// 许愿
async wishGoods(msg: {goodId: number, type: number}, session: BackendSession) {
const { goodId, type } = msg;
const roleId: string = session.get('roleId');
const serverId: number = parseInt(session.get('serverId'));
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
let count;
let goodInfo = getGoodById(goodId)
if (!goodInfo)
return resResult(STATUS.WRONG_PARMS);
let userGuild = await getUserGuildWithRefActive(roleId, ' wishDntCnt wishGoods guildCode wishGoods');
if (!userGuild)
return resResult(STATUS.WRONG_PARMS);
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
const { wishPoolLv } = await GuildModel.findGuild(code, serverId);
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
let { wishGoodsEquips, wishGoodsHeros } = getArmyWishPoolBaseByLv(lv);
let len = wishGoods.length;
if (len >= 1) //今日已经许愿过
return resResult(STATUS.WRONG_PARMS);
if (type == 1) {
let wishGoodsEquip = findWhere(wishGoodsEquips, { quality: goodInfo.quality});
count = wishGoodsEquip.count;
} else {
let wishGoodsHero = findWhere(wishGoodsHeros, { quality: goodInfo.quality});
count = wishGoodsHero.count;
}
const id = genCode(6);
let { wishGoods : resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, { wishGoods }, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods');
return resResult(STATUS.SUCCESS, { wishDntCnt, wishGoods: resWishGoods });
}
// 捐赠
async donateGoods(msg: {wishRoleId: string, id: string}, session: BackendSession) {
let { wishRoleId, id } = msg;
const dntRoleId: string = session.get('roleId');
const serverId: number = parseInt(session.get('serverId'));
const dntRoleName: string = session.get('roleName');
let wishUserGuild = await getUserGuildWithRefActive(wishRoleId, ' wishDntCnt wishGoods guildCode wishGoods');
if (!wishUserGuild)
return resResult(STATUS.WRONG_PARMS);
const { guildCode: code, wishGoods } = wishUserGuild;
const { } = await GuildModel.findGuild(code, serverId);
let wishGood = findWhere(wishGoods, { id });
if (wishGood) {
}
// WishPoolReportModel.addReport(code, roleId: wishRoleId, roleName: , dntRoleId, dntRoleName, goodId, 1);
}
async receiveGoods(msg: { id: string }, session: BackendSession) {
let { id } = msg;
const roleId: string = session.get('roleId');
const roleName: string = session.get('roleName');
const sid: string = session.get('sid');
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
if (!userGuild)
return resResult(STATUS.WRONG_PARMS);
const { guildCode: code, wishGoods } = userGuild;
let index = findIndex(wishGoods, { id });
if (index == -1)
return resResult(STATUS.WRONG_PARMS);
let { drawCnt, goodId } = wishGoods[index];
if (drawCnt <= 0)
return resResult(STATUS.WRONG_PARMS);
let goods = await addItems(roleId, roleName, sid, [{ id : goodId, count: drawCnt }]);
wishGoods[index].drawCnt = 0;
await UserGuildModel.updateInfo(code, { wishGoods }, {});
return resResult(STATUS.SUCCESS, { goods, wishGoods });
}
async getReports(msg: {}, session: BackendSession) {
const roleId: string = session.get('roleId');
let userGuild = await getUserGuildWithRefActive(roleId, ' guildCode');
if (!userGuild)
return resResult(STATUS.WRONG_PARMS);
const { guildCode: code } = userGuild;
const reports = await WishPoolReportModel.getReportsByTime(code, 1);
return resResult(STATUS.SUCCESS, { reports });
}
}