From 4ffb494609a865613890b5798f45f06f5399d1f9 Mon Sep 17 00:00:00 2001 From: mengchengzhen <13682025901@163.com> Date: Fri, 14 May 2021 17:05:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BC=E5=8C=85=E4=BC=98=E5=8C=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ljsd/jieling/logic/dao/PlayerManager.java | 10 + .../ljsd/jieling/logic/dao/UserManager.java | 2 + .../jieling/logic/store/BuyGoodsNewLogic.java | 500 ++++++++++++++++++ .../newRechargeInfo/NewRechargeInfo.java | 139 +++++ .../store/newRechargeInfo/RechargeType.java | 19 + .../bean/AbstractWelfareBag.java | 143 +++++ .../bean/PerpetualWelfareBag.java | 32 ++ .../newRechargeInfo/bean/PushWelfareBag.java | 13 + .../bean/ReceiveWelfareBag.java | 62 +++ .../bean/TimeLimitWelfareBag.java | 37 ++ .../newRechargeInfo/bean/WelfareBag.java | 6 + .../src/main/java/config/SPackPushConfig.java | 110 ++++ .../config/SRechargeCommodityNewConfig.java | 132 +++++ 13 files changed, 1205 insertions(+) create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/BuyGoodsNewLogic.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/NewRechargeInfo.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/RechargeType.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/AbstractWelfareBag.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/PerpetualWelfareBag.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/PushWelfareBag.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/ReceiveWelfareBag.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/TimeLimitWelfareBag.java create mode 100644 serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/WelfareBag.java create mode 100644 tablemanager/src/main/java/config/SPackPushConfig.java create mode 100644 tablemanager/src/main/java/config/SRechargeCommodityNewConfig.java diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PlayerManager.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PlayerManager.java index da7859ee0..a1cc19ec8 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PlayerManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PlayerManager.java @@ -6,6 +6,7 @@ import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig; import com.ljsd.jieling.core.VipPrivilegeType; import com.ljsd.jieling.globals.Global; import com.ljsd.jieling.logic.dao.root.User; +import com.ljsd.jieling.logic.store.newRechargeInfo.NewRechargeInfo; import com.ljsd.jieling.util.MessageUtil; import config.SMonthcardConfig; import config.SPrivilegeTypeConfig; @@ -73,6 +74,7 @@ public class PlayerManager extends MongoBase { private Set reds = new CopyOnWriteArraySet<>(); private RechargeInfo rechargeInfo; + private NewRechargeInfo newRechargeInfo; private Map monthCard = new HashMap<>();//月卡信息 private Set monthCardDailyTake = new HashSet<>(); @@ -1025,4 +1027,12 @@ public class PlayerManager extends MongoBase { this.lastDeviceId = lastDeviceId; updateString("lastDeviceId",lastDeviceId); } + + public NewRechargeInfo getNewRechargeInfo() { + return newRechargeInfo; + } + + public void setNewRechargeInfo(NewRechargeInfo newRechargeInfo) { + this.newRechargeInfo = newRechargeInfo; + } } diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/UserManager.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/UserManager.java index 956c8a5c3..254735861 100644 --- a/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/UserManager.java +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/dao/UserManager.java @@ -17,6 +17,7 @@ import com.ljsd.jieling.logic.dao.root.User; import com.ljsd.jieling.logic.hero.HeroLogic; import com.ljsd.jieling.logic.mission.GameEvent; import com.ljsd.jieling.logic.player.PlayerLogic; +import com.ljsd.jieling.logic.store.newRechargeInfo.NewRechargeInfo; import com.ljsd.jieling.util.ItemUtil; import com.ljsd.jieling.util.SysUtil; import config.SGameSetting; @@ -118,6 +119,7 @@ public class UserManager { playerManager.updateVipInfo(GlobalsDef.LEVEL_UNLOCK_PRIVILEGE,1); playerManager.updateVipInfo(GlobalsDef.VIP_UNLOCK_PRIVILEGE,0); playerManager.setRechargeInfo(new RechargeInfo()); + playerManager.setNewRechargeInfo(new NewRechargeInfo()); playerManager.setPhoneBindInfo(new PhoneBindInfo("")); playerManager.setChannel(channel); playerManager.setPid(pid); diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/BuyGoodsNewLogic.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/BuyGoodsNewLogic.java new file mode 100644 index 000000000..b88adf71c --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/BuyGoodsNewLogic.java @@ -0,0 +1,500 @@ +package com.ljsd.jieling.logic.store; + +import ch.qos.logback.core.util.TimeUtil; +import com.ljsd.GameApplication; +import com.ljsd.jieling.config.reportData.DataMessageUtils; +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; +import com.ljsd.jieling.globals.BIReason; +import com.ljsd.jieling.globals.Global; +import com.ljsd.jieling.ktbeans.ReportEventEnum; +import com.ljsd.jieling.ktbeans.ReportUtil; +import com.ljsd.jieling.logic.GlobalDataManaager; +import com.ljsd.jieling.logic.OnlineUserManager; +import com.ljsd.jieling.logic.activity.ActivityLogic; +import com.ljsd.jieling.logic.activity.ActivityType; +import com.ljsd.jieling.logic.activity.event.BuyGoodsDirectEvent; +import com.ljsd.jieling.logic.activity.event.NewWelfareEvent; +import com.ljsd.jieling.logic.activity.event.NewWelfareTypeEnum; +import com.ljsd.jieling.logic.activity.event.Poster; +import com.ljsd.jieling.logic.dao.PlayerManager; +import com.ljsd.jieling.logic.dao.UserManager; +import com.ljsd.jieling.logic.dao.VipInfo; +import com.ljsd.jieling.logic.dao.root.User; +import com.ljsd.jieling.logic.expedition.ExpeditionLogic; +import com.ljsd.jieling.logic.fight.CombatLogic; +import com.ljsd.jieling.logic.mail.MailLogic; +import com.ljsd.jieling.logic.mission.GameEvent; +import com.ljsd.jieling.logic.player.PlayerLogic; +import com.ljsd.jieling.logic.store.newRechargeInfo.NewRechargeInfo; +import com.ljsd.jieling.logic.store.newRechargeInfo.RechargeType; +import com.ljsd.jieling.logic.store.newRechargeInfo.bean.*; +import com.ljsd.jieling.network.server.ProtocolsManager; +import com.ljsd.jieling.network.session.ISession; +import com.ljsd.jieling.thrift.idl.Result; +import com.ljsd.jieling.util.AynMissionWorker; +import com.ljsd.jieling.util.AyyncWorker; +import com.ljsd.jieling.util.ItemUtil; +import com.ljsd.jieling.util.MessageUtil; +import config.*; +import manager.STableManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import rpc.protocols.CommonProto; +import rpc.protocols.MessageTypeProto; +import rpc.protocols.PlayerInfoProto; +import util.MathUtils; +import util.StringUtil; +import util.TimeUtils; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 新礼包逻辑 + */ +public class BuyGoodsNewLogic { + + private static final Logger LOGGER = LoggerFactory.getLogger(BuyGoodsNewLogic.class); + + /** + * 登录刷新礼包 + */ + public void refreshWelfareState(User user){ + List pAddList = new ArrayList<>(); + List garbageList = new ArrayList<>(); + NewRechargeInfo info = user.getPlayerInfoManager().getNewRechargeInfo(); + for(Map.Entry entry : SRechargeCommodityNewConfig.configMap.entrySet()){ + Map perpetualWelfareBagMap = info.getPerpetualMap(); + if(perpetualWelfareBagMap.containsKey(entry.getKey())){ + refreshUnitWF(perpetualWelfareBagMap.get(entry.getKey()),garbageList,user); + }else{ + AbstractWelfareBag bag = initUnitWF(user,entry.getValue()); + pAddList.add(bag); + refreshUnitWF(bag,garbageList,user); + } + } + //添加新增礼包 + for(AbstractWelfareBag bag : pAddList){ + if(bag.getType() == RechargeType.perpetual.getType()){ + info.addPerpetual((PerpetualWelfareBag) bag); + }else if(bag.getType() == RechargeType.timeLimit.getType()){ + info.addTimeLimit((TimeLimitWelfareBag) bag); + }else if(bag.getType() == RechargeType.receive.getType()){ + info.addReceive((ReceiveWelfareBag)bag); + }else if(bag.getType() == RechargeType.push.getType()){ + info.addPush((PushWelfareBag)bag); + } + } + if(garbageList.size()>0){ + //添加新垃圾礼包 + info.addGarbage(garbageList); + //缓存删除垃圾礼包 + for(Integer i : garbageList){ + info.getTimeLimitMap().remove(i); + } + } + } + + /** + * 测试购买物品 + */ + public void testGoods(ISession session, String goodsId) throws Exception { + int uid = session.getUid(); + SRechargeCommodityNewConfig config = SRechargeCommodityNewConfig.getConfigById(Integer.valueOf(goodsId)); + if(config == null){ + throw new ErrorCodeException(ErrorCode.CFG_NULL); + } + int price = -999; + String openId = "gm-test"; + String orderId = "111111"; + if(!GameApplication.serverProperties.isDebug()){ + if(config.getPrice()!=0){ + throw new ErrorCodeException("In a formal setting"); + }else{ + price = 0; + openId = "free-openId"; + orderId = "free-order"; + } + } + MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.TEST_BUY_GIGT_GOODS_RESPONSE_VALUE,null,true); + sendGoods(uid, goodsId, openId, orderId,System.currentTimeMillis(), price); + } + + public static Result sendGoods(int uid, String sdkGoodsId, String openId, String orderId, long orderTime, int amount) throws Exception { + Result resultRes = new Result(); + ISession session = OnlineUserManager.getSessionByUid(uid); + LOGGER.info("send to uid={},the goods={},openID={},orderId={},orderTime={},amount={}",uid,sdkGoodsId,openId,orderId,orderTime,amount); + int goodsId = 0; + SRechargeCommodityNewConfig config ; + if(isNumeric(sdkGoodsId)){ + goodsId = Integer.parseInt(sdkGoodsId); + config =SRechargeCommodityNewConfig.configMap.get(goodsId); + }else { + config = SRechargeCommodityNewConfig.sdkconfigMap.get(sdkGoodsId); + } + + if(null == config){ + resultRes.setResultCode(0); + resultRes.setResultMsg("good config null"); + LOGGER.error("the uid={},the goodId={},good config null",uid,goodsId); + return resultRes; + } + goodsId = config.getId(); + + double priceTemp =config.getPrice(); + int cfgType = SSpecialConfig.getIntegerValue(SSpecialConfig.EXCHANGE_FORCE_TYPE); + double price = priceTemp==0?0: SExchangeRate.doubleIntegerHashMap.get(cfgType).get((int)priceTemp); + + User user = UserManager.getUser(uid); + NewRechargeInfo info = user.getPlayerInfoManager().getNewRechargeInfo(); + AbstractWelfareBag bag = null; + if(config.getOtype() == RechargeType.perpetual.getType()){ + bag = info.getPerpetualMap().get(goodsId); + }else if(config.getOtype() == RechargeType.timeLimit.getType()){ + bag = info.getTimeLimitMap().get(goodsId); + }else if(config.getOtype() == RechargeType.receive.getType()){ + bag = info.getReceiveMap().get(goodsId); + }else if(config.getOtype() == RechargeType.push.getType()){ + bag = info.getPushMap().get(goodsId); + } + String rewardStr=""; + if(bag == null || !bag.buy()){ + LOGGER.error("购买失败!bag是否为空:{}",bag == null); + return resultRes; + } + //成功购买 + if (goodsId == GlobalsDef.DAILY_GOODS_FAST_ID) { + //每日礼包一键购买之后,把所有单个的每日礼包的购买次数加一 + for (int gId : GlobalsDef.DAILY_RECHARGE_IDS) { + PerpetualWelfareBag pbag = info.getPerpetualMap().get(gId); + pbag.setBuyTimes(pbag.getBuyTimes()+1); + } + } + rewardStr = bag.sendGoods(); + sendGoodsByType(user,config,rewardStr); + if(config.getAccumulativeRecharge() == 1){ + info.setRr(MathUtils.doubleAdd(price,info.getRr())); + //处理月卡 + user.getPlayerInfoManager().getMonthCard(); + info.setMonthRr(MathUtils.doubleAdd(price,info.getMonthRr())); + info.setsMonthRr(MathUtils.doubleAdd(price,info.getsMonthRr())); + activeMonthCard(user,price,info); + //活动 + changeActivity(user,price,info); + } + if(info.getIsFirst()){ + info.setIsFirst(true); + info.setFirstTime(System.currentTimeMillis()); + } + //处理特权 + activePrivilege(user,config); + resultRes.setResultCode(1); + + notifyPaySuccessFul(uid,goodsId,amount != -999); + // Poster.getPoster().dispatchEvent(new NewWelfareEvent(user, NewWelfareTypeEnum.RECHARGE_BUY.getType(),goodsId)); + MongoUtil.getLjsdMongoTemplate().lastUpdate(); + sendGiftGooodsIndication(uid); + onChargeSuccess(user,price,0,orderId,cfgType);//充值成功上报 + Map mapReward = ItemUtil.arrayToMap(config.getBaseReward()); + if(price>0){ + MessageUtil.sendIndicationMessage(session,1, + MessageTypeProto.MessageType.RECHARGE_SUCCESS_INDICATION_VALUE, + PlayerInfoProto.RechargeSuccessIndication.newBuilder().setOrderId(orderId).build(),true); + ReportUtil.onReportEvent(user, ReportEventEnum.ORDER_COMPLETE.getType(),orderId,price, + user.getPlayerInfoManager().getBundle_id(),user.getPlayerInfoManager().getChannel_id(), + String.valueOf(GameApplication.serverId),String.valueOf(goodsId),config.getName(), + new ArrayList<>(mapReward.keySet()),new ArrayList<>(mapReward.values()),new Date(), + user.getPlayerInfoManager().getLastDeviceId()==null? + "DEFAULT_DEVICE":user.getPlayerInfoManager().getLastDeviceId()); + } + return resultRes; + } + + /** + * 通知前端充值成功 + */ + public static void notifyPaySuccessFul(int uid,int goodsId,boolean needNotify){ + if(!needNotify){ + return; + } + ISession session = OnlineUserManager.getSessionByUid(uid); + if(session!=null){ + PlayerInfoProto.NotifyPaySuccessfulIndicaiton build = PlayerInfoProto.NotifyPaySuccessfulIndicaiton.newBuilder().setGoodsId(goodsId).build(); + MessageUtil.sendIndicationMessage(session,1, MessageTypeProto.MessageType.NOTIFY_PAY_SUCCESS_INDICATION_VALUE,build,true); + } + } + + public static void sendGiftGooodsIndication(int uid) throws Exception { + List goodsBagInfo = new ArrayList<>(SRechargeCommodityConfig.rechargeCommodityConfigMap.size()); + boolean change = BuyGoodsLogic.getGoodsBagInfo(uid, goodsBagInfo,false); + ISession session = OnlineUserManager.getSessionByUid(uid); + if(session!=null && change){ + PlayerInfoProto.AllGiftGoodsIndication build = PlayerInfoProto.AllGiftGoodsIndication.newBuilder().addAllGiftGoodsInfo(goodsBagInfo).build(); + MessageUtil.sendIndicationMessage(session,1, MessageTypeProto.MessageType.ALL_GIFTGOODS_INDICATION_VALUE,build,true); + } + } + + private static void onChargeSuccess(User user,double amount,int virtualAmount,String orderId,int cfgType){ + String currency_type = "CNY"; + switch (cfgType){ + case 1: + currency_type="CNY"; + break; + case 2: + currency_type = "USD"; + break; + default:break; + + } + RechargeEvent rechargeEvent = new RechargeEvent(); + rechargeEvent.setModule("GameAnalysis"); + rechargeEvent.setIp(""); + rechargeEvent.setName("charge"); + rechargeEvent.setIndex(GameApplication.serverProperties.getAppId()==null?"APPID":GameApplication.serverProperties.getAppId()); + rechargeEvent.setIdentify(String.valueOf(user.getPlayerInfoManager().getOpenId())); + rechargeEvent.setProperties(new RechargeEventProp(orderId,amount*100,virtualAmount,currency_type,"","")); + String s = DataMessageUtils.sendRechargePost(rechargeEvent); + if(s!=null&&s.equals("1")){ + LOGGER.info("{}充值上报成功,价格为{}",user.getPlayerInfoManager().getOpenId(),amount); + } + } + + /** + * 活动变更 + */ + public static void changeActivity(User user,double price,NewRechargeInfo info){ + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.RechargeTotal,(int)(price*1000)); + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.LUCKYCAT,(int)(price*1000)); + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.DAILY_RECHARGE,(int)(price*1000)); + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.RECHARGE_NUM,(int)(price*1000)); + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.JADE_DYNASTY_RECHARGE_SUM,(int)(price*1000)); + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.RECHARGE_SUM_DAY, (int)(user.getPlayerInfoManager().getRechargedaily()*1000) ); + ActivityLogic.getInstance().updateActivityMissionProgress(user, ActivityType.FIND_FAIRY_FESTIVAL, (int)(price*1000)); + + AyyncWorker ayyncWorker = new AyyncWorker(user, true, new AynMissionWorker(GameEvent.RECHARGE_TOTAL,(int)(price*1000))) ; + + ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker); + + + ISession session = OnlineUserManager.getSessionByUid(user.getId()); + + PlayerInfoProto.RefreshRechargeIndication.Builder builder = PlayerInfoProto.RefreshRechargeIndication.newBuilder(); + builder.setAmount(info.getRr()); + builder.setMonthSaveAmt(info.getMonthRr()); + builder.setSmonthSaveAmt(info.getsMonthRr()); + MessageUtil.sendIndicationMessage(session,1, MessageTypeProto.MessageType.REFRESH_RECHARGE_INDICATION_VALUE,builder.build(),true); + } + + /** + * 处理各类型发货 + */ + public static void sendGoodsByType(User user,SRechargeCommodityNewConfig config,String rewardStr) throws Exception{ + ISession session = OnlineUserManager.getSessionByUid(user.getId()); + int type = config.getType(); + //直购礼包 + if(type == GiftGoodsType.DIRECTBAG){ + CommonProto.Drop.Builder drop = ItemUtil.drop(user, config.getBaseReward(), BIReason.DIRECT_BUY); + + if(session!=null){ + PlayerInfoProto.DirectBuyIndication build = PlayerInfoProto.DirectBuyIndication.newBuilder().setDrop(drop).build(); + MessageUtil.sendIndicationMessage(session,1, MessageTypeProto.MessageType.DIRECT_BUY_GOODS_INDICATION_VALUE,build,true); + } + + }else{ + String title = SErrorCodeEerverConfig.getI18NMessage("recharge_" + config.getType() + "_title"); + String content = SErrorCodeEerverConfig.getI18NMessage("recharge_" + config.getType() + "_txt"); + if(type== GiftGoodsType.GEM || type==GiftGoodsType.MONTHCARD || type==GiftGoodsType.LUXURYMONTHCARD){ + content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("recharge_" + config.getType() + "_txt",new Object[]{rewardStr.split("#")[1]},new int[]{0},"#"); + } + if(type==GiftGoodsType.RED_PACKET){ + //红包事件 + Poster.getPoster().dispatchEvent(new BuyGoodsDirectEvent(user.getId(),config.getId())); + title = SErrorCodeEerverConfig.getI18NMessageNeedConvert("recharge_" + config.getType() + "_title",new Object[]{config.getName()},new int[]{1},"#"); + content = SErrorCodeEerverConfig.getI18NMessageNeedConvert("recharge_" + config.getType() + "_txt",new Object[]{config.getName()},new int[]{1},"#"); + } + if(type==GiftGoodsType.SKY_TREASURE){ + user.getExpeditionManager().addScore(SSpecialConfig.getIntegerValue(SSpecialConfig.SKY_TREASURE_SCORE_INGIFT)); + user.getExpeditionManager().getWorldTreasureReward().setIsBuy(1); + Map rewardStatusMap = user.getExpeditionManager().getWorldTreasureReward().getRewardStatusMap(); + ExpeditionLogic.sendTreasureRewardUpdate(session,user.getExpeditionManager().getWorldTreasureReward().getScore(), + rewardStatusMap,user.getExpeditionManager().getWorldTreasureReward().getCreateTime(),1); + } + if(type == GiftGoodsType.SUN_LONG){ + PlayerManager playerManager = user.getPlayerInfoManager(); + playerManager.setHadBuyTreasure(1); + playerManager.setTreasureLevel(playerManager.getTreasureLevel()+15); + PlayerInfoProto.TreasureLevelUpIndication indication = PlayerInfoProto.TreasureLevelUpIndication.newBuilder() + .setHadBuy(user.getPlayerInfoManager().getHadBuyTreasure()).setLevel(user.getPlayerInfoManager().getTreasureLevel()).build(); + MessageUtil.sendIndicationMessage(OnlineUserManager.getSessionByUid(user.getId()),1,MessageTypeProto.MessageType.TREASURE_LEVELUP_INDICATION_VALUE,indication,true); + } + //发货 + if(!rewardStr.isEmpty()){ + int nowTime =(int) (TimeUtils.now()/1000); + MailLogic.getInstance().sendMail(user.getId(),title,content,rewardStr,nowTime, Global.MAIL_EFFECTIVE_TIME); + } + + } + } + + /** + * 激活月卡 + */ + public static void activeMonthCard(User user,double price,NewRechargeInfo info){ + int monthline = STableManager.getConfig(SMonthcardConfig.class).get(Global.MONTHCARDID).getPrice(); + int lmonthline = STableManager.getConfig(SMonthcardConfig.class).get(Global.LMONTHCARDID).getPrice(); + boolean sendneed =false; + if(info.getMonthRr()=monthline){ + sendneed=true; + user.getPlayerInfoManager().getMonthCard().put(Global.MONTHCARDID, (int) (System.currentTimeMillis() / 1000)); + } + if(info.getsMonthRr()=lmonthline){ + sendneed=true; + user.getPlayerInfoManager().getMonthCard().put(Global.LMONTHCARDID, (int) (System.currentTimeMillis() / 1000)); + Poster.getPoster().dispatchEvent(new NewWelfareEvent(user, NewWelfareTypeEnum.RECHARGE_BUY.getType(),Global.LMONTHCARDID)); + } + if(sendneed){ + ISession session = OnlineUserManager.sessionMap.get(user.getId()); + if(session!=null){ + PlayerInfoProto.MonthCardIndication monthCardIndication = PlayerInfoProto.MonthCardIndication.newBuilder().addAllMonthinfos(PlayerLogic.getInstance().getMonthCardInfo(user)).build(); + MessageUtil.sendIndicationMessage(session, 1, MessageTypeProto.MessageType.MONTHCARD_INDICATION_VALUE, monthCardIndication, true); + } + } + } + + /** + * 处理特权 + */ + public static void activePrivilege(User user,SRechargeCommodityNewConfig config) throws Exception{ + ISession session = OnlineUserManager.getSessionByUid(user.getId()); + int[] openPrivilege = config.getOpenPrivilege(); + if(openPrivilege!=null && openPrivilege.length>0) { + PlayerInfoProto.PrivilegeIndication.Builder indication = PlayerInfoProto.PrivilegeIndication.newBuilder(); + for (int privilege : openPrivilege) { + addNewPrivilege(user,privilege,indication); + } + MessageUtil.sendIndicationMessage(session, 1, + MessageTypeProto.MessageType.PRIVILLEGE_ADD_INDICATION_VALUE, indication.build(), true); + } + } + + public static void addNewPrivilege(User user ,int privilege,PlayerInfoProto.PrivilegeIndication.Builder indication) throws Exception { + int privilegeType = SPrivilegeTypeConfig.getsPrivilegeTypeConfigMap().get(privilege).getPrivilegeType(); + if(privilegeType == VipPrivilegeType.ADVENTURE_BASE_REWARD){ + CombatLogic.getInstance().getNewAdventureReward(user,true,(int)(TimeUtils.now()/1000)); + } + VipInfo vipInfo = user.getPlayerInfoManager().getVipInfo().get(privilege); + user.getPlayerInfoManager().addVipInfo(privilege); + indication.addInfos(CommonProto.Privilege.newBuilder().setId(privilege).setUsedTimes(vipInfo.getCount()).setEffectTime(vipInfo.getEffectTime()).build()); + } + + + /** + * 刷新单个礼包状态 + */ + public void refreshUnitWF(AbstractWelfareBag bag,List garbageList,User user){ + if(bag.isProhibited()){ + garbageList.add(bag.getModId()); + return; + } + if(bag.isOpen()){ + if(bag.getEndTime() == 0){ + //永久类型只需查看刷新时间 + if(bag.getDailyUpdate()>0 && bag.getLastBuyTime()>0 && + System.currentTimeMillis() > bag.getLastBuyTime()+bag.getDailyUpdate()* TimeUtils.DAY){ + bag.setBuyTimes(0); + } + }else{ + if(System.currentTimeMillis() > bag.getEndTime()){ + bagTimeUp(bag); + } + } + }else{ + boolean open = true; + if(System.currentTimeMillis() > bag.getStartTime()){ + if(bag.getType() != RechargeType.perpetual.getType()){ + for(String[] con : bag.getCondition()){ + if(!judgeOpen(con,user)){ + open = false; + break; + } + } + } + }else { + open = false; + } + if(open){ + bag.setOpen(true); + } + } + } + + /** + * 初始化单个礼包 + */ + public AbstractWelfareBag initUnitWF(User user,SRechargeCommodityNewConfig config){ + AbstractWelfareBag bag = null; + try{ + if(config.getOtype() == 1){ + bag = new PerpetualWelfareBag(user,config); + }else if(config.getOtype() == 2){ + bag = new TimeLimitWelfareBag(user,config); + }else if(config.getOtype() == 3){ + bag = new ReceiveWelfareBag(user,config); + }else if(config.getOtype() == 4){ + bag = new PushWelfareBag(config); + } + }catch(Exception e){ + e.printStackTrace(); + } + return bag; + } + + /** + * 礼包到时处理 + */ + public void bagTimeUp(AbstractWelfareBag bag){ + bag.setOpen((false)); + if(bag.getType() == RechargeType.timeLimit.getType() && bag.getDailyUpdate()<1){ + bag.setProhibited(true); + }else if(bag.getType() == RechargeType.receive.getType() && bag.getLastBuyTime() > 0 && + System.currentTimeMillis() < bag.getLastBuyTime() + TimeUtils.DAY * bag.getContinueDays()){ + bag.setOpen(true); + } + bag.setBuyTimes(0); + } + + /** + * 礼包开启条件判断(除了时间) + */ + public boolean judgeOpen(String[] con,User user) { + if(con[0].equals("1")){ + int level = user.getPlayerInfoManager().getLevel(); + if(Integer.parseInt(con[1]) <= level && level <= Integer.parseInt(con[2])){ + return true; + } + }else if(con[0].equals("2")){ + return GlobalDataManaager.getInstance().checkIsOpen(Integer.parseInt(con[1])); + }else if(con[0].equals("3")){ + + }else if(con[0].equals("5")){ + + } + return false; + } + + public static boolean isNumeric(String str) { + try { + new BigDecimal(str).toString(); + } catch (Exception e) { + return false;//异常 + } + return true; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/NewRechargeInfo.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/NewRechargeInfo.java new file mode 100644 index 000000000..b5c24a2d4 --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/NewRechargeInfo.java @@ -0,0 +1,139 @@ +package com.ljsd.jieling.logic.store.newRechargeInfo; + +import com.ljsd.jieling.logic.store.newRechargeInfo.bean.PerpetualWelfareBag; +import com.ljsd.jieling.logic.store.newRechargeInfo.bean.PushWelfareBag; +import com.ljsd.jieling.logic.store.newRechargeInfo.bean.ReceiveWelfareBag; +import com.ljsd.jieling.logic.store.newRechargeInfo.bean.TimeLimitWelfareBag; + +import java.util.List; +import java.util.Map; + +public class NewRechargeInfo { + + private double rr;//累计充值 + + private double monthRr ; //月卡累计总额 + private double sMonthRr ; //豪华月卡累计总额 + + private boolean isFirst;//是否首冲过 + private long firstTime;//首冲时间 + private int isDayFirst; + + private Map perpetualMap;//永久礼包 + private Map timeLimitMap;//限时刷新礼包 + private Map receiveMap;//限时刷新礼包 + private Map pushMap;//推送礼包 + private List garbage;//废弃礼包 + + public double getRr() { + return rr; + } + + public void setRr(double rr) { + this.rr = rr; + } + + public double getMonthRr() { + return monthRr; + } + + public void setMonthRr(double monthRr) { + this.monthRr = monthRr; + } + + public double getsMonthRr() { + return sMonthRr; + } + + public void setsMonthRr(double sMonthRr) { + this.sMonthRr = sMonthRr; + } + + public boolean getIsFirst() { + return isFirst; + } + + public void setIsFirst(boolean isFirst) { + this.isFirst = isFirst; + } + + public long getFirstTime() { + return firstTime; + } + + public void setFirstTime(long firstTime) { + this.firstTime = firstTime; + } + + public int getIsDayFirst() { + return isDayFirst; + } + + public void setIsDayFirst(int isDayFirst) { + this.isDayFirst = isDayFirst; + } + + public Map getPerpetualMap() { + return perpetualMap; + } + + public void setPerpetualMap(Map perpetualMap) { + this.perpetualMap = perpetualMap; + } + + public Map getTimeLimitMap() { + return timeLimitMap; + } + + public void setTimeLimitMap(Map timeLimitMap) { + this.timeLimitMap = timeLimitMap; + } + + public Map getReceiveMap() { + return receiveMap; + } + + public void setReceiveMap(Map receiveMap) { + this.receiveMap = receiveMap; + } + + public Map getPushMap() { + return pushMap; + } + + public void setPushMap(Map pushMap) { + this.pushMap = pushMap; + } + + public List getGarbage() { + return garbage; + } + + public void setGarbage(List garbage) { + this.garbage = garbage; + } + + public void addPerpetual(PerpetualWelfareBag bag){ + perpetualMap.put(bag.getModId(),bag); + } + + public void addTimeLimit(TimeLimitWelfareBag bag){ + timeLimitMap.put(bag.getModId(),bag); + } + + public void removeTimeLimit(TimeLimitWelfareBag bag){ + timeLimitMap.remove(bag.getModId()); + } + + public void addReceive(ReceiveWelfareBag bag){ + receiveMap.put(bag.getModId(),bag); + } + + public void addPush(PushWelfareBag bag){ + pushMap.put(bag.getModId(),bag); + } + + public void addGarbage(List list){ + garbage.addAll(list); + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/RechargeType.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/RechargeType.java new file mode 100644 index 000000000..04d9d35be --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/RechargeType.java @@ -0,0 +1,19 @@ +package com.ljsd.jieling.logic.store.newRechargeInfo; + +public enum RechargeType { + perpetual(1), + timeLimit(2), + receive(3), + push(4), + ; + + private int type; + + RechargeType(int type){ + this.type = type; + } + + public int getType() { + return type; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/AbstractWelfareBag.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/AbstractWelfareBag.java new file mode 100644 index 000000000..1c6ccd57a --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/AbstractWelfareBag.java @@ -0,0 +1,143 @@ +package com.ljsd.jieling.logic.store.newRechargeInfo.bean; + +import com.ljsd.jieling.logic.dao.root.User; +import com.ljsd.jieling.util.ItemUtil; +import config.SRechargeCommodityNewConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.annotation.Transient; + +public abstract class AbstractWelfareBag implements WelfareBag{ + private static final Logger LOGGER = LoggerFactory.getLogger(AbstractWelfareBag.class); + + private int roleId; + private int modId; + private int type; + private long startTime; + private long endTime; + private int limit; + private int dailyUpdate; + private int continueDays; + private boolean open; + private boolean prohibited;//禁止的礼包 + private long lastBuyTime; + private int buyTimes; + private long refreshTime; + @Transient + private String[][] condition; + + public AbstractWelfareBag(SRechargeCommodityNewConfig config){ + modId = config.getId(); + type = config.getOtype(); + limit = config.getLimit(); + condition = config.getOnSaleRule(); + dailyUpdate = config.getDailyUpdate(); + continueDays = config.getContiueDays(); + } + + @Override + public boolean buy() { + if(!open){ + LOGGER.error("礼包:{}未开启",modId); + return false; + } + if(prohibited){ + LOGGER.error("礼包:{}已被禁",modId); + return false; + } + if(buyTimes >=limit){ + LOGGER.error("礼包:{}购买次数为:{}超过限制:{}",modId,buyTimes,limit); + return false; + } + buyTimes++; + lastBuyTime = System.currentTimeMillis(); + return true; + } + + @Override + public String sendGoods() throws Exception{ + String rewardStr=""; + SRechargeCommodityNewConfig config = SRechargeCommodityNewConfig.getConfigById(modId); + int[][] baseReward = config.getBaseReward(); + int[][] firstMultiple = config.getFirstMultiple(); + int length = baseReward.length; + int[][] result ; + if(buyTimes == 1){ + length += firstMultiple.length; + result = new int[length][]; + int i=0; + for(;i0){ + setRefreshTime(getStartTime() + getDailyUpdate() * TimeUtils.DAY); + } + } + + @Override + public boolean buy() { + if(super.buy()){ + if(bought){ + LOGGER.error("礼包:{}已经购买",getModId()); + return false; + } + } + bought = true; + return true; + } + + private boolean bought ; + private int buyTimes; + + public int getBuyTimes() { + return buyTimes; + } + + public void setBuyTimes(int buyTimes) { + this.buyTimes = buyTimes; + } +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/TimeLimitWelfareBag.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/TimeLimitWelfareBag.java new file mode 100644 index 000000000..6cf541fdd --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/TimeLimitWelfareBag.java @@ -0,0 +1,37 @@ +package com.ljsd.jieling.logic.store.newRechargeInfo.bean; + +import com.ljsd.GameApplication; +import com.ljsd.jieling.logic.dao.root.User; +import config.SRechargeCommodityNewConfig; +import util.TimeUtils; + +/** + * 时限礼包 + */ +public class TimeLimitWelfareBag extends AbstractWelfareBag { + + public TimeLimitWelfareBag(User user, SRechargeCommodityNewConfig config) throws Exception{ + super(config); + for(String[] I : getCondition()){ + if(I[0].equals("4")){ + if(config.getTime() == 1){//绝对时间 + setStartTime(TimeUtils.parseTimeToMiles(I[1],TimeUtils.Stand_CeHua_Data_format)); + setEndTime(TimeUtils.parseTimeToMiles(I[2],TimeUtils.Stand_CeHua_Data_format)); + }else if(config.getTime() == 2){//创角时间 + setStartTime(user.getPlayerInfoManager().getCreateTime()+Long.parseLong(I[1])); + setEndTime(user.getPlayerInfoManager().getCreateTime()+Long.parseLong(I[2])); + }else if(config.getTime() == 3){//开服时间 + setStartTime(GameApplication.serverConfig.getCacheOpenTime()); + }else if(config.getTime() == 7){//自然周 + setStartTime(TimeUtils.getCurWeekdayStartTime(1,0)); + }else if(config.getTime() == 8){//自然月 + setStartTime(TimeUtils.getCurMonthStartTime(1)); + } + } + } + if(getDailyUpdate()>0){ + setRefreshTime(getStartTime() + getDailyUpdate() * TimeUtils.DAY); + } + } + +} diff --git a/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/WelfareBag.java b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/WelfareBag.java new file mode 100644 index 000000000..6a158934a --- /dev/null +++ b/serverlogic/src/main/java/com/ljsd/jieling/logic/store/newRechargeInfo/bean/WelfareBag.java @@ -0,0 +1,6 @@ +package com.ljsd.jieling.logic.store.newRechargeInfo.bean; + +public interface WelfareBag { + public boolean buy(); + public String sendGoods() throws Exception; +} diff --git a/tablemanager/src/main/java/config/SPackPushConfig.java b/tablemanager/src/main/java/config/SPackPushConfig.java new file mode 100644 index 000000000..5e8a725c3 --- /dev/null +++ b/tablemanager/src/main/java/config/SPackPushConfig.java @@ -0,0 +1,110 @@ +package config; + +import manager.STableManager; +import manager.Table; + +import java.util.HashMap; +import java.util.Map; + +@Table(name ="PackPush") +public class SPackPushConfig implements BaseConfig { + + private int id; + private String desc; + private int[][] conditionId; + private int priority; + private int cDTime; + private int count; + private int[] personas; + private int[] packs; + private int statistics; + + public static Map configMap; + + public void init() throws Exception { + Map config = STableManager.getConfig(SPackPushConfig.class); + Map tempConfigMap = new HashMap<>(); + for(SPackPushConfig newConfig : config.values()){ + tempConfigMap.put(newConfig.getId(),newConfig); + } + if(configMap == null){ + configMap = tempConfigMap; + } + } + + public SPackPushConfig getConfigById(int id){ + return configMap.get(id); + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public int[][] getConditionId() { + return conditionId; + } + + public void setConditionId(int[][] conditionId) { + this.conditionId = conditionId; + } + + public int getPriority() { + return priority; + } + + public void setPriority(int priority) { + this.priority = priority; + } + + public int getcDTime() { + return cDTime; + } + + public void setcDTime(int cDTime) { + this.cDTime = cDTime; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int[] getPersonas() { + return personas; + } + + public void setPersonas(int[] personas) { + this.personas = personas; + } + + public int[] getPacks() { + return packs; + } + + public void setPacks(int[] packs) { + this.packs = packs; + } + + public int getStatistics() { + return statistics; + } + + public void setStatistics(int statistics) { + this.statistics = statistics; + } +} diff --git a/tablemanager/src/main/java/config/SRechargeCommodityNewConfig.java b/tablemanager/src/main/java/config/SRechargeCommodityNewConfig.java new file mode 100644 index 000000000..b6e8b8d00 --- /dev/null +++ b/tablemanager/src/main/java/config/SRechargeCommodityNewConfig.java @@ -0,0 +1,132 @@ +package config; + +import manager.STableManager; +import manager.Table; + +import java.util.HashMap; +import java.util.Map; + +@Table(name ="RechargeCommodityNewConfig") +public class SRechargeCommodityNewConfig implements BaseConfig { + + private int id; + + private String rechargeId; + + private String name; + + private int type; + + private double price; + + private int[][] firstMultiple; + + private int[][] baseReward; + + private int[] openPrivilege; + + private int contiueDays; + + private int limit; + + private int firstInvest; + + private int accumulativeRecharge; + + private int time; + + private String[][] onSaleRule; + + private int dailyUpdate; + + private int otype; + + private String rechargeId2; + + private String rechargeId3; + +// public static Map perpetualMap;//永久礼包 +// public static Map timeLimitMap;//限时刷新礼包 +// public static Map receiveMap;//限时刷新礼包 +// public static Map pushMap;//推送礼包 + + public static Map configMap; + public static Map sdkconfigMap; + + public void init() throws Exception { + Map config = STableManager.getConfig(SRechargeCommodityNewConfig.class); +// Map tempPerpetualMap = new HashMap<>();//永久礼包 +// Map tempTimeLimitMap = new HashMap<>();//限时刷新礼包 +// Map tempReceiveMap = new HashMap<>();//限时刷新礼包 +// Map tempPushMap = new HashMap<>();//推送礼包 + Map tempConfigMap = new HashMap<>(); + Map tempSdkConfigMap = new HashMap<>(); + for(SRechargeCommodityNewConfig newConfig : config.values()){ + tempConfigMap.put(newConfig.getId(),newConfig); + tempSdkConfigMap.put(newConfig.getRechargeId(),newConfig); + tempSdkConfigMap.put(newConfig.getRechargeId2(),newConfig); + tempSdkConfigMap.put(newConfig.getRechargeId3(),newConfig); +// if(newConfig.getOtype() == 1){ +// tempPerpetualMap.put(newConfig.getId(),newConfig); +// }else if(newConfig.getOtype() == 2){ +// tempTimeLimitMap.put(newConfig.getId(),newConfig); +// }else if(newConfig.getOtype() == 3){ +// tempReceiveMap.put(newConfig.getId(),newConfig); +// }else if(newConfig.getOtype() == 4){ +// tempPushMap.put(newConfig.getId(),newConfig); +// } + } +// perpetualMap = tempPerpetualMap; +// timeLimitMap = tempTimeLimitMap; +// receiveMap = tempReceiveMap; +// pushMap = tempPushMap; + if(configMap == null){ + configMap = tempConfigMap; + sdkconfigMap = tempSdkConfigMap; + } + } + + public static SRechargeCommodityNewConfig getConfigById(int id){ + return configMap.get(id); + } + + public int getId() { return id; } + + public String getRechargeId() { return rechargeId; } + + public String getName() { return name; } + + public int getType() { + return type; + } + + public double getPrice() { return price; } + + public int[][] getFirstMultiple() { return firstMultiple; } + + public int[][] getBaseReward() { return baseReward; } + + public int[] getOpenPrivilege() { return openPrivilege; } + + public int getContiueDays() { return contiueDays; } + + public int getLimit() { return limit; } + + public int getFirstInvest() { return firstInvest; } + + public int getAccumulativeRecharge() { return accumulativeRecharge; } + + public int getTime() { return time; } + + public String[][] getOnSaleRule() { return onSaleRule; } + + public int getDailyUpdate() { return dailyUpdate; } + + public int getOtype() { return otype; } + + public String getRechargeId2() { return rechargeId2; } + + public String getRechargeId3() { return rechargeId3; } + + +}