Просмотр исходного кода

Merge branch 'master' of slambb_qq/FragrantTown_Server_Local into master

slambb 4 лет назад
Родитель
Сommit
35f6bdbf7f

+ 13 - 9
src/main/java/com/td/boss/game/commallseed/controller/ComMallSeedController.java

@@ -56,6 +56,7 @@ public class ComMallSeedController extends CommonController<ComMallSeedVo, ComMa
 
 
     @Autowired
     @Autowired
     private RedisLock redisLock;
     private RedisLock redisLock;
+
     /**
     /**
      * 获取商城种子
      * 获取商城种子
      *
      *
@@ -84,11 +85,14 @@ public class ComMallSeedController extends CommonController<ComMallSeedVo, ComMa
             @RequestParam(value = "payAmount") Integer payAmount,
             @RequestParam(value = "payAmount") Integer payAmount,
             @RequestParam(value = "seedId") Integer seedId
             @RequestParam(value = "seedId") Integer seedId
     ) {
     ) {
-
+        //校验如果前台输入负数
+        Map map = new HashMap();
+        if(payAmount<=0){
+            return Result.of(map, false, ResultEnum.SEED_PLAY_ERROR.getMessage(), ResultEnum.SEED_PLAY_ERROR.getCode());
+        }
         // 处理itemType,种子id ,获取种子类型,设置种子不同的数据
         // 处理itemType,种子id ,获取种子类型,设置种子不同的数据
         Integer itemType = seedId;
         Integer itemType = seedId;
         ComMallSeedVo seedVo = comMallSeedService.findById(seedId);
         ComMallSeedVo seedVo = comMallSeedService.findById(seedId);
-        Map map = new HashMap();
         if (seedVo == null) {
         if (seedVo == null) {
 
 
             map.put("msg", "非法操作:所修改的种子不存在服务器中!");
             map.put("msg", "非法操作:所修改的种子不存在服务器中!");
@@ -114,16 +118,16 @@ public class ComMallSeedController extends CommonController<ComMallSeedVo, ComMa
 
 
             //todo 操作snb数量
             //todo 操作snb数量
             ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
             ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
-            if (comUsersVo.getSnb() < payAmount) {
+            if ( comUsersVo.getSnb() < payAmount || comUsersVo.getSnb()<=0) {
                 map.put("msg", "账户snb不足");
                 map.put("msg", "账户snb不足");
                 //WALLET_SNB_INSUFFICIENT_QUANTITY(602,"snb不足以支付!")
                 //WALLET_SNB_INSUFFICIENT_QUANTITY(602,"snb不足以支付!")
                 return Result.of(map, false, ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getMessage(), ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getCode());
                 return Result.of(map, false, ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getMessage(), ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getCode());
             }
             }
             //如果数量够,写入修改对应操作
             //如果数量够,写入修改对应操作
-            Integer _oldSnb = comUsersVo.getSnb();
-            Integer _snb = comUsersVo.getSnb() - payAmount;
+            Integer _oldSnb =  comUsersVo.getSnb();
+            Integer _snb =  comUsersVo.getSnb() - payAmount;
             comUsersVo.setSnb(_snb);
             comUsersVo.setSnb(_snb);
-            comUsersService.save(comUsersVo);
+            comUsersService.save( comUsersVo);
 
 
             //合法操作记录到仓库中
             //合法操作记录到仓库中
             ComPlayerGoods entityVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, itemType, 0);
             ComPlayerGoods entityVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, itemType, 0);
@@ -166,13 +170,13 @@ public class ComMallSeedController extends CommonController<ComMallSeedVo, ComMa
             //不涉及交易的设置为0
             //不涉及交易的设置为0
             _snbTran.setTranAmountPart(0d);
             _snbTran.setTranAmountPart(0d);
             _snbTran.setTranSnbPart(0d);
             _snbTran.setTranSnbPart(0d);
-            _snbTran.setBeforeSnbPart(comUsersVo.getSnbPart());
-            _snbTran.setAfterSnbPart(comUsersVo.getSnbPart());
+            _snbTran.setBeforeSnbPart( comUsersVo.getSnbPart());
+            _snbTran.setAfterSnbPart( comUsersVo.getSnbPart());
             comSnbTranService.save(_snbTran);
             comSnbTranService.save(_snbTran);
 
 
             redisLock.unlock(_redisKey, String.valueOf(time));
             redisLock.unlock(_redisKey, String.valueOf(time));
             map.put("seed", entityVo.getGoodsIndex());
             map.put("seed", entityVo.getGoodsIndex());
-            map.put("snb",comUsersVo.getSnb());
+            map.put("snb", comUsersVo.getSnb());
             return Result.of(map);
             return Result.of(map);
         }catch (Exception e) {
         }catch (Exception e) {
             redisLock.unlock(_redisKey, String.valueOf(time));
             redisLock.unlock(_redisKey, String.valueOf(time));

+ 9 - 0
src/main/java/com/td/boss/game/complayerdog/controller/ComPlayerDogController.java

@@ -85,6 +85,10 @@ public class ComPlayerDogController extends CommonController<ComPlayerDogVo, Com
             }
             }
 
 
             ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
             ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
+            if(comUsersVo.getSnb()<=0){
+                return Result.of(map, false, ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getMessage(), ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getCode());
+            }
+
             Double _allSnb = DoubleUtil.add(comUsersVo.getSnb().doubleValue(), comUsersVo.getSnbPart());
             Double _allSnb = DoubleUtil.add(comUsersVo.getSnb().doubleValue(), comUsersVo.getSnbPart());
             //如果有snb,扣除对应的snb
             //如果有snb,扣除对应的snb
             Integer _allSnbMaxInt = (int) Math.floor(_allSnb);
             Integer _allSnbMaxInt = (int) Math.floor(_allSnb);
@@ -215,6 +219,11 @@ public class ComPlayerDogController extends CommonController<ComPlayerDogVo, Com
             }
             }
             //todo 操作snb数量
             //todo 操作snb数量
             ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
             ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
+            if(comUsersVo.getSnb()<=0){
+                redisLock.unlock(_redisKey, String.valueOf(time));
+                return Result.of(map, false, ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getMessage(), ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getCode());
+            }
+
             /**
             /**
              * todo 购买狗粮时候snb变动
              * todo 购买狗粮时候snb变动
              */
              */

