|
|
@@ -255,10 +255,21 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
//return Result.of(null, false, ResultEnum.LAND_PLANT_FLAG_IS_NULL.getMessage(), ResultEnum.LAND_PLANT_FLAG_IS_NULL.getCode());
|
|
|
_redisKey = comPlayerLand.getUserId() + "or" + comPlayerLand.getConfigLandId();
|
|
|
}
|
|
|
+ //受灾时候,不给收获
|
|
|
+ String _disasterKey = RedisData.getPlayerDisastersFirstKey() + comPlayerLand.getConfigLandId() + comPlayerLand.getUserId();
|
|
|
+ long _disasterTime = System.currentTimeMillis() + RedisData.getPlayerDisastersFirstTimeout();
|
|
|
+
|
|
|
Map map = new HashMap();
|
|
|
//todo 总共偷去的数量
|
|
|
Double _stealProfits = 0d;
|
|
|
+ //todo 灾难影响的数量
|
|
|
+ Double _disasterProfits = 0d;
|
|
|
try {
|
|
|
+ //加一层受灾锁
|
|
|
+ if (!redisLock.lock(_disasterKey, String.valueOf(_disasterTime))) {
|
|
|
+ return Result.of(null, false, ResultEnum.LAND_DISATER_LOCK.getMessage(), ResultEnum.LAND_DISATER_LOCK.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
// 如果存在plantFlag 说明是新种植的
|
|
|
if (!redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
return Result.of(null, false, ResultEnum.LAND_STEAL_LOCK.getMessage(), ResultEnum.LAND_STEAL_LOCK.getCode());
|
|
|
@@ -285,9 +296,9 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
// 配置的参数。这里先直接定义
|
|
|
Double profitConfig = comSettingVo.getProfit(), stealRatioMaxConfig = comSettingVo.getStealMaxRatio(), stealRatioMinConfig = comSettingVo.getStealMinRatio(), finallyGetRatioConfig = comSettingVo.getFinalRatio();
|
|
|
Double landLevelInCome = getLandLevelInCome(comPlayerLand, comMallSeedVo.getPriceSnb());
|
|
|
- Double _profitDouble = DoubleUtil.add(_profit.doubleValue(),landLevelInCome);
|
|
|
+ Double _profitDouble = DoubleUtil.add(_profit.doubleValue(), landLevelInCome);
|
|
|
Double _residualProfit = DoubleUtil.mul(_profitDouble, DoubleUtil.sub(1d, profitConfig));//如果 profitConfig 0.2,剩余利润就是0.8;
|
|
|
- Double _stealAmount = DoubleUtil.sub(_profitDouble, _residualProfit); //可偷取的利润
|
|
|
+ //Double _stealAmount = DoubleUtil.sub(_profitDouble, _residualProfit); //可偷取的利润
|
|
|
|
|
|
//todo 计算总共损失的数量
|
|
|
List<ComPlayerProfit> comPlayerProfits = comPlayerProfitService.findByUserIdAndPlantFlagAndLandId(userId, _redisKey, comPlayerLand.getConfigLandId());
|
|
|
@@ -295,21 +306,29 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
ComPlayerProfit temp = comPlayerProfits.get(i);
|
|
|
_stealProfits = DoubleUtil.add(_stealProfits, temp.getStolen());
|
|
|
}
|
|
|
- Double _userHarvestPart = DoubleUtil.sub(_stealAmount, _stealProfits);
|
|
|
+ // Double _userHarvestPart = DoubleUtil.sub(_stealAmount, _stealProfits);
|
|
|
+ Double _userHarvestPart = DoubleUtil.sub(_profitDouble, _stealProfits);
|
|
|
+ Double _endLossProfits = 0d;
|
|
|
if (_userHarvestPart < 0.0) {
|
|
|
//差值不能为负数
|
|
|
_userHarvestPart = 0d;
|
|
|
//相当于被偷取全部利润,这里返回一个被偷去的全部利润值
|
|
|
- map.put("lossAmount", _stealAmount);
|
|
|
+ //map.put("lossAmount", _stealAmount);
|
|
|
+ map.put("lossAmount", _profitDouble);
|
|
|
+ _endLossProfits = _profitDouble;
|
|
|
} else {
|
|
|
//todo 返回一个被偷的数量
|
|
|
map.put("lossAmount", _stealProfits);
|
|
|
+ _endLossProfits = _stealProfits;
|
|
|
}
|
|
|
|
|
|
+ //上面计算被偷的,下面计算灾难影响的
|
|
|
+
|
|
|
+
|
|
|
//todo 利润
|
|
|
_amount -= _profit;
|
|
|
- //用户收取的对应数量,固定收入+被偷取后剩余的部分
|
|
|
- _amountPart = DoubleUtil.add(_residualProfit, _userHarvestPart);
|
|
|
+ //用户收取的对应数量,固定收入+被偷取后剩余的部分 (改成全部影响利润了。没有固定收入)
|
|
|
+ _amountPart = _userHarvestPart;// DoubleUtil.add(_residualProfit, _userHarvestPart);
|
|
|
//果实 Type =1
|
|
|
ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
|
|
|
Integer _beforeAmount = 0;
|
|
|
@@ -355,7 +374,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
_playerLog.setAfterAmount(comPlayerGoodsSimpleVo.getAmount());
|
|
|
//收取时候信息记录
|
|
|
_playerLog.setTPart(_amountPart);
|
|
|
- _playerLog.setTLoss(_stealProfits); //损失的部分
|
|
|
+ _playerLog.setTLoss(_endLossProfits); //(_stealProfits); //损失的部分
|
|
|
_playerLog.setBeforePart(_beforeProfitPart);
|
|
|
_playerLog.setAfterPart(_afterProfitPart);
|
|
|
_playerLog.setLMultiple(comPlayerLand.getLeaseMultiple());
|
|
|
@@ -364,9 +383,11 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
|
|
|
//对应的,存在plantFlag则解锁
|
|
|
redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
+ redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
|
|
|
} catch (Exception e) {
|
|
|
//对应的,存在plantFlag则解锁
|
|
|
redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
+ redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
|
|
|
throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
map.put("msg", "成功收取果实!");
|
|
|
@@ -507,7 +528,17 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
//需要redis 加锁
|
|
|
long time = System.currentTimeMillis() + RedisData.getPlayerGoodsTimeout();
|
|
|
|
|
|
+ //受灾时候,不给收获
|
|
|
+ String _disasterKey = RedisData.getPlayerDisastersFirstKey() + otherPlayerLand.getConfigLandId() + otherPlayerLand.getUserId();
|
|
|
+ long _disasterTime = System.currentTimeMillis() + RedisData.getPlayerDisastersFirstTimeout();
|
|
|
+
|
|
|
+
|
|
|
try {
|
|
|
+ //加一层受灾锁
|
|
|
+ if (!redisLock.lock(_disasterKey, String.valueOf(_disasterTime))) {
|
|
|
+ return Result.of(null, false, ResultEnum.LAND_DISATER_LOCK.getMessage(), ResultEnum.LAND_DISATER_LOCK.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
if (!redisLock.lock(_redisSNBKey, String.valueOf(time))) {
|
|
|
//如果有snb冲突锁
|
|
|
return Result.of(null, false, ResultEnum.USER_LOGIN_LOCK.getMessage(), ResultEnum.USER_LOGIN_LOCK.getCode());
|
|
|
@@ -530,7 +561,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
//todo 拿出计算利润,收获量减去种子的成本(snb)后的百分之30 ,后面需要后台可调整
|
|
|
Double landLevelInCome = getLandLevelInCome(otherPlayerLand, comMallSeedVo.getPriceSnb());
|
|
|
Integer _profitInt = _otherAmount - otherPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
|
|
|
- Double _profit = DoubleUtil.add(_profitInt.doubleValue(),landLevelInCome);
|
|
|
+ Double _profit = DoubleUtil.add(_profitInt.doubleValue(), landLevelInCome);
|
|
|
// 配置的参数。这里先直接定义
|
|
|
// 需要根据 狗是否生效,小偷是否装备打狗棒来确定参数
|
|
|
Double profitConfig = _dogWork ? comSettingVo.getProfitDog() : comSettingVo.getProfit(),
|
|
|
@@ -543,27 +574,70 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
if (_dogWork) {
|
|
|
_stealRatio = _holdTheStick ? comSettingVo.getStealRatioHasStick() : comSettingVo.getStealRatioNoStick();
|
|
|
}
|
|
|
- Double _stolenAmount = DoubleUtil.mul(_profit.doubleValue(), _stealRatio);
|
|
|
+ Double _stolenAmount = DoubleUtil.mul(_profit, _stealRatio);
|
|
|
//这里根据plantFlag判断目标用户当前种植被偷取完,记录更新用户 comPlayerLand plantSteal 字段;保存一个偷取状态
|
|
|
- Double _sumStolen = comPlayerProfitService.getStolenSumByOtherUserIdAndPlantFlag(otherUserId, _redisKey);
|
|
|
+ //这里只拿去被偷的利润,灾难扣除的不算再这里,但是总利润需要限制计算
|
|
|
+ //Double _sumStolen = comPlayerProfitService.getStolenSumByOtherUserIdAndPlantFlagAndLossType(otherUserId, _redisKey,0);
|
|
|
+ Double _sumStolen = 0d,_allStolen = 0d;
|
|
|
+ List<ComPlayerProfit> comPlayerProfits = comPlayerProfitService.findByUserIdAndPlantFlagAndLandId(otherUserId, _redisKey, otherPlayerLand.getConfigLandId());
|
|
|
+ for (int i = 0; i < comPlayerProfits.size(); i++) {
|
|
|
+ ComPlayerProfit temp = comPlayerProfits.get(i);
|
|
|
+ if(temp.getLossType().equals(0)){
|
|
|
+ //偷取时候的利润总和
|
|
|
+ _sumStolen = DoubleUtil.add(_sumStolen, temp.getStolen());
|
|
|
+ }
|
|
|
+ //当前全部损失的利润
|
|
|
+ _allStolen = DoubleUtil.add(_allStolen, temp.getStolen());
|
|
|
+ }
|
|
|
+
|
|
|
//todo 这里的可偷利润应该是最大值,用户不能超过这个,需要限制判断
|
|
|
- Double _maxAmount = DoubleUtil.mul(_profit.doubleValue(), profitConfig); //可偷取的利润
|
|
|
+ Double _maxAmount = DoubleUtil.mul(_profit, profitConfig); //可偷取的利润
|
|
|
//1 单偷操作 就是 _sumStolen>_maxAmount 或者 _sumStolen == _maxAmount ,被偷完了
|
|
|
- if (!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1)) {
|
|
|
+ //if (!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1)) {
|
|
|
+ // // 需要redis 解锁
|
|
|
+ // redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
+ // redisLock.unlock(_redisSNBKey, String.valueOf(time));
|
|
|
+ // redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
|
|
|
+ // //记录一个不可偷取的状态
|
|
|
+ // otherPlayerLand.setPlantSteal(0);
|
|
|
+ // comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
|
|
|
+ // map.put("plant_steal", otherPlayerLand.getPlantSteal());
|
|
|
+ // return Result.of(map, false, ResultEnum.LAND_CAN_STEAL_IS_MAX.getMessage(), ResultEnum.LAND_CAN_STEAL_IS_MAX.getCode());
|
|
|
+ //}
|
|
|
+ //计算剩下可偷利润的差,防止过多偷取用户利润 _stolenAmount
|
|
|
+ //Double _diff = Math.abs(DoubleUtil.sub(_maxAmount, _sumStolen));
|
|
|
+ Double _diff = DoubleUtil.sub(_maxAmount, _sumStolen);
|
|
|
+ Boolean isUpdateCanSteal = false;
|
|
|
+ if (DoubleUtil.compare(_diff,0.0).equals(1)) {
|
|
|
+ if(DoubleUtil.compare(_stolenAmount, _diff).equals(1)){
|
|
|
+ _stolenAmount = _diff;
|
|
|
+ isUpdateCanSteal = true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ _stolenAmount = 0d;
|
|
|
+ isUpdateCanSteal = true;
|
|
|
+ }
|
|
|
+ //这里需要拦截处理最终偷取的利润,比如 总利润_profit=530(可能会加上收益),
|
|
|
+ // _allStolen + _stolenAmount 不能大于总利润
|
|
|
+ Double _endLossProfit = DoubleUtil.add(_allStolen,_stolenAmount);
|
|
|
+ Double _endLossDiff = DoubleUtil.sub(_profit,_endLossProfit);
|
|
|
+ if(!DoubleUtil.compare(_sumStolen, _maxAmount).equals(-1) || DoubleUtil.compare(_endLossDiff,0.0).equals(-1)){
|
|
|
+ //如果差值为零
|
|
|
// 需要redis 解锁
|
|
|
redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
redisLock.unlock(_redisSNBKey, String.valueOf(time));
|
|
|
+ redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
|
|
|
//记录一个不可偷取的状态
|
|
|
otherPlayerLand.setPlantSteal(0);
|
|
|
comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
|
|
|
map.put("plant_steal", otherPlayerLand.getPlantSteal());
|
|
|
return Result.of(map, false, ResultEnum.LAND_CAN_STEAL_IS_MAX.getMessage(), ResultEnum.LAND_CAN_STEAL_IS_MAX.getCode());
|
|
|
}
|
|
|
- //计算剩下可偷利润的差,防止过多偷取用户利润 _stolenAmount
|
|
|
- Double _diff = Math.abs(DoubleUtil.sub(_maxAmount, _sumStolen));
|
|
|
- if (DoubleUtil.compare(_stolenAmount, _diff).equals(1)) {
|
|
|
- //_stolenAmount>_diff
|
|
|
- _stolenAmount = _diff;
|
|
|
+ if(isUpdateCanSteal){
|
|
|
+ //记录一个不可偷取的状态
|
|
|
+ otherPlayerLand.setPlantSteal(0);
|
|
|
+ comPlayerLandService.save(CopyUtil.copy(otherPlayerLand, ComPlayerLandVo.class));
|
|
|
+ map.put("plant_steal", otherPlayerLand.getPlantSteal());
|
|
|
}
|
|
|
//最终偷窃人获取的是偷取的是目标用户损失量的10% finallyGetRatioConfig
|
|
|
Double _finalStealAmount = DoubleUtil.mul(_stolenAmount, finallyGetRatioConfig);
|
|
|
@@ -603,15 +677,20 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
comPlayerProfit.setLeaseMultiple(otherPlayerLand.getLeaseMultiple());
|
|
|
comPlayerProfit.setLeaseDate(otherPlayerLand.getLeaseDate());
|
|
|
comPlayerProfit.setHarvest(_otherAmount);
|
|
|
- comPlayerProfit.setProfit(_profit.doubleValue());//目标用户可偷的初始利润值
|
|
|
+ comPlayerProfit.setProfit(_profit);//目标用户可偷的初始利润值
|
|
|
comPlayerProfit.setStolen(_stolenAmount);//目标用户被偷的数量
|
|
|
comPlayerProfit.setFinalSteal(_finalStealAmount);//用户最终偷取的量,是被偷的数量 10%左右
|
|
|
- comPlayerProfit.setProfitAfter(DoubleUtil.sub(_profit.doubleValue(), DoubleUtil.add(_stolenAmount, _sumStolen))); //可偷的减去被偷的
|
|
|
+ comPlayerProfit.setProfitAfter(DoubleUtil.sub(_profit, DoubleUtil.add(_stolenAmount, _sumStolen))); //可偷的减去被偷的
|
|
|
//记录相关比例
|
|
|
comPlayerProfit.setProfitRatio(profitConfig);
|
|
|
comPlayerProfit.setStealRatio(_stealRatio);
|
|
|
comPlayerProfit.setFinalRatio(finallyGetRatioConfig);
|
|
|
comPlayerProfit.setLossType(0);
|
|
|
+
|
|
|
+ //
|
|
|
+ comPlayerProfit.setDsasterId(-10L);
|
|
|
+ comPlayerProfit.setAddedPart(landLevelInCome);
|
|
|
+
|
|
|
ComPlayerProfitVo comPlayerProfitVo = CopyUtil.copy(comPlayerProfit, ComPlayerProfitVo.class);
|
|
|
comPlayerProfitService.save(comPlayerProfitVo);
|
|
|
|
|
|
@@ -736,11 +815,14 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
|
|
|
//解除snb锁
|
|
|
redisLock.unlock(_redisSNBKey, String.valueOf(time));
|
|
|
+
|
|
|
+ redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
|
|
|
return Result.of(map);
|
|
|
} catch (Exception e) {
|
|
|
// 需要redis 解锁
|
|
|
redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
redisLock.unlock(_redisSNBKey, String.valueOf(time));
|
|
|
+ redisLock.unlock(_disasterKey, String.valueOf(_disasterTime));
|
|
|
throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
|
|
|
@@ -979,8 +1061,10 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
// }
|
|
|
@Autowired
|
|
|
private ComConfigService comConfigService;
|
|
|
+
|
|
|
/**
|
|
|
* 获得土地级别收益,普通土地最后结果为0
|
|
|
+ *
|
|
|
* @param comPlayerLand
|
|
|
* @param priceSnb
|
|
|
* @return
|