支持商店下架商品

back_recharge
jiahuiwen 2021-11-03 17:46:27 +08:00
parent b24f82df04
commit bff21f989c
2 changed files with 29 additions and 24 deletions

View File

@ -176,6 +176,9 @@ public enum ErrorCode implements IErrorCode {
CROSS_YXLD_OVER(145,"赛季结算中"),
RIDING_SWARD_BET_TWO(146,"一轮比赛最多押注两次!"),
PRACTICE_LEVE_DOWN(147,"修行等级不足"),
SHOP_XIA_JIA(150,"商品已下架"),
SHOP_COLSE(151,"商店已关闭"),
SHOP_NO_ITEM(152,"商品不存在"),
GUILD_NOT_AUTHORITY(300,"账号因错误发言导致相关功能封禁中,操作失败"),
;

View File

@ -1,8 +1,6 @@
package com.ljsd.jieling.logic.store;
import com.ljsd.jieling.core.FunctionIdEnum;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
@ -21,13 +19,15 @@ import com.ljsd.jieling.logic.mission.GameEvent;
import com.ljsd.jieling.logic.player.PlayerLogic;
import com.ljsd.jieling.network.server.ProtocolsManager;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.*;
import config.SPlayerLevelConfig;
import config.SStoreConfig;
import config.SStoreTypeConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rpc.protocols.CommonProto;
import rpc.protocols.MessageTypeProto;
import rpc.protocols.PlayerInfoProto;
import com.ljsd.jieling.util.*;
import config.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import util.TimeUtils;
import java.util.*;
@ -191,7 +191,7 @@ public class StoreLogic implements IEventHandler {
PlayerInfoProto.GetStoreInfosResponse.Builder builder = PlayerInfoProto.GetStoreInfosResponse.newBuilder();
Map<Integer, StoreInfo> storeInfoMap = storeManager.getStoreInfoMap();
checkStoreRefresh(user,storeInfoMap);
List<CommonProto.StoreInfo> storeInfos = new CopyOnWriteArrayList<>();
List<CommonProto.StoreInfo> storeInfos = new ArrayList<>(storeInfoMap.size());
for (Map.Entry<Integer, StoreInfo> entry: storeInfoMap.entrySet()){
CommonProto.StoreInfo.Builder storeBuilder = getBuilder(entry.getValue());
storeInfos.add(storeBuilder.build());
@ -210,6 +210,9 @@ public class StoreLogic implements IEventHandler {
List<CommonProto.StoreItem> builderList = new CopyOnWriteArrayList<>();
for (Map.Entry<Integer, Integer> entry1: itemNumMap.entrySet()){
int itemId = entry1.getKey();
if (!SStoreConfig.getSstoreConfigMap().containsKey(itemId)) {
continue;
}
int buyNum = entry1.getValue();
CommonProto.StoreItem.Builder storeItemBuilder = CommonProto.StoreItem.newBuilder();
storeItemBuilder.setId(itemId);
@ -460,19 +463,16 @@ public class StoreLogic implements IEventHandler {
* @throws Exception
*/
public static CommonProto.Drop buyStoreItem(int uid,int storeId, int itemId,int itemNum) throws Exception {
if (itemNum < 0|| itemNum >999){
LOGGER.info("buyStoreItem==> uid={},itemNum={}",uid,itemNum);
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
}
User user = UserManager.getUser(uid);
SStoreConfig sStoreConfig = SStoreConfig.getSstoreConfigMap().get(storeId==8?itemId%100000:itemId);
String err = checkBuyGoodsAndUpdate(user,storeId, itemId,itemNum);
if (!"".equals(err)){
throw new ErrorCodeException(ErrorCode.newDefineCode(err));
}
SStoreConfig sStoreConfig = SStoreConfig.getSstoreConfigMap().get(storeId==8?itemId%100000:itemId);
int[][] goods = sStoreConfig.getGoods();
int length = goods.length;
int[][] extraAdd = sStoreConfig.getExtraAdd();
@ -532,8 +532,8 @@ public class StoreLogic implements IEventHandler {
PlayerInfoProto.PrivilegeIndication.Builder indication = PlayerInfoProto.PrivilegeIndication.newBuilder();
int[] openPrivilege = sStoreConfig.getOpenPrivilege();
for(int i=0;i<itemNum;i++){
for(int privilege:openPrivilege){
for(int i=0;i<itemNum;i++){
for(int privilege:openPrivilege){
// int privilegeType = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilege).getPrivilegeType();
// if(privilegeType== VipPrivilegeType.ADVENTURE_BASE_REWARD||privilegeType==VipPrivilegeType.FAST_MAP_LIMIT){
// CombatLogic.getInstance().getNewAdventureReward(user,true);
@ -541,32 +541,35 @@ public class StoreLogic implements IEventHandler {
// user.getPlayerInfoManager().addVipInfo(privilege);
// VipInfo vipInfo = user.getPlayerInfoManager().getVipInfo().get(privilege);
// indication.addInfos(CommonProto.Privilege.newBuilder().setId(privilege).setUsedTimes(vipInfo.getCount()).setEffectTime(vipInfo.getEffectTime()).build());
BuyGoodsNewLogic.addNewPrivilege(user,privilege,indication);
}
}
BuyGoodsNewLogic.addNewPrivilege(user,privilege,indication);
}
}
ISession sessionByUid = OnlineUserManager.getSessionByUid(uid);
MessageUtil.sendIndicationMessage(sessionByUid,1, MessageTypeProto.MessageType.PRIVILLEGE_ADD_INDICATION_VALUE,indication.build(),true);
}
return drop.build();
return drop.build();
}
public static String checkBuyGoodsAndUpdate(User user,int storeId,int itemId,int itemNum) throws Exception {
Map<Integer, StoreInfo> storeInfoMap = user.getStoreManager().getStoreInfoMap();
if (!storeInfoMap.containsKey(storeId)){
LOGGER.info("buyStoreItem==> uid={},storeId={}",user.getId(),storeId);
return "no store";
throw new ErrorCodeException(ErrorCode.SHOP_COLSE);
}
SStoreConfig sStoreConfig = SStoreConfig.getSstoreConfigMap().get(storeId == 8 ? itemId % 100000 : itemId);
if (sStoreConfig == null) {
LOGGER.info("buyStoreItem==> uid={},storeId={} item={}",user.getId(),storeId, itemId);
throw new ErrorCodeException(ErrorCode.SHOP_XIA_JIA);
}
SStoreConfig sStoreConfig = SStoreConfig.getSstoreConfigMap().get(storeId==8?itemId%100000:itemId);
StoreInfo storeInfo = storeInfoMap.get(storeId);
Map<Integer, Integer> itemNumMap =storeInfo.getItemNumMap();
if (!itemNumMap.containsKey(itemId)){
LOGGER.info("buyStoreItem==> uid={},itemId={}",user.getId(),itemId);
return "no goods";
throw new ErrorCodeException(ErrorCode.SHOP_NO_ITEM);
}
// if(storeId==Global.VIPSTORID){
// int vipLeve = user.getPlayerInfoManager().getVipLevel();
// if(vipLeve<(sStoreConfig.getSort()-1)){
@ -576,7 +579,6 @@ public class StoreLogic implements IEventHandler {
//// return "vip time limit 1";
//// }
// }
PlayerManager playerInfoManager = user.getPlayerInfoManager();
int[] buyRule = sStoreConfig.getBuyRule();
if(buyRule!=null&&buyRule.length>0){
//充值金额购买条件判断
@ -601,7 +603,7 @@ public class StoreLogic implements IEventHandler {
check = limit > buyTimes;
}
if(!check){
return "over limit";
throw new ErrorCodeException(ErrorCode.HERO_MAX);
}
}
int[][] cost = getCost(buyTimes ,itemNum, sStoreConfig.getCost(), sStoreConfig.getPremiumType(),sStoreConfig.getIsDiscount(),sStoreConfig.getDiscountDegree());
@ -630,7 +632,7 @@ public class StoreLogic implements IEventHandler {
for(;buyTimes<nums;buyTimes++){
int costNum=0;
if(premiumType == 1){
costNum = (int) (Math.ceil(Math.pow(ints[0], 3)) *buyTimes) + (int) (Math.ceil(Math.pow(ints[1], 2)) *buyTimes) +(int) (Math.ceil(Math.pow(ints[2], 1)) *buyTimes) + ints[3];
costNum = (int) (Math.ceil(Math.pow(ints[0], 3)) *buyTimes) + (int) (Math.ceil(Math.pow(ints[1], 2)) *buyTimes) +(int) (Math.ceil(Math.pow(ints[2], 1)) *buyTimes) + ints[3];
}
if (premiumType == 2){
if (buyTimes < ints.length){