许愿池
This commit is contained in:
@@ -29,7 +29,7 @@ export class DonationHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, donateCnt, receiveBoxs } = userGuild;
|
||||
let { donateFund, reports } = await getDonation(code, serverId);
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt });
|
||||
return resResult(STATUS.SUCCESS, { receiveBoxs, donateFund, reports, donateCnt:donateCnt||0 });
|
||||
}
|
||||
|
||||
async donate(msg: {id: number}, session: BackendSession) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { STATUS, GUILD_OPERATE } from '../../../consts';
|
||||
import { GuildRefineModel } from '../../../db/GuildRefine';
|
||||
import { getArmyDevelopConsumeById, getGoodById } from '../../../pubUtils/data';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { handleCost, addItems, checkGoods } from '../../../services/rewardService';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { findIndex, findWhere } from 'underscore';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
@@ -41,12 +41,12 @@ export class GuildRefineHandler {
|
||||
const roleId: string = session.get('roleId');
|
||||
const sid: string = session.get('sid');
|
||||
const roleName: string = session.get('roleName');
|
||||
let pieceInfo = getGoodById(pid);
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId, 'guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let { guildCode: code } = userGuild;
|
||||
let pieceInfo = getGoodById(pid);
|
||||
//判断是否有该装备或物品
|
||||
|
||||
let { scienceTrees } = await GuildRefineModel.getRefine(code);
|
||||
let findDevelopConsume;
|
||||
for (let scienceTree of scienceTrees) {
|
||||
@@ -60,7 +60,6 @@ export class GuildRefineHandler {
|
||||
}
|
||||
if (!findDevelopConsume)
|
||||
return resResult(STATUS.GUILD_NOT_REFINE_THE_EQUIP);
|
||||
|
||||
let result = await handleCost(roleId, sid, findDevelopConsume.honourConsume);
|
||||
if(!result)
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
@@ -4,14 +4,14 @@ import { GuildModel } from '../../../db/Guild';
|
||||
import { WishPoolReportModel } from '../../../db/WishPoolReport';
|
||||
import { resResult, genCode } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getArmyWishPoolBaseByLv, getGoodById } from '../../../pubUtils/data';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { CHAT_SERVER } from '../../../consts';
|
||||
import { addItems, checkGoods } from '../../../services/rewardService';
|
||||
import { IT_TYPE } from '../../../consts/constModules/itemConst';
|
||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { findIndex, findWhere } from 'underscore';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { getRedis } from '../../../services/redisService';
|
||||
export default function(app: Application) {
|
||||
return new WishPoolHandler(app);
|
||||
}
|
||||
@@ -23,18 +23,18 @@ export class WishPoolHandler {
|
||||
|
||||
async getWishPool(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'donateCnt receiveBoxs guildCode');
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'wishDntCnt wishGoods guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
|
||||
let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods');
|
||||
let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods roleId');
|
||||
let list = [];
|
||||
userGuilds.map(({ wishGoods })=>{
|
||||
userGuilds.map(({ wishGoods, roleId })=>{
|
||||
wishGoods.map(({ type, goodId, count, receiveCnt, drawCnt, id })=>{
|
||||
list.push({ type, goodId, count, receiveCnt, drawCnt, id })
|
||||
list.push({ type, goodId, count, receiveCnt, drawCnt, id, roleId })
|
||||
});
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, { list, wishDntCnt, wishGoods });
|
||||
return resResult(STATUS.SUCCESS, { list, wishDntCnt:wishDntCnt||0, wishGoods });
|
||||
}
|
||||
|
||||
// 许愿
|
||||
@@ -46,10 +46,24 @@ export class WishPoolHandler {
|
||||
let goodInfo = getGoodById(goodId)
|
||||
if (!goodInfo)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (!(goodInfo.goodType == IT_TYPE.HERO_PIECE && type == 2 ) && !(goodInfo.goodType == IT_TYPE.EQUIP_PIECE && type == 1 ))
|
||||
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;
|
||||
let result = await checkGoods(roleId, [goodId]);
|
||||
if (!result) {
|
||||
if (goodInfo.goodType == IT_TYPE.HERO_PIECE ) {
|
||||
result = await checkGoods(roleId, [goodInfo.hid]);
|
||||
if (!result)
|
||||
return resResult(STATUS.GUILD_WISH_POOL_NOT_OWN_HERO);
|
||||
} else if (goodInfo.goodType == IT_TYPE.EQUIP_PIECE ) {
|
||||
result = await checkGoods(roleId, [goodInfo.equipId]);
|
||||
if (!result)
|
||||
return resResult(STATUS.GUILD_WISH_POOL_NOT_OWN_EQUIP);
|
||||
}
|
||||
}
|
||||
const { guildCode: code, wishGoods } = userGuild;
|
||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
|
||||
let { wishGoodsEquips, wishGoodsHeros } = getArmyWishPoolBaseByLv(lv);
|
||||
@@ -58,33 +72,59 @@ export class WishPoolHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (type == 1) {
|
||||
let wishGoodsEquip = findWhere(wishGoodsEquips, { quality: goodInfo.quality});
|
||||
if (!wishGoodsEquip)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
count = wishGoodsEquip.count;
|
||||
} else {
|
||||
let wishGoodsHero = findWhere(wishGoodsHeros, { quality: goodInfo.quality});
|
||||
if (!wishGoodsHero)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
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 });
|
||||
let { wishGoods : resWishGoods } = await UserGuildModel.pushAndUpdate(roleId, {}, { wishGoods: { type, goodId, count, receiveCnt: 0, drawCnt: 0, id} }, 'wishGoods');
|
||||
return resResult(STATUS.SUCCESS, { 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 (wishRoleId == dntRoleId)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let role = await RoleModel.findByRoleId(wishRoleId);
|
||||
if (!role)
|
||||
return resResult(STATUS.WRONG_PARMS);//没有玩家
|
||||
let wishUserGuild = await getUserGuildWithRefActive(wishRoleId, ' wishDntCnt wishGoods guildCode');
|
||||
if (!wishUserGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, wishGoods } = wishUserGuild;
|
||||
const { } = await GuildModel.findGuild(code, serverId);
|
||||
let dntRoleGuild = await getUserGuildWithRefActive(dntRoleId, ' wishDntCnt wishGoods guildCode');
|
||||
if (!dntRoleGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (dntRoleGuild.guildCode != code)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
if (dntRoleGuild.wishDntCnt >= 3)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let wishGood = findWhere(wishGoods, { id });
|
||||
if (wishGood) {
|
||||
|
||||
if (!wishGood)
|
||||
return resResult(STATUS.WRONG_PARMS);//没有该许愿
|
||||
if (wishGood.receiveCnt >= wishGood.count)
|
||||
return resResult(STATUS.WRONG_PARMS);//已经收到
|
||||
let { wishDntCnt } = await UserGuildModel.donateGoods(dntRoleId, 1, 'wishDntCnt');
|
||||
let { wishGoods: resWishGoods } = await UserGuildModel.donateUpdate(wishRoleId, id, 'wishGoods');
|
||||
let key = 'login_roleId_' + wishRoleId;
|
||||
let sid = await getRedis(key);
|
||||
let goods = await addItems(wishRoleId, role.roleName , sid , [{ id : wishGood.goodId, count: 1 }]);
|
||||
if (!!sid) {
|
||||
this.app.channelService.pushMessageByUids('onWishGoodsRecive', resResult(STATUS.SUCCESS, { goods }), [{uid:wishRoleId, sid}]);
|
||||
}
|
||||
// WishPoolReportModel.addReport(code, roleId: wishRoleId, roleName: , dntRoleId, dntRoleName, goodId, 1);
|
||||
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 };
|
||||
})});
|
||||
}
|
||||
|
||||
async receiveGoods(msg: { id: string }, session: BackendSession) {
|
||||
@@ -92,7 +132,7 @@ export class WishPoolHandler {
|
||||
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');
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'wishDntCnt wishGoods guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code, wishGoods } = userGuild;
|
||||
@@ -114,7 +154,7 @@ export class WishPoolHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
const reports = await WishPoolReportModel.getReportsByTime(code, 1);
|
||||
const reports = await WishPoolReportModel.getReportsByTime(code, 1);//获得今天的捐赠日报
|
||||
return resResult(STATUS.SUCCESS, { reports });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user