|
|
@@ -21,18 +21,29 @@ import com.td.boss.game.complayerland.vo.ComPlayerLandVo;
|
|
|
import com.td.boss.game.complayerlog.pojo.ComPlayerLog;
|
|
|
import com.td.boss.game.complayerlog.service.ComPlayerLogService;
|
|
|
import com.td.boss.game.complayerlog.vo.ComPlayerLogVo;
|
|
|
+import com.td.boss.game.complayerprofit.pojo.ComPlayerProfit;
|
|
|
+import com.td.boss.game.complayerprofit.service.ComPlayerProfitService;
|
|
|
+import com.td.boss.game.complayerprofit.vo.ComPlayerProfitVo;
|
|
|
+import com.td.boss.game.complayers.vo.ComPlayersVo;
|
|
|
+import com.td.boss.game.complayersattri.service.ComPlayersAttriService;
|
|
|
+import com.td.boss.game.complayersattri.vo.ComPlayersAttriSimpleVo;
|
|
|
+import com.td.boss.game.complayersattri.vo.ComPlayersAttriVo;
|
|
|
+import com.td.boss.game.comsetting.pojo.ComSetting;
|
|
|
+import com.td.boss.game.comsetting.service.ComSettingService;
|
|
|
+import com.td.boss.game.comsetting.vo.ComSettingVo;
|
|
|
import com.td.boss.game.comsnbtran.pojo.ComSnbTran;
|
|
|
import com.td.boss.game.comsnbtran.service.ComSnbTranService;
|
|
|
import com.td.boss.game.comsnbtran.vo.ComSnbTranVo;
|
|
|
import com.td.boss.game.comusers.service.ComUsersService;
|
|
|
import com.td.boss.game.comusers.vo.ComUsersVo;
|
|
|
-import com.td.boss.util.CopyUtil;
|
|
|
-import com.td.boss.util.DateUtil;
|
|
|
+import com.td.boss.util.*;
|
|
|
import net.bytebuddy.asm.Advice;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -49,9 +60,15 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
@Autowired
|
|
|
private ComPlayerLandService comPlayerLandService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ComPlayerProfitService comPlayerProfitService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ComUsersService comUsersService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ComPlayersAttriService comPlayersAttriService;
|
|
|
+
|
|
|
//交易表service
|
|
|
@Autowired
|
|
|
private ComSnbTranService comSnbTranService;
|
|
|
@@ -63,8 +80,16 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
@Autowired
|
|
|
private ComExplainLandService comExplainLandService;
|
|
|
|
|
|
+ //配置信息
|
|
|
+ @Autowired
|
|
|
+ private ComSettingService comSettingService;
|
|
|
|
|
|
|
|
|
+ private static final int TIMEOUT = 10 * 1000; //超时时间 10s
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisLock redisLock;
|
|
|
+
|
|
|
/**
|
|
|
* 获取仓库 全部数据,目前使用goods_type区分种子和果实
|
|
|
*
|
|
|
@@ -90,6 +115,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
ComFruitVo comFruitVo = comFruitService.findById(e.getGoodsIndex());
|
|
|
ComFruitAmountVo comFruitAmountVo = CopyUtil.copy(comFruitVo, ComFruitAmountVo.class);
|
|
|
comFruitAmountVo.setAmount(e.getAmount());
|
|
|
+ comFruitAmountVo.setAmountPart(e.getAmountPart());
|
|
|
fruitList.add(comFruitAmountVo);
|
|
|
}
|
|
|
return e;
|
|
|
@@ -168,12 +194,11 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
//todo 判断土地租赁是否到期,是到期不给种植
|
|
|
//租赁的剩余天数 。
|
|
|
Long leaseDaysMill = comPlayerLand.getLeaseTime().getTime() - DateUtil.getNowDate().getTime();
|
|
|
- if(leaseDaysMill <= 0){
|
|
|
- //todo 清除记录的数据
|
|
|
- //todo 清除记录的数据
|
|
|
- // 1.土地租赁到期,删除土地租赁数据
|
|
|
+ if (leaseDaysMill <= 0) {
|
|
|
+ // 清除记录的数据
|
|
|
+ // 1.土地租赁到期,删除土地租赁数据
|
|
|
comPlayerLandService.delete(comPlayerLand.getId());
|
|
|
- //todo 2.把删除的这个土地的数据记录到com_explain_land中去
|
|
|
+ // 2.把删除的这个土地的数据记录到com_explain_land中去
|
|
|
ComExplainLandVo comExplainLandVo = new ComExplainLandVo();
|
|
|
comExplainLandVo = CopyUtil.copy(comPlayerLand, ComExplainLandVo.class);
|
|
|
comExplainLandVo.setLandId(comPlayerLand.getConfigLandId());
|
|
|
@@ -202,7 +227,28 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
//如果当前时间减去种子的成熟期,还是小于种植日期,则判断未成熟
|
|
|
return Result.of(null, false, ResultEnum.SEED_DATE_ERROR.getMessage(), ResultEnum.SEED_DATE_ERROR.getCode());
|
|
|
}
|
|
|
+ //获取数据库相关配置
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ //需要redis 加锁
|
|
|
+ long time = System.currentTimeMillis() + TIMEOUT;
|
|
|
+ //获取用户的plantFlag,因为之前的用户没有设置这个flag,所以设为第一次,用 userId 和 landId 组合成key
|
|
|
+ String _redisKey = comPlayerLand.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 = comPlayerLand.getUserId() + "or" + comPlayerLand.getConfigLandId();
|
|
|
+ }
|
|
|
+ //todo 总共偷去的数量
|
|
|
+ Double _stealProfits = 0d;
|
|
|
try {
|
|
|
+ // 如果存在plantFlag 说明是新种植的
|
|
|
+ if (!redisLock.lock(_redisKey, String.valueOf(time))) {
|
|
|
+ return Result.of(null, false, ResultEnum.LAND_STEAL_LOCK.getMessage(), ResultEnum.LAND_STEAL_LOCK.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
//设置一个未种植状态即可
|
|
|
comPlayerLand.setIsPlant(0);
|
|
|
ComPlayerLandVo comPlayerLandVo = CopyUtil.copy(comPlayerLand, ComPlayerLandVo.class);
|
|
|
@@ -210,6 +256,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
|
|
|
//计算一个收获量, 租赁倍数* 租赁日期下的产量
|
|
|
Integer _amount = 0;
|
|
|
+ Double _amountPart = 0d;
|
|
|
if (comPlayerLand.getLeaseDate().equals(1)) {
|
|
|
_amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
|
|
|
} else if (comPlayerLand.getLeaseDate().equals(2)) {
|
|
|
@@ -217,13 +264,37 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
} else if (comPlayerLand.getLeaseDate().equals(3)) {
|
|
|
_amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
}
|
|
|
+ //todo 收获果实时候,需要减去一个被偷取的利润,然后判断一个是否大于设置的利润,超出了报异常,并且收取的数量不能为小于0
|
|
|
+ // 拿出计算利润,收获量减去种子的成本(snb)后的百分之20 ,后面需要后台可调整
|
|
|
+ Integer _profit = _amount - comPlayerLand.getLeaseMultiple() * comMallSeedVo.getPriceSnb();
|
|
|
+ // 配置的参数。这里先直接定义
|
|
|
+ Double profitConfig = comSettingVo.getProfit(), stealRatioMaxConfig = comSettingVo.getStealMaxRatio(), stealRatioMinConfig = comSettingVo.getStealMinRatio(), finallyGetRatioConfig = comSettingVo.getFinalRatio();
|
|
|
+
|
|
|
+ Double _profitDouble = _profit.doubleValue();
|
|
|
+ Double _residualProfit = DoubleUtil.mul(_profitDouble, DoubleUtil.sub(1d, profitConfig));//如果 profitConfig 0.2,剩余利润就是0.8;
|
|
|
+ Double _stealAmount = DoubleUtil.sub(_profitDouble, _residualProfit); //可偷取的利润
|
|
|
+
|
|
|
+ //todo 计算总共损失的数量
|
|
|
+ List<ComPlayerProfit> comPlayerProfits = comPlayerProfitService.findByUserIdAndPlantFlagAndLandId(userId, comPlayerLand.getPlantFlag(), comPlayerLand.getConfigLandId());
|
|
|
+ for (int i = 0; i < comPlayerProfits.size(); i++) {
|
|
|
+ ComPlayerProfit temp = comPlayerProfits.get(i);
|
|
|
+ _stealProfits = DoubleUtil.add(_stealProfits, temp.getStolen());
|
|
|
+ }
|
|
|
+ Double _userHarvestPart = DoubleUtil.sub(_stealAmount, _stealProfits);
|
|
|
+ if (_userHarvestPart < 0.0) {
|
|
|
+ //差值不能为负数
|
|
|
+ _userHarvestPart = 0d;
|
|
|
+ }
|
|
|
+ //todo 利润
|
|
|
+ _amount -= _profit;
|
|
|
+ //用户收取的对应数量,固定收入+被偷取后剩余的部分
|
|
|
+ _amountPart = DoubleUtil.add(_residualProfit, _userHarvestPart);
|
|
|
//果实 Type =1
|
|
|
- //todo 收获果实时候
|
|
|
ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
|
|
|
-
|
|
|
Integer _beforeAmount = 0;
|
|
|
+ Double _beforeProfitPart = 0d, _afterProfitPart = 0d;
|
|
|
if (comPlayerGoodsSimpleVo == null) {
|
|
|
- //背包增加一个果实
|
|
|
+ //背包增加果实
|
|
|
comPlayerGoodsSimpleVo = new ComPlayerGoods();
|
|
|
comPlayerGoodsSimpleVo.setUserId(userId);
|
|
|
comPlayerGoodsSimpleVo.setGoodsIndex(comMallSeedVo.getHarvestId());
|
|
|
@@ -232,12 +303,20 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
//用种子的picture
|
|
|
comPlayerGoodsSimpleVo.setPictureName(comMallSeedVo.getPicture());
|
|
|
comPlayerGoodsSimpleVo.setAmount(_amount);
|
|
|
+ comPlayerGoodsSimpleVo.setAmountPart(_amountPart);
|
|
|
|
|
|
_beforeAmount = 0;
|
|
|
+ _beforeProfitPart = 0d;
|
|
|
+ _afterProfitPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
} else {
|
|
|
_beforeAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ _beforeProfitPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
|
|
|
comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() + _amount);
|
|
|
+ //用户利润部分
|
|
|
+ comPlayerGoodsSimpleVo.setAmountPart(DoubleUtil.add(comPlayerGoodsSimpleVo.getAmountPart(), _amountPart));
|
|
|
+
|
|
|
+ _afterProfitPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
}
|
|
|
|
|
|
ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
@@ -253,15 +332,230 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
_playerLog.setBeforeAmount(_beforeAmount);
|
|
|
////交易后的数据
|
|
|
_playerLog.setAfterAmount(comPlayerGoodsSimpleVo.getAmount());
|
|
|
+ //收取时候信息记录
|
|
|
+ _playerLog.setTPart(_amountPart);
|
|
|
+ _playerLog.setTLoss(_stealProfits); //损失的部分
|
|
|
+ _playerLog.setBeforePart(_beforeProfitPart);
|
|
|
+ _playerLog.setAfterPart(_afterProfitPart);
|
|
|
_playerLog.setLMultiple(comPlayerLand.getLeaseMultiple());
|
|
|
ComPlayerLogVo _playerLogVo = CopyUtil.copy(_playerLog, ComPlayerLogVo.class);
|
|
|
comPlayerLogService.save(_playerLogVo);
|
|
|
+
|
|
|
+ //对应的,存在plantFlag则解锁
|
|
|
+ redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
} catch (Exception e) {
|
|
|
+ //对应的,存在plantFlag则解锁
|
|
|
+ redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
|
|
|
Map map = new HashMap();
|
|
|
map.put("msg", "成功收取果实!");
|
|
|
+ //todo 返回一个被偷的数量
|
|
|
+ map.put("lossAmount",_stealProfits);
|
|
|
+ return Result.of(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理一键收取水果果实时候,传入对方用户id 即可
|
|
|
+ * <p>
|
|
|
+ * <p>
|
|
|
+ * 收获时候,操作用户snb时候,需要加锁,防止用户收取时候遗漏计算snb
|
|
|
+ *
|
|
|
+ * @param otherUserId
|
|
|
+ * @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 = 0;
|
|
|
+ //1.先判断用户是否有足够的体力,根据snb判断。2. 收取到果实,扣除用户一个体力值
|
|
|
+ ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
+ ComPlayersAttriVo playersAttribute = comPlayersAttriService.findByUserId(userId);
|
|
|
+ Integer _out = _configStrength - Math.abs(playersAttribute.getStrength());
|
|
|
+ if (comUsersVo.getSnb() < comSettingVo.getLeastSnb()) {
|
|
|
+ //判断是否有双倍体力
|
|
|
+ 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;
|
|
|
+ //偷取用户的id
|
|
|
+ List<ComPlayerLand> otherPlayerLands = comPlayerLandService.findAllByCanStealOtherLands(userId, otherUserId);
|
|
|
+ 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() + TIMEOUT;
|
|
|
+ //获取用户的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.getStolenSumByPlantFlag(otherPlayerLand.getPlantFlag());
|
|
|
+ //todo 这里的可偷利润应该是最大值,用户不能超过这个,需要限制判断
|
|
|
+ Double _maxAmount = DoubleUtil.mul(_profit.doubleValue(), profitConfig); //可偷取的利润
|
|
|
+ //1 就是 _sumStolen>_maxAmount
|
|
|
+ if (DoubleUtil.compare(_sumStolen, _maxAmount).equals(1)) {
|
|
|
+ // 需要redis 解锁
|
|
|
+ redisLock.unlock(_redisKey, String.valueOf(time));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //最终偷窃人获取的是偷取的是目标用户损失量的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(otherPlayerLand.getPlantFlag());
|
|
|
+ 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.setTPart(_finalStealAmount);
|
|
|
+ _playerLog.setTLoss(_lostStealAmount); //损失的部分
|
|
|
+ _playerLog.setBeforePart(_beforeStealAmount);
|
|
|
+ _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);
|
|
|
+ _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.getLeastSnb() ? comSettingVo.getSnbUnitStrength() : comSettingVo.getUnitStrength();
|
|
|
+ playersAttribute.setStrength(playersAttribute.getStrength() + _addStrength);
|
|
|
+ comPlayersAttriService.save(playersAttribute);
|
|
|
+ ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttribute, ComPlayersAttriSimpleVo.class);
|
|
|
+ //前端的显示,输出一个不小于0的体力值
|
|
|
+ Integer _outEnd = _configStrength - Math.abs(playersAttribute.getStrength());
|
|
|
+ comPlayersAttriSimpleVo.setCurrentStrength(_outEnd < 0 ? 0 : _outEnd);
|
|
|
+ //最大值是配置的值和链上数据的值相加
|
|
|
+ comPlayersAttriSimpleVo.setMaxStrength(_configStrength + _chainStrength);
|
|
|
+
|
|
|
+ map.put("playerAttribute", comPlayersAttriSimpleVo);
|
|
|
+ }
|
|
|
+
|
|
|
return Result.of(map);
|
|
|
}
|
|
|
|
|
|
@@ -296,8 +590,10 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
if (comPlayerGoodsSimpleVo == null) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_DATA_ERROR.getMessage(), ResultEnum.FRUIT_DATA_ERROR.getCode());
|
|
|
}
|
|
|
-
|
|
|
- if (amount > comPlayerGoodsSimpleVo.getAmount()) {
|
|
|
+ //添加了 amountPart,需要加入判断整数部分
|
|
|
+ Integer _userFloorAmount = comPlayerGoodsSimpleVo.getAmount() + (int) Math.floor(comPlayerGoodsSimpleVo.getAmountPart());
|
|
|
+ //旧判断 amount > comPlayerGoodsSimpleVo.getAmount()
|
|
|
+ if (amount > _userFloorAmount) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_ERROR.getMessage(), ResultEnum.FRUIT_AMOUNT_ERROR.getCode());
|
|
|
}
|
|
|
//todo 销售果实时候,收取5%手续费,最少出售20的倍数
|
|
|
@@ -309,15 +605,58 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
try {
|
|
|
Integer _selfBeforeFruitAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
Integer _selfAfterFruitAmount = 0;
|
|
|
- if (comPlayerGoodsSimpleVo.getAmount().equals(amount)) {
|
|
|
- //如果库存量和出售的果实数量一样,删除
|
|
|
- comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
- _selfAfterFruitAmount = 0;
|
|
|
- } else {
|
|
|
- comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
+ Double _selfBeforeFruitAmountPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
+ Double _selfAfterFruitAmountPart = 0d;
|
|
|
+ Integer _tAmount = 0;
|
|
|
+ Double _tAmountPart = 0d;
|
|
|
+
|
|
|
+ //if (comPlayerGoodsSimpleVo.getAmount().equals(amount)) {
|
|
|
+ // //如果库存量和出售的果实数量一样,删除
|
|
|
+ // comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
+ // _selfAfterFruitAmount = 0;
|
|
|
+ //} else {
|
|
|
+ // comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
+ // _selfAfterFruitAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ // ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ // comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ //}
|
|
|
+ Integer _amountDif = comPlayerGoodsSimpleVo.getAmount() - amount;
|
|
|
+ //优先处理背包的amount
|
|
|
+ if (_amountDif > 0) {
|
|
|
+ //当前交易值
|
|
|
+ _tAmount = amount;
|
|
|
+ //如果amount 数量足够,直接记录 他们的差值
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(_amountDif);
|
|
|
_selfAfterFruitAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ _selfAfterFruitAmountPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ } else {
|
|
|
+ _selfAfterFruitAmount = 0;
|
|
|
+
|
|
|
+ //保证精度
|
|
|
+ BigDecimal bigDecimal1 = new BigDecimal(Double.toString(_amountDif));
|
|
|
+ BigDecimal bigDecimal2 = new BigDecimal(Double.toString(comPlayerGoodsSimpleVo.getAmountPart()));
|
|
|
+ BigDecimal _amountPart = bigDecimal1.add(bigDecimal2);
|
|
|
+
|
|
|
+ //当前交易值,_amountDif 小于0 说明 amount 是全全部扣除,到小数部分了。
|
|
|
+ _tAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ _tAmountPart = Math.abs(bigDecimal1.doubleValue());
|
|
|
+
|
|
|
+ System.out.print("_amountPart{}," + _amountPart.doubleValue());
|
|
|
+ //前面判断了。所以 _amountPart 不会比0.0小
|
|
|
+ if (_amountPart.compareTo(new BigDecimal(0.0)) <= 0) {
|
|
|
+ //如果库存量 amount 和 amountPart 都为零,删除
|
|
|
+ comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
+ //这里记录一下,看是否会是一个负数
|
|
|
+ _selfAfterFruitAmountPart = _amountPart.doubleValue();
|
|
|
+ } else {
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(0);
|
|
|
+ comPlayerGoodsSimpleVo.setAmountPart(_amountPart.doubleValue());
|
|
|
+ _selfAfterFruitAmountPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
+ ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ }
|
|
|
}
|
|
|
//todo 收取手续费之后
|
|
|
int _endAmount = (int) (amount * 1);
|
|
|
@@ -359,10 +698,15 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
_saleFruitPlayerLog.setTId(comFruitVo.getId());
|
|
|
_saleFruitPlayerLog.setTName(comFruitVo.getName());
|
|
|
_saleFruitPlayerLog.setTType(5);//出售水果时候,type设置5
|
|
|
- _saleFruitPlayerLog.setTAmount(amount);
|
|
|
+ _saleFruitPlayerLog.setTAmount(_tAmount);
|
|
|
_saleFruitPlayerLog.setBeforeAmount(_selfBeforeFruitAmount);
|
|
|
////交易后的数据
|
|
|
_saleFruitPlayerLog.setAfterAmount(_selfAfterFruitAmount);
|
|
|
+ //增加一个小数部分记录
|
|
|
+ _saleFruitPlayerLog.setTPart(_tAmountPart);
|
|
|
+ _saleFruitPlayerLog.setTLoss(0d);
|
|
|
+ _saleFruitPlayerLog.setBeforePart(_selfBeforeFruitAmountPart);
|
|
|
+ _saleFruitPlayerLog.setAfterPart(_selfAfterFruitAmountPart);
|
|
|
_saleFruitPlayerLog.setLMultiple(0);//收获时候,会有一个倍数
|
|
|
ComPlayerLogVo _saleFruitPlayerLogVo = CopyUtil.copy(_saleFruitPlayerLog, ComPlayerLogVo.class);
|
|
|
comPlayerLogService.save(_saleFruitPlayerLogVo);
|
|
|
@@ -415,25 +759,65 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
if (comPlayerGoodsSimpleVo == null) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_DATA_ERROR.getMessage(), ResultEnum.FRUIT_DATA_ERROR.getCode());
|
|
|
}
|
|
|
-
|
|
|
- if (amount > comPlayerGoodsSimpleVo.getAmount()) {
|
|
|
+ //添加了 amountPart,需要加入判断整数部分
|
|
|
+ Integer _userFloorAmount = comPlayerGoodsSimpleVo.getAmount() + (int) Math.floor(comPlayerGoodsSimpleVo.getAmountPart());
|
|
|
+ if (amount > _userFloorAmount) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_ERROR.getMessage(), ResultEnum.FRUIT_AMOUNT_ERROR.getCode());
|
|
|
}
|
|
|
try {
|
|
|
- Integer _selfBeforeAmount = 0;
|
|
|
+ Integer _selfBeforeAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
Integer _selfAfterAmount = 0;
|
|
|
- if (comPlayerGoodsSimpleVo.getAmount().equals(amount)) {
|
|
|
- _selfBeforeAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
- //如果库存量和出售的果实数量一样,删除
|
|
|
- comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
- _selfAfterAmount = 0;
|
|
|
- } else {
|
|
|
- _selfBeforeAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
- comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
+ Double _selfBeforeFruitAmountPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
+ Double _selfAfterFruitAmountPart = 0d;
|
|
|
+ Integer _tAmount = 0;
|
|
|
+ Double _tAmountPart = 0d;
|
|
|
+
|
|
|
+ //if (comPlayerGoodsSimpleVo.getAmount().equals(amount)) {
|
|
|
+ // //如果库存量和出售的果实数量一样,删除
|
|
|
+ // comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
+ // _selfAfterAmount = 0;
|
|
|
+ //} else {
|
|
|
+ // comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
+ // _selfAfterAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ // ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ // comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ //}
|
|
|
+ Integer _amountDif = comPlayerGoodsSimpleVo.getAmount() - amount;
|
|
|
+ //优先处理背包的amount
|
|
|
+ if (_amountDif > 0) {
|
|
|
+ //当前交易值
|
|
|
+ _tAmount = amount;
|
|
|
+ //如果amount 数量足够,直接记录 他们的差值
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(_amountDif);
|
|
|
_selfAfterAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ _selfAfterFruitAmountPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ } else {
|
|
|
+ _selfAfterAmount = 0;
|
|
|
+ //保证精度
|
|
|
+ BigDecimal bigDecimal1 = new BigDecimal(Double.toString(_amountDif));
|
|
|
+ BigDecimal bigDecimal2 = new BigDecimal(Double.toString(comPlayerGoodsSimpleVo.getAmountPart()));
|
|
|
+ BigDecimal _amountPart = bigDecimal1.add(bigDecimal2);
|
|
|
+ //当前交易值,_amountDif 小于0 说明 amount 是全全部扣除,到小数部分了。
|
|
|
+ _tAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ _tAmountPart = Math.abs(bigDecimal1.doubleValue());
|
|
|
+ System.out.print("_amountPart{}," + _amountPart.doubleValue());
|
|
|
+ //前面判断了。所以 _amountPart 不会比0.0小
|
|
|
+ if (_amountPart.compareTo(new BigDecimal(0.0)) <= 0) {
|
|
|
+ //如果库存量 amount 和 amountPart 都为零,删除
|
|
|
+ comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
+ //这里记录一下,看是否会是一个负数
|
|
|
+ _selfAfterFruitAmountPart = _amountPart.doubleValue();
|
|
|
+ } else {
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(0);
|
|
|
+ comPlayerGoodsSimpleVo.setAmountPart(_amountPart.doubleValue());
|
|
|
+ _selfAfterFruitAmountPart = comPlayerGoodsSimpleVo.getAmountPart();
|
|
|
+ ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
//todo 发送果实,记录当前用户的playerLog
|
|
|
//当前用户
|
|
|
ComPlayerLog _selfPlayerLog = new ComPlayerLog();
|
|
|
@@ -478,10 +862,16 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
_targetPlayerLog.setTId(comFruitVo.getId());
|
|
|
_targetPlayerLog.setTName(comFruitVo.getName());
|
|
|
_targetPlayerLog.setTType(3);//接收用户赠送水果,type设置 3
|
|
|
- _targetPlayerLog.setTAmount(amount);
|
|
|
+ _targetPlayerLog.setTAmount(_tAmount);
|
|
|
_targetPlayerLog.setBeforeAmount(_targetBeforeAmount);
|
|
|
////交易后的数据
|
|
|
_targetPlayerLog.setAfterAmount(_targetAfterAmount);
|
|
|
+ //增加一个小数部分记录
|
|
|
+ _targetPlayerLog.setTPart(_tAmountPart);
|
|
|
+ _targetPlayerLog.setTLoss(0d);
|
|
|
+ _targetPlayerLog.setBeforePart(_selfBeforeFruitAmountPart);
|
|
|
+ _targetPlayerLog.setAfterPart(_selfAfterFruitAmountPart);
|
|
|
+
|
|
|
_targetPlayerLog.setLMultiple(0);
|
|
|
ComPlayerLogVo _targetPlayerLogVo = CopyUtil.copy(_targetPlayerLog, ComPlayerLogVo.class);
|
|
|
comPlayerLogService.save(_targetPlayerLogVo);
|