+ 225 - 221
src/main/java/com/td/boss/game/complayergoods/controller/ComPlayerGoodsController.java

@@ -744,227 +744,227 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
      * @param otherUserId
      * @param otherUserId
      * @return
      * @return
      */
      */
-    @PostMapping("stealAllFruit")
-    @ResponseBody
-    @Transactional(rollbackFor = Exception.class)
-    public Result<Map> stealAllFruitFunction(
-            @RequestParam(value = "userId") String userId,
-            @RequestParam(value = "otherUserId") String otherUserId) {
-
-        Map map = new HashMap();
-
-        //获取数据库相关配置
-        ComSettingVo comSettingVo = comSettingService.get("1").getData();
-        if (comSettingVo.equals(null)) {
-            return Result.of(null, false, ResultEnum.SETTING_IS_NULL.getMessage(), ResultEnum.SETTING_IS_NULL.getCode());
-        }
-        //todo 后台可配置,获取一个链上数据
-        Integer _configStrength = comSettingVo.getMaxStrength(), _chainStrength = DappUtil.getChildrenCount(userId);
-        //前端的显示,输出一个不小于0的体力值
-        Integer _maxStrength = _configStrength + _chainStrength;
-        //1.先判断用户是否有足够的体力,根据snb判断。2. 收取到果实,扣除用户一个体力值
-        ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
-        ComPlayersAttriVo playersAttribute = comPlayersAttriService.findByUserId(userId);
-        Integer _out = _maxStrength - Math.abs(playersAttribute.getStrength());
-        if (comUsersVo.getSnb() < comSettingVo.getDeductSnb()) {
-            //判断是否有双倍体力
-            if (_out < comSettingVo.getSnbUnitStrength()) {
-                map.put("msg", "需要双倍体力:" + comSettingVo.getSnbUnitStrength());
-                return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
-            }
-        } else {
-            //正常判断体力
-            if (_out < comSettingVo.getUnitStrength()) {
-                map.put("msg", "需要单倍体力:" + comSettingVo.getUnitStrength());
-                return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
-            }
-        }
-
-        List<Map> _stealLandInfos = new ArrayList<>();
-        Double _finalStealAmountSum = 0d;
-        //todo 偷取用户的对象信息等id
-        List<ComPlayerLandAndCanSteal> otherPlayerLandAndCanSteal = comPlayerLandService.findCanStealByUserIdAndOtherUserId(userId, otherUserId);
-        //List<ComPlayerLand> otherPlayerLands = comPlayerLandService.findAllByCanStealOtherLands(userId, otherUserId);
-        List<ComPlayerLand> otherPlayerLands = new ArrayList<>();
-        for (int i = 0; i < otherPlayerLandAndCanSteal.size(); i++) {
-            if (otherPlayerLandAndCanSteal.get(i).getCanSteal().equals(1)) {
-                otherPlayerLands.add(CopyUtil.copy(otherPlayerLandAndCanSteal.get(i), ComPlayerLand.class));
-            }
-        }
-        if (otherPlayerLands.size() == 0) {
-            return Result.of(null, false, ResultEnum.LAND_CAN_STEAL_IS_ZERO.getMessage(), ResultEnum.LAND_CAN_STEAL_IS_ZERO.getCode());
-        }
-
-        for (int i = 0; i < otherPlayerLands.size(); i++) {
-            ComPlayerLand otherPlayerLand = otherPlayerLands.get(i);
-            //获取当前种植的种子
-            ComMallSeedVo comMallSeedVo = comMallSeedService.findById(otherPlayerLand.getPlantId());
-            //需要redis 加锁
-            long time = System.currentTimeMillis() + RedisData.getPlayerGoodsTimeout();
-            //获取用户的plantFlag,因为之前的用户没有设置这个flag,所以设为第一次,用 userId 和 landId 组合成key
-            String _redisKey = otherPlayerLand.getPlantFlag();
-            if (!StringUtils.hasText(_redisKey)) {
-                //return Result.of(null, false, ResultEnum.LAND_PLANT_FLAG_IS_NULL.getMessage(), ResultEnum.LAND_PLANT_FLAG_IS_NULL.getCode());
-                _redisKey = otherPlayerLand.getUserId() + "or" + otherPlayerLand.getConfigLandId();
-            }
-            try {
-                if (!redisLock.lock(_redisKey, String.valueOf(time))) {
-                    //如果有冲突锁,跳过
-                    continue;
-                }
-                //todo 如果当前人员偷窃水果。记录一个信息,存储当前玩家已偷过的水果的信息
-                //计算一个偷取的收获量, 租赁倍数* 租赁日期下的产量
-                Integer _otherAmount = 0;
-                if (otherPlayerLand.getLeaseDate().equals(1)) {
-                    _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
-                } else if (otherPlayerLand.getLeaseDate().equals(2)) {
-                    _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
-                } else if (otherPlayerLand.getLeaseDate().equals(3)) {
-                    _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
-                }
-                //todo 拿出计算利润,收获量减去种子的成本(snb)后的百分之30 ,后面需要后台可调整
-                Integer _profit = _otherAmount - otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
-                // 配置的参数。这里先直接定义
-                Double profitConfig = comSettingVo.getProfit(), stealRatioMaxConfig = comSettingVo.getStealMaxRatio(), stealRatioMinConfig = comSettingVo.getStealMinRatio(), finallyGetRatioConfig = comSettingVo.getFinalRatio();
-                Double _stealRatio = new Random().nextDouble() * DoubleUtil.sub(stealRatioMaxConfig, stealRatioMinConfig) + stealRatioMinConfig;// 1%-3%
-                //todo 被偷取的人扣除 一个损失量,初利润算 _profit
-                Double _stolenAmount = DoubleUtil.mul(_profit.doubleValue(), _stealRatio);
-                //这里根据plantFlag判断目标用户当前种植被偷取完,看下是否需要处理更新前端信息,暂不处理
-                Double _sumStolen = comPlayerProfitService.getStolenSumByOtherUserIdAndPlantFlag(otherUserId, _redisKey);
-                //todo 这里的可偷利润应该是最大值,用户不能超过这个,需要限制判断
-                Double _maxAmount = DoubleUtil.mul(_profit.doubleValue(), profitConfig); //可偷取的利润
-                //1 一键 就是 _sumStolen>_maxAmount 或者 _sumStolen == _maxAmount ,被偷完了
-                if (!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1)) {
-                    // 需要redis 解锁
-                    redisLock.unlock(_redisKey, String.valueOf(time));
-                    //记录一个不可偷取的状态
-                    otherPlayerLand.setPlantSteal(0);
-                    comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
-                    continue;
-                }
-                //计算剩下可偷利润的差,防止过多偷取用户利润 _stolenAmount
-                Double _diff = Math.abs(DoubleUtil.sub(_maxAmount, _sumStolen));
-                if (DoubleUtil.compare(_stolenAmount, _diff).equals(1)) {
-                    //_stolenAmount>_diff
-                    _stolenAmount = _diff;
-                }
-                //最终偷窃人获取的是偷取的是目标用户损失量的10% finallyGetRatioConfig
-                Double _finalStealAmount = DoubleUtil.mul(_stolenAmount, finallyGetRatioConfig);
-                //偷窃后,系统回收部分
-                Double _lostStealAmount = DoubleUtil.sub(1d, finallyGetRatioConfig) * _stolenAmount;
-                //果实 Type =1
-                //todo 增加一个字段处理背包果实,拿出当前用户背包果实
-                ComPlayerGoods comPlayerGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
-                Double _beforeStealAmount = 0.0;
-                if (comPlayerGoods == null) {
-                    //背包增加收取到别的用户对应的类型数量。比如当前是偷取到的果实
-                    comPlayerGoods = new ComPlayerGoods();
-                    comPlayerGoods.setUserId(userId);
-                    comPlayerGoods.setGoodsIndex(comMallSeedVo.getHarvestId());
-                    comPlayerGoods.setGoodsType(1);
-                    comPlayerGoods.setName(comMallSeedVo.getHarvestName());
-                    //用种子的picture
-                    comPlayerGoods.setPictureName(comMallSeedVo.getPicture());
-                    //amount 设置0
-                    comPlayerGoods.setAmount(0);
-                    comPlayerGoods.setAmountPart(_finalStealAmount);
-                    _beforeStealAmount = 0.0;
-                } else {
-                    _beforeStealAmount = comPlayerGoods.getAmountPart();
-                    //修改偷取字段
-                    comPlayerGoods.setAmountPart(DoubleUtil.add(comPlayerGoods.getAmountPart(), _finalStealAmount));
-                }
-                ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoods, ComPlayerGoodsVo.class);
-                comPlayerGoodsService.save(comPlayerGoodsVo);
-
-                //todo 偷窃损失,处理目标用户收取果实时候,减扣一部分被偷取的数量
-                ComPlayerProfit comPlayerProfit = new ComPlayerProfit();
-                comPlayerProfit.setUserId(userId);
-                comPlayerProfit.setTargetId(otherUserId);
-                comPlayerProfit.setPlantFlag(_redisKey);
-                comPlayerProfit.setLandId(otherPlayerLand.getConfigLandId());
-                comPlayerProfit.setLeaseMultiple(otherPlayerLand.getLeaseMultiple());
-                comPlayerProfit.setLeaseDate(otherPlayerLand.getLeaseDate());
-                comPlayerProfit.setHarvest(_otherAmount);
-                comPlayerProfit.setProfit(_profit.doubleValue());//目标用户可偷的初始利润值
-                comPlayerProfit.setStolen(_stolenAmount);//目标用户被偷的数量
-                comPlayerProfit.setFinalSteal(_finalStealAmount);//用户最终偷取的量,是被偷的数量 10%左右
-                comPlayerProfit.setProfitAfter(DoubleUtil.sub(_profit.doubleValue(), DoubleUtil.add(_stolenAmount, _sumStolen))); //可偷的减去被偷的
-                //记录相关比例
-                comPlayerProfit.setProfitRatio(profitConfig);
-                comPlayerProfit.setStealRatio(_stealRatio);
-                comPlayerProfit.setFinalRatio(finallyGetRatioConfig);
-                ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
-                comPlayerProfitService.save(comPlayerProfitVo);
-
-                //todo 记录一个收获的操作日志,这里由于偷取果实是有小数点的,小数点处理成整数,单位 暂定5位 100000
-                //      这里的数量都与偷窃知道相关。amountPart,注意不是果实实际总数 amount
-                ComPlayerLog _playerLog = new ComPlayerLog();
-                _playerLog.setUserId(userId);
-                _playerLog.setTId(comMallSeedVo.getHarvestId());
-                _playerLog.setTName(comMallSeedVo.getHarvestName());
-                _playerLog.setTType(6);//偷取果实时候,type设置6
-                //偷水果时候这部分数据应该是不变的
-                _playerLog.setTAmount(0);
-                _playerLog.setBeforeAmount(comPlayerGoods.getAmount());
-                _playerLog.setAfterAmount(comPlayerGoods.getAmount());
-                //偷取用户果实时候,收取时候信息记录
-                _playerLog.setBeforePart(_beforeStealAmount);
-                _playerLog.setTPart(_finalStealAmount);
-                _playerLog.setTLoss(_lostStealAmount); //损失的部分
-                _playerLog.setAfterPart(comPlayerGoods.getAmountPart());
-                _playerLog.setLMultiple(otherPlayerLand.getLeaseMultiple());
-                ComPlayerLogVo _playerLogVo = CopyUtil.copy(_playerLog, ComPlayerLogVo.class);
-                comPlayerLogService.save(_playerLogVo);
-
-                //todo 成功收取记录一个土地id
-                Map _landMap = new HashMap();
-                //记录一个id
-                _landMap.put("landId", otherPlayerLand.getConfigLandId());
-                //
-                _landMap.put("stealAmount", _finalStealAmount);
-
-                //固定成本
-                _landMap.put("cost", otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb());
-                //当前利润
-                _landMap.put("profit", _profit);
-                //打印一个比例
-                _landMap.put("profitRatio", profitConfig);
-                _landMap.put("intervalStealRatio", _stealRatio);
-                _landMap.put("finallyGetRatioConfig", finallyGetRatioConfig);
-
-                _finalStealAmountSum = DoubleUtil.add(_finalStealAmount, _finalStealAmountSum);
-                _stealLandInfos.add(_landMap);
-                // 需要redis 解锁
-                redisLock.unlock(_redisKey, String.valueOf(time));
-            } catch (Exception e) {
-                // 需要redis 解锁
-                redisLock.unlock(_redisKey, String.valueOf(time));
-                throw new RuntimeException(e.getMessage());
-            }
-        }
-
-        map.put("msg", "偷取果实.");
-        map.put("steals", _stealLandInfos);
-        map.put("stealSum", _finalStealAmountSum);
-
-        if (_stealLandInfos.size() > 0) {
-            //todo 体力值可以后台配置
-            Integer _addStrength = comUsersVo.getSnb() < comSettingVo.getDeductSnb() ? comSettingVo.getSnbUnitStrength() : comSettingVo.getUnitStrength();
-            playersAttribute.setStrength(playersAttribute.getStrength() + _addStrength);
-            comPlayersAttriService.save(playersAttribute);
-            ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttribute, ComPlayersAttriSimpleVo.class);
-            //前端的显示,输出一个不小于0的体力值
-            Integer _outEnd = _maxStrength - Math.abs(playersAttribute.getStrength());
-            comPlayersAttriSimpleVo.setCurrentStrength(_outEnd < 0 ? 0 : _outEnd);
-            //最大值是配置的值和链上数据的值相加
-            comPlayersAttriSimpleVo.setMaxStrength(_maxStrength);
-
-            map.put("playerAttribute", comPlayersAttriSimpleVo);
-        }
-
-        return Result.of(map);
-    }
+//    @PostMapping("stealAllFruit")
+//    @ResponseBody
+//    @Transactional(rollbackFor = Exception.class)
+//    public Result<Map> stealAllFruitFunction(
+//            @RequestParam(value = "userId") String userId,
+//            @RequestParam(value = "otherUserId") String otherUserId) {
+//
+//        Map map = new HashMap();
+//
+//        //获取数据库相关配置
+//        ComSettingVo comSettingVo = comSettingService.get("1").getData();
+//        if (comSettingVo.equals(null)) {
+//            return Result.of(null, false, ResultEnum.SETTING_IS_NULL.getMessage(), ResultEnum.SETTING_IS_NULL.getCode());
+//        }
+//        //todo 后台可配置,获取一个链上数据
+//        Integer _configStrength = comSettingVo.getMaxStrength(), _chainStrength = DappUtil.getChildrenCount(userId);
+//        //前端的显示,输出一个不小于0的体力值
+//        Integer _maxStrength = _configStrength + _chainStrength;
+//        //1.先判断用户是否有足够的体力,根据snb判断。2. 收取到果实,扣除用户一个体力值
+//        ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
+//        ComPlayersAttriVo playersAttribute = comPlayersAttriService.findByUserId(userId);
+//        Integer _out = _maxStrength - Math.abs(playersAttribute.getStrength());
+//        if (comUsersVo.getSnb() < comSettingVo.getDeductSnb()) {
+//            //判断是否有双倍体力
+//            if (_out < comSettingVo.getSnbUnitStrength()) {
+//                map.put("msg", "需要双倍体力:" + comSettingVo.getSnbUnitStrength());
+//                return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
+//            }
+//        } else {
+//            //正常判断体力
+//            if (_out < comSettingVo.getUnitStrength()) {
+//                map.put("msg", "需要单倍体力:" + comSettingVo.getUnitStrength());
+//                return Result.of(map, false, ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getMessage(), ResultEnum.PLAYER_ATTRIBUTE_STRENGTH_IS_NOT.getCode());
+//            }
+//        }
+//
+//        List<Map> _stealLandInfos = new ArrayList<>();
+//        Double _finalStealAmountSum = 0d;
+//        //todo 偷取用户的对象信息等id
+//        List<ComPlayerLandAndCanSteal> otherPlayerLandAndCanSteal = comPlayerLandService.findCanStealByUserIdAndOtherUserId(userId, otherUserId);
+//        //List<ComPlayerLand> otherPlayerLands = comPlayerLandService.findAllByCanStealOtherLands(userId, otherUserId);
+//        List<ComPlayerLand> otherPlayerLands = new ArrayList<>();
+//        for (int i = 0; i < otherPlayerLandAndCanSteal.size(); i++) {
+//            if (otherPlayerLandAndCanSteal.get(i).getCanSteal().equals(1)) {
+//                otherPlayerLands.add(CopyUtil.copy(otherPlayerLandAndCanSteal.get(i), ComPlayerLand.class));
+//            }
+//        }
+//        if (otherPlayerLands.size() == 0) {
+//            return Result.of(null, false, ResultEnum.LAND_CAN_STEAL_IS_ZERO.getMessage(), ResultEnum.LAND_CAN_STEAL_IS_ZERO.getCode());
+//        }
+//
+//        for (int i = 0; i < otherPlayerLands.size(); i++) {
+//            ComPlayerLand otherPlayerLand = otherPlayerLands.get(i);
+//            //获取当前种植的种子
+//            ComMallSeedVo comMallSeedVo = comMallSeedService.findById(otherPlayerLand.getPlantId());
+//            //需要redis 加锁
+//            long time = System.currentTimeMillis() + RedisData.getPlayerGoodsTimeout();
+//            //获取用户的plantFlag,因为之前的用户没有设置这个flag,所以设为第一次,用 userId 和 landId 组合成key
+//            String _redisKey = otherPlayerLand.getPlantFlag();
+//            if (!StringUtils.hasText(_redisKey)) {
+//                //return Result.of(null, false, ResultEnum.LAND_PLANT_FLAG_IS_NULL.getMessage(), ResultEnum.LAND_PLANT_FLAG_IS_NULL.getCode());
+//                _redisKey = otherPlayerLand.getUserId() + "or" + otherPlayerLand.getConfigLandId();
+//            }
+//            try {
+//                if (!redisLock.lock(_redisKey, String.valueOf(time))) {
+//                    //如果有冲突锁,跳过
+//                    continue;
+//                }
+//                //todo 如果当前人员偷窃水果。记录一个信息,存储当前玩家已偷过的水果的信息
+//                //计算一个偷取的收获量, 租赁倍数* 租赁日期下的产量
+//                Integer _otherAmount = 0;
+//                if (otherPlayerLand.getLeaseDate().equals(1)) {
+//                    _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
+//                } else if (otherPlayerLand.getLeaseDate().equals(2)) {
+//                    _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
+//                } else if (otherPlayerLand.getLeaseDate().equals(3)) {
+//                    _otherAmount = otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
+//                }
+//                //todo 拿出计算利润,收获量减去种子的成本(snb)后的百分之30 ,后面需要后台可调整
+//                Integer _profit = _otherAmount - otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
+//                // 配置的参数。这里先直接定义
+//                Double profitConfig = comSettingVo.getProfit(), stealRatioMaxConfig = comSettingVo.getStealMaxRatio(), stealRatioMinConfig = comSettingVo.getStealMinRatio(), finallyGetRatioConfig = comSettingVo.getFinalRatio();
+//                Double _stealRatio = new Random().nextDouble() * DoubleUtil.sub(stealRatioMaxConfig, stealRatioMinConfig) + stealRatioMinConfig;// 1%-3%
+//                //todo 被偷取的人扣除 一个损失量,初利润算 _profit
+//                Double _stolenAmount = DoubleUtil.mul(_profit.doubleValue(), _stealRatio);
+//                //这里根据plantFlag判断目标用户当前种植被偷取完,看下是否需要处理更新前端信息,暂不处理
+//                Double _sumStolen = comPlayerProfitService.getStolenSumByOtherUserIdAndPlantFlag(otherUserId, _redisKey);
+//                //todo 这里的可偷利润应该是最大值,用户不能超过这个,需要限制判断
+//                Double _maxAmount = DoubleUtil.mul(_profit.doubleValue(), profitConfig); //可偷取的利润
+//                //1 一键 就是 _sumStolen>_maxAmount 或者 _sumStolen == _maxAmount ,被偷完了
+//                if (!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1)) {
+//                    // 需要redis 解锁
+//                    redisLock.unlock(_redisKey, String.valueOf(time));
+//                    //记录一个不可偷取的状态
+//                    otherPlayerLand.setPlantSteal(0);
+//                    comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
+//                    continue;
+//                }
+//                //计算剩下可偷利润的差,防止过多偷取用户利润 _stolenAmount
+//                Double _diff = Math.abs(DoubleUtil.sub(_maxAmount, _sumStolen));
+//                if (DoubleUtil.compare(_stolenAmount, _diff).equals(1)) {
+//                    //_stolenAmount>_diff
+//                    _stolenAmount = _diff;
+//                }
+//                //最终偷窃人获取的是偷取的是目标用户损失量的10% finallyGetRatioConfig
+//                Double _finalStealAmount = DoubleUtil.mul(_stolenAmount, finallyGetRatioConfig);
+//                //偷窃后,系统回收部分
+//                Double _lostStealAmount = DoubleUtil.sub(1d, finallyGetRatioConfig) * _stolenAmount;
+//                //果实 Type =1
+//                //todo 增加一个字段处理背包果实,拿出当前用户背包果实
+//                ComPlayerGoods comPlayerGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
+//                Double _beforeStealAmount = 0.0;
+//                if (comPlayerGoods == null) {
+//                    //背包增加收取到别的用户对应的类型数量。比如当前是偷取到的果实
+//                    comPlayerGoods = new ComPlayerGoods();
+//                    comPlayerGoods.setUserId(userId);
+//                    comPlayerGoods.setGoodsIndex(comMallSeedVo.getHarvestId());
+//                    comPlayerGoods.setGoodsType(1);
+//                    comPlayerGoods.setName(comMallSeedVo.getHarvestName());
+//                    //用种子的picture
+//                    comPlayerGoods.setPictureName(comMallSeedVo.getPicture());
+//                    //amount 设置0
+//                    comPlayerGoods.setAmount(0);
+//                    comPlayerGoods.setAmountPart(_finalStealAmount);
+//                    _beforeStealAmount = 0.0;
+//                } else {
+//                    _beforeStealAmount = comPlayerGoods.getAmountPart();
+//                    //修改偷取字段
+//                    comPlayerGoods.setAmountPart(DoubleUtil.add(comPlayerGoods.getAmountPart(), _finalStealAmount));
+//                }
+//                ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoods, ComPlayerGoodsVo.class);
+//                comPlayerGoodsService.save(comPlayerGoodsVo);
+//
+//                //todo 偷窃损失,处理目标用户收取果实时候,减扣一部分被偷取的数量
+//                ComPlayerProfit comPlayerProfit = new ComPlayerProfit();
+//                comPlayerProfit.setUserId(userId);
+//                comPlayerProfit.setTargetId(otherUserId);
+//                comPlayerProfit.setPlantFlag(_redisKey);
+//                comPlayerProfit.setLandId(otherPlayerLand.getConfigLandId());
+//                comPlayerProfit.setLeaseMultiple(otherPlayerLand.getLeaseMultiple());
+//                comPlayerProfit.setLeaseDate(otherPlayerLand.getLeaseDate());
+//                comPlayerProfit.setHarvest(_otherAmount);
+//                comPlayerProfit.setProfit(_profit.doubleValue());//目标用户可偷的初始利润值
+//                comPlayerProfit.setStolen(_stolenAmount);//目标用户被偷的数量
+//                comPlayerProfit.setFinalSteal(_finalStealAmount);//用户最终偷取的量,是被偷的数量 10%左右
+//                comPlayerProfit.setProfitAfter(DoubleUtil.sub(_profit.doubleValue(), DoubleUtil.add(_stolenAmount, _sumStolen))); //可偷的减去被偷的
+//                //记录相关比例
+//                comPlayerProfit.setProfitRatio(profitConfig);
+//                comPlayerProfit.setStealRatio(_stealRatio);
+//                comPlayerProfit.setFinalRatio(finallyGetRatioConfig);
+//                ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
+//                comPlayerProfitService.save(comPlayerProfitVo);
+//
+//                //todo 记录一个收获的操作日志,这里由于偷取果实是有小数点的,小数点处理成整数,单位 暂定5位 100000
+//                //      这里的数量都与偷窃知道相关。amountPart,注意不是果实实际总数 amount
+//                ComPlayerLog _playerLog = new ComPlayerLog();
+//                _playerLog.setUserId(userId);
+//                _playerLog.setTId(comMallSeedVo.getHarvestId());
+//                _playerLog.setTName(comMallSeedVo.getHarvestName());
+//                _playerLog.setTType(6);//偷取果实时候,type设置6
+//                //偷水果时候这部分数据应该是不变的
+//                _playerLog.setTAmount(0);
+//                _playerLog.setBeforeAmount(comPlayerGoods.getAmount());
+//                _playerLog.setAfterAmount(comPlayerGoods.getAmount());
+//                //偷取用户果实时候,收取时候信息记录
+//                _playerLog.setBeforePart(_beforeStealAmount);
+//                _playerLog.setTPart(_finalStealAmount);
+//                _playerLog.setTLoss(_lostStealAmount); //损失的部分
+//                _playerLog.setAfterPart(comPlayerGoods.getAmountPart());
+//                _playerLog.setLMultiple(otherPlayerLand.getLeaseMultiple());
+//                ComPlayerLogVo _playerLogVo = CopyUtil.copy(_playerLog, ComPlayerLogVo.class);
+//                comPlayerLogService.save(_playerLogVo);
+//
+//                //todo 成功收取记录一个土地id
+//                Map _landMap = new HashMap();
+//                //记录一个id
+//                _landMap.put("landId", otherPlayerLand.getConfigLandId());
+//                //
+//                _landMap.put("stealAmount", _finalStealAmount);
+//
+//                //固定成本
+//                _landMap.put("cost", otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb());
+//                //当前利润
+//                _landMap.put("profit", _profit);
+//                //打印一个比例
+//                _landMap.put("profitRatio", profitConfig);
+//                _landMap.put("intervalStealRatio", _stealRatio);
+//                _landMap.put("finallyGetRatioConfig", finallyGetRatioConfig);
+//
+//                _finalStealAmountSum = DoubleUtil.add(_finalStealAmount, _finalStealAmountSum);
+//                _stealLandInfos.add(_landMap);
+//                // 需要redis 解锁
+//                redisLock.unlock(_redisKey, String.valueOf(time));
+//            } catch (Exception e) {
+//                // 需要redis 解锁
+//                redisLock.unlock(_redisKey, String.valueOf(time));
+//                throw new RuntimeException(e.getMessage());
+//            }
+//        }
+//
+//        map.put("msg", "偷取果实.");
+//        map.put("steals", _stealLandInfos);
+//        map.put("stealSum", _finalStealAmountSum);
+//
+//        if (_stealLandInfos.size() > 0) {
+//            //todo 体力值可以后台配置
+//            Integer _addStrength = comUsersVo.getSnb() < comSettingVo.getDeductSnb() ? comSettingVo.getSnbUnitStrength() : comSettingVo.getUnitStrength();
+//            playersAttribute.setStrength(playersAttribute.getStrength() + _addStrength);
+//            comPlayersAttriService.save(playersAttribute);
+//            ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttribute, ComPlayersAttriSimpleVo.class);
+//            //前端的显示,输出一个不小于0的体力值
+//            Integer _outEnd = _maxStrength - Math.abs(playersAttribute.getStrength());
+//            comPlayersAttriSimpleVo.setCurrentStrength(_outEnd < 0 ? 0 : _outEnd);
+//            //最大值是配置的值和链上数据的值相加
+//            comPlayersAttriSimpleVo.setMaxStrength(_maxStrength);
+//
+//            map.put("playerAttribute", comPlayersAttriSimpleVo);
+//        }
+//
+//        return Result.of(map);
+//    }
 
 
 
 
     /**
     /**
@@ -984,6 +984,10 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
             @RequestParam(value = "fruitId") Integer fruitId,
             @RequestParam(value = "fruitId") Integer fruitId,
             @RequestParam(value = "amount") Integer amount) {
             @RequestParam(value = "amount") Integer amount) {
 
 
+        //防止输入负数
+        if(amount <= 0){
+            return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_ERROR.getMessage(), ResultEnum.FRUIT_AMOUNT_ERROR.getCode());
+        }
         //
         //
         ComFruitVo comFruitVo = comFruitService.findById(fruitId);
         ComFruitVo comFruitVo = comFruitService.findById(fruitId);
 
 

+ 9 - 4
src/main/java/com/td/boss/game/comsnbfreeze/controller/ComSnbFreezeController.java

@@ -119,7 +119,7 @@ public class ComSnbFreezeController extends CommonController<ComSnbFreezeVo, Com
 
 
         //拿出用户对应的数据
         //拿出用户对应的数据
         ComUsersVo comUsersVo = comUsersService.findByUserId(id.toString());
         ComUsersVo comUsersVo = comUsersService.findByUserId(id.toString());
-        if (comUsersVo.getSnb() < snbAmount) {
+        if (comUsersVo.getSnb() <= 0 || comUsersVo.getSnb() < snbAmount || snbAmount <= 0) {
             map.put("msg", "账户snb不足");
             map.put("msg", "账户snb不足");
             //WALLET_SNB_INSUFFICIENT_QUANTITY(602,"snb不足以支付!")
             //WALLET_SNB_INSUFFICIENT_QUANTITY(602,"snb不足以支付!")
             //return Result.of(map, false, ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getMessage(), ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getCode());
             //return Result.of(map, false, ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getMessage(), ResultEnum.WALLET_SNB_INSUFFICIENT_QUANTITY.getCode());
@@ -140,7 +140,7 @@ public class ComSnbFreezeController extends CommonController<ComSnbFreezeVo, Com
             }
             }
             comUsersService.save(comUsersVo);
             comUsersService.save(comUsersVo);
             redisLock.unlock(_redisKey, String.valueOf(time));
             redisLock.unlock(_redisKey, String.valueOf(time));
-        }catch (Exception e){
+        } catch (Exception e) {
             redisLock.unlock(_redisKey, String.valueOf(time));
             redisLock.unlock(_redisKey, String.valueOf(time));
             map.put("msg", "保存账户数据失败!");
             map.put("msg", "保存账户数据失败!");
             return Result.of(map);
             return Result.of(map);
@@ -212,6 +212,11 @@ public class ComSnbFreezeController extends CommonController<ComSnbFreezeVo, Com
         }
         }
 
 
         ComSnbFreezeVo comSnbFreezeVo = comSnbFreezeService.findById(snbId);
         ComSnbFreezeVo comSnbFreezeVo = comSnbFreezeService.findById(snbId);
+        if(comSnbFreezeVo.getSnb()<=0){
+            map.put("msg", "snb是小于0?");
+            return Result.of(map);
+        }
+
         if (!comSnbFreezeVo.getIsSuccess().equals(0)) {
         if (!comSnbFreezeVo.getIsSuccess().equals(0)) {
             //交易状态是0才可以进行下一步操作
             //交易状态是0才可以进行下一步操作
             //WALLET_SNB_SUCCESS_NOT_ZERO(603,"snb不可操作"),
             //WALLET_SNB_SUCCESS_NOT_ZERO(603,"snb不可操作"),
@@ -244,7 +249,7 @@ public class ComSnbFreezeController extends CommonController<ComSnbFreezeVo, Com
                 }
                 }
                 comUsersService.save(comUsersVo);
                 comUsersService.save(comUsersVo);
                 redisLock.unlock(_redisKey, String.valueOf(time));
                 redisLock.unlock(_redisKey, String.valueOf(time));
-            }catch (Exception e){
+            } catch (Exception e) {
                 redisLock.unlock(_redisKey, String.valueOf(time));
                 redisLock.unlock(_redisKey, String.valueOf(time));
                 map.put("msg", "保存账户数据失败!");
                 map.put("msg", "保存账户数据失败!");
                 return Result.of(map);
                 return Result.of(map);
@@ -455,7 +460,7 @@ public class ComSnbFreezeController extends CommonController<ComSnbFreezeVo, Com
                 Double _backCNT = Double.parseDouble(pay_amount);
                 Double _backCNT = Double.parseDouble(pay_amount);
                 // 处理itemType,种子id ,获取种子类型,设置种子不同的数据
                 // 处理itemType,种子id ,获取种子类型,设置种子不同的数据
                 // todo 直接处理种子id
                 // todo 直接处理种子id
-                Integer itemType =  Integer.parseInt(item_type);
+                Integer itemType = Integer.parseInt(item_type);
                 ComMallSeedVo seedVo = comMallSeedService.findById(itemType);
                 ComMallSeedVo seedVo = comMallSeedService.findById(itemType);
                 if (seedVo == null) {
                 if (seedVo == null) {
                     comCntOrderVo.setCntDescribe("非法操作:所修改的种子不存在服务器中!当前购买种子id:" + itemType);
                     comCntOrderVo.setCntDescribe("非法操作:所修改的种子不存在服务器中!当前购买种子id:" + itemType);

+ 24 - 24
src/main/java/com/td/boss/game/comusers/controller/ComUsersController.java

@@ -359,30 +359,30 @@ public class ComUsersController extends CommonController<ComUsersVo, ComUsers, S
     }
     }
 
 
 
 
-    @PostMapping("setUserInfo")
-    public Result<Map> setUserInfo(@RequestParam(value = "userId") String userId,
-                                   @RequestParam(value = "cnt") Integer cnt,
-                                   @RequestParam(value = "snb") Integer snb,
-                                   @RequestParam(value = "gold") Integer gold,
-                                   @RequestParam(value = "diamond") Integer diamond) {
-        Map map = new HashMap();
-        ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
-        if (comUsersVo == null) {
-            return Result.of(null, false, ResultEnum.USER_DOES_NOT_EXIST.getMessage(), ResultEnum.USER_DOES_NOT_EXIST.getCode());
-        }
-
-        comUsersVo.setCnt(cnt);
-        comUsersVo.setSnb(snb);
-        comUsersVo.setGold(gold);
-        comUsersVo.setDiamond(diamond);
-        comUsersService.save(comUsersVo);
-        map.put("gold", comUsersVo.getGold());
-        map.put("diamond", comUsersVo.getDiamond());
-        map.put("CNT", comUsersVo.getCnt());
-        map.put("SNB", comUsersVo.getSnb());
-        map.put("address", comUsersVo.getAddress());
-        return Result.of(map);
-    }
+//    @PostMapping("setUserInfo")
+//    public Result<Map> setUserInfo(@RequestParam(value = "userId") String userId,
+//                                   @RequestParam(value = "cnt") Integer cnt,
+//                                   @RequestParam(value = "snb") Integer snb,
+//                                   @RequestParam(value = "gold") Integer gold,
+//                                   @RequestParam(value = "diamond") Integer diamond) {
+//        Map map = new HashMap();
+//        ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
+//        if (comUsersVo == null) {
+//            return Result.of(null, false, ResultEnum.USER_DOES_NOT_EXIST.getMessage(), ResultEnum.USER_DOES_NOT_EXIST.getCode());
+//        }
+//
+//        comUsersVo.setCnt(cnt);
+//        comUsersVo.setSnb(snb);
+//        comUsersVo.setGold(gold);
+//        comUsersVo.setDiamond(diamond);
+//        comUsersService.save(comUsersVo);
+//        map.put("gold", comUsersVo.getGold());
+//        map.put("diamond", comUsersVo.getDiamond());
+//        map.put("CNT", comUsersVo.getCnt());
+//        map.put("SNB", comUsersVo.getSnb());
+//        map.put("address", comUsersVo.getAddress());
+//        return Result.of(map);
+//    }
 
 
 
 
     //推送数据接口
     //推送数据接口