捐献所
This commit is contained in:
@@ -12,6 +12,7 @@ import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { findIndex, findWhere } from 'underscore';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { getRedis } from '../../../services/redisService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
export default function(app: Application) {
|
||||
return new WishPoolHandler(app);
|
||||
}
|
||||
@@ -67,8 +68,12 @@ export class WishPoolHandler {
|
||||
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) //今日已经许愿过
|
||||
let len = 0;
|
||||
wishGoods.map(({type: resType})=>{
|
||||
if (resType == type)
|
||||
len++;
|
||||
});
|
||||
if (len >= ARMY.ARMY_WISH_TIMES) //今日已经许愿过
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (type == 1) {
|
||||
let wishGoodsEquip = findWhere(wishGoodsEquips, { quality: goodInfo.quality});
|
||||
@@ -81,9 +86,8 @@ export class WishPoolHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
count = wishGoodsHero.count;
|
||||
}
|
||||
|
||||
const id = genCode(6);
|
||||
let { wishGoods : resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, {}, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods');
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, {}, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods');
|
||||
return resResult(STATUS.SUCCESS, { wishGoods: resWishGoods });
|
||||
}
|
||||
|
||||
@@ -106,13 +110,13 @@ export class WishPoolHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (dntRoleGuild.guildCode != code)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (dntRoleGuild.wishDntCnt >= 3)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (dntRoleGuild.wishDntCnt >= ARMY.ARMY_WISH_HELP)
|
||||
return resResult(STATUS.HAS_REACH_WISH_COUNT_LIMIT);
|
||||
let wishGood = findWhere(wishGoods, { id });
|
||||
if (!wishGood)
|
||||
return resResult(STATUS.WRONG_PARMS);//没有该许愿
|
||||
if (wishGood.receiveCnt >= wishGood.count)
|
||||
return resResult(STATUS.WRONG_PARMS);//已经收到
|
||||
return resResult(STATUS.HAS_RECEIVE_WISH_GOOD);//已经收到
|
||||
let { wishDntCnt } = await UserGuildModel.donateGoods(dntRoleId, 1, 'wishDntCnt');
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.donateUpdate(wishRoleId, id, 'wishGoods');
|
||||
let key = 'login_roleId_' + wishRoleId;
|
||||
@@ -123,8 +127,9 @@ export class WishPoolHandler {
|
||||
}
|
||||
await WishPoolReportModel.addReport(code, wishRoleId, role.roleName , dntRoleId, dntRoleName, wishGood.goodId, 1);
|
||||
return resResult(STATUS.SUCCESS, { wishDntCnt, updateWishGoods: resWishGoods.map(({type, goodId, count, receiveCnt, drawCnt, id})=>{
|
||||
return { type, goodId, count, receiveCnt, drawCnt, id, roleId: wishRoleId };
|
||||
})});
|
||||
return { type, goodId, count, receiveCnt, drawCnt, id, roleId: wishRoleId };
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async receiveGoods(msg: { id: string }, session: BackendSession) {
|
||||
@@ -157,5 +162,4 @@ export class WishPoolHandler {
|
||||
const reports = await WishPoolReportModel.getReportsByTime(code, 1);//获得今天的捐赠日报
|
||||
return resResult(STATUS.SUCCESS, { reports });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user