服务器发货增加礼包数量限制判断

master_yuenan
DESKTOP-C3M45P4\dengdan 2026-06-09 16:55:40 +08:00
parent 5177a3807b
commit 73888d5add
3 changed files with 50 additions and 25 deletions

View File

@ -11,6 +11,8 @@ import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.rank.RankEnum;
import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
import com.ljsd.jieling.logic.store.newRechargeInfo.bean.AbstractWelfareBag;
import com.ljsd.jieling.logic.store.newRechargeInfo.rechargeHandler.RechargeHandler;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.ItemUtil;
import config.SRechargeCommodityNewConfig;
@ -46,6 +48,9 @@ public class MoneyBuyGiftHandler extends BaseHandler<PlayerInfoProto.GmBuyGoodRe
if (!cost){
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
if(!checkGoodStatus(user,goodsId,config)){
throw new ErrorTableException(104,"礼包已购买");
}
// 走礼包逻辑发送奖励
BuyGoodsNewLogic.moneyBuyGoods(iSession, goodsId);
int money = config.getOtherBuy1()[0][1];
@ -53,4 +58,17 @@ public class MoneyBuyGiftHandler extends BaseHandler<PlayerInfoProto.GmBuyGoodRe
Poster.getPoster().dispatchEvent(new OpenServerActivityEvent(user.getId(),money, RankEnum.MONEY_RANK.getType()));
}
/**
*
*/
private static boolean checkGoodStatus(User user, int goodId,SRechargeCommodityNewConfig config){
RechargeHandler rechargeHandler = BuyGoodsNewLogic.getRechargeHandler(config.getOtype());
AbstractWelfareBag bag = rechargeHandler.getRechargeMap(user).get(goodId);
if (bag == null){
return false;
}
// 是否可买
return bag.isBuy();
}
}

View File

@ -2,11 +2,14 @@ package com.ljsd.jieling.handler.goods;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.exception.ErrorTableException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
import com.ljsd.jieling.logic.store.newRechargeInfo.bean.AbstractWelfareBag;
import com.ljsd.jieling.logic.store.newRechargeInfo.rechargeHandler.RechargeHandler;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.ItemUtil;
import config.SRechargeCommodityNewConfig;
@ -42,6 +45,9 @@ public class VouchersBuyGiftHandler extends BaseHandler<PlayerInfoProto.GmBuyGoo
if (!cost){
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
if(!checkGoodStatus(user,goodsId,config)){
throw new ErrorTableException(104,"礼包已购买");
}
// 走礼包逻辑发送奖励
BuyGoodsNewLogic.vouchersBuyGoods(iSession, goodsId);
}
@ -49,14 +55,13 @@ public class VouchersBuyGiftHandler extends BaseHandler<PlayerInfoProto.GmBuyGoo
/**
*
*/
// private static boolean checkGoodStatus(User user, int goodId){
// SRechargeCommodityNewConfig recharge = SRechargeCommodityNewConfig.getConfigById(goodId);
// RechargeHandler rechargeHandler = BuyGoodsNewLogic.getRechargeHandler(recharge.getOtype());
// AbstractWelfareBag bag = rechargeHandler.getRechargeMap(user).get(goodId);
// if (bag == null){
// return false;
// }
// // 是否可买
// return bag.isBuy();
// }
private static boolean checkGoodStatus(User user, int goodId,SRechargeCommodityNewConfig config){
RechargeHandler rechargeHandler = BuyGoodsNewLogic.getRechargeHandler(config.getOtype());
AbstractWelfareBag bag = rechargeHandler.getRechargeMap(user).get(goodId);
if (bag == null){
return false;
}
// 是否可买
return bag.isBuy();
}
}

View File

@ -263,18 +263,6 @@ public class BuyGoodsNewLogic {
long now = TimeUtils.now();
Result resultRes = new Result();
resultRes.setResultCode(0);
ISession session = OnlineUserManager.getSessionByUid(uid);
if (session == null) {
Order order = new Order(uid, sdkGoodsId, openId, orderId, orderTime, amount);
String key = RedisKey.ANEW_RECHARGE_ORDER + ":" + uid;
RedisUtil.getInstence().putmap(key, order.getId(), order);
RedisUtil.getInstence().expireMills(key, TimeUtils.DAY * 30);
LOGGER.error("sendGoods 玩家不在缓存中,补单信息已放入redis缓存 uid={}order{}",uid, order);
resultRes.setResultCode(1);
resultRes.setResultMsg("Session is null");
return resultRes;
}
if (StringUtil.isEmpty(sdkGoodsId)){
resultRes.setResultMsg("sdkGoodsId is error");
LOGGER.error("sdkGoodsId empty, uid={}, goodId={}",uid, sdkGoodsId);
@ -313,15 +301,12 @@ public class BuyGoodsNewLogic {
return resultRes;
}
}
User user = UserManager.getUser(uid);
if (user == null) {
resultRes.setResultMsg("User not found");
LOGGER.error("sendGoods 玩家找不到, uid={}",uid);
return resultRes;
}
RechargeHandler rechargeHandler = getRechargeHandler(config.getOtype());
AbstractWelfareBag bag = rechargeHandler.getBag(user, goodsId);
if (bag == null) {
@ -329,6 +314,23 @@ public class BuyGoodsNewLogic {
LOGGER.error("sendGoods 玩家身上找不到礼包, uid={}, goodId={}",uid, goodsId);
return resultRes;
}
if(!bag.isBuy()){
resultRes.setResultMsg("bag limit");
LOGGER.error("sendGoods 礼包已购买, uid={}, goodId={}",uid, goodsId);
return resultRes;
}
ISession session = OnlineUserManager.getSessionByUid(uid);
if (session == null) {
Order order = new Order(uid, sdkGoodsId, openId, orderId, orderTime, amount);
String key = RedisKey.ANEW_RECHARGE_ORDER + ":" + uid;
RedisUtil.getInstence().putmap(key, order.getId(), order);
RedisUtil.getInstence().expireMills(key, TimeUtils.DAY * 30);
LOGGER.error("sendGoods 玩家不在缓存中,补单信息已放入redis缓存 uid={}order{}",uid, order);
resultRes.setResultCode(1);
resultRes.setResultMsg("Session is null");
return resultRes;
}
// 礼包购买
bag.buy();