|
|
@@ -3,6 +3,8 @@ package com.td.boss.game.complayergoods.controller;
|
|
|
import com.td.boss.common.controller.*;
|
|
|
import com.td.boss.common.pojo.Result;
|
|
|
import com.td.boss.config.enums.ResultEnum;
|
|
|
+import com.td.boss.game.comexplainland.service.ComExplainLandService;
|
|
|
+import com.td.boss.game.comexplainland.vo.ComExplainLandVo;
|
|
|
import com.td.boss.game.comfruit.pojo.ComFruit;
|
|
|
import com.td.boss.game.comfruit.service.ComFruitService;
|
|
|
import com.td.boss.game.comfruit.vo.ComFruitAmountVo;
|
|
|
@@ -16,10 +18,17 @@ import com.td.boss.game.complayergoods.service.ComPlayerGoodsService;
|
|
|
import com.td.boss.game.complayerland.pojo.ComPlayerLand;
|
|
|
import com.td.boss.game.complayerland.service.ComPlayerLandService;
|
|
|
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.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 net.bytebuddy.asm.Advice;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
@@ -43,6 +52,18 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
@Autowired
|
|
|
private ComUsersService comUsersService;
|
|
|
|
|
|
+ //交易表service
|
|
|
+ @Autowired
|
|
|
+ private ComSnbTranService comSnbTranService;
|
|
|
+
|
|
|
+ //背包操作日志
|
|
|
+ @Autowired
|
|
|
+ private ComPlayerLogService comPlayerLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ComExplainLandService comExplainLandService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取仓库 全部数据,目前使用goods_type区分种子和果实
|
|
|
@@ -94,19 +115,19 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
@RequestParam(value = "currentAmount") Integer currentAmount
|
|
|
) {
|
|
|
//查询背包种子存在的数量
|
|
|
- ComPlayerGoods comPlayerGood = comPlayerGoodsService.findByUserIdAndIndexAndType(userId,seedId,0);
|
|
|
- if(comPlayerGood == null){
|
|
|
+ ComPlayerGoods comPlayerGood = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, seedId, 0);
|
|
|
+ if (comPlayerGood == null) {
|
|
|
//如果背包种子是空的,说明还未添加上去
|
|
|
return Result.of(null, false, ResultEnum.SEED_DATA_ERROR.getMessage(), ResultEnum.SEED_DATA_ERROR.getCode());
|
|
|
}
|
|
|
- if(comPlayerGood.getAmount() <= currentAmount){
|
|
|
+ if (comPlayerGood.getAmount() <= currentAmount) {
|
|
|
//如果背包数量等于或者小于传进来的,提示轮询未更新
|
|
|
return Result.of(null, false, ResultEnum.SEED_AMOUNT_ERROR.getMessage(), ResultEnum.SEED_AMOUNT_ERROR.getCode());
|
|
|
- } else{
|
|
|
+ } else {
|
|
|
Map map = new HashMap();
|
|
|
- map.put("msg","背包种子更新成功!");
|
|
|
- map.put("goodsAmount",comPlayerGood.getAmount());
|
|
|
- map.put("currentAmount",currentAmount);
|
|
|
+ map.put("msg", "背包种子更新成功!");
|
|
|
+ map.put("goodsAmount", comPlayerGood.getAmount());
|
|
|
+ map.put("currentAmount", currentAmount);
|
|
|
return Result.of(map);
|
|
|
}
|
|
|
|
|
|
@@ -116,6 +137,9 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
|
|
|
/**
|
|
|
* 收获时候,传入土地id和种子id
|
|
|
+ * <p>
|
|
|
+ * <p>
|
|
|
+ * 收获时候,操作用户snb时候,需要加锁,防止用户收取时候遗漏计算snb
|
|
|
*
|
|
|
* @param userId
|
|
|
* @param landId
|
|
|
@@ -128,7 +152,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
@RequestParam(value = "userId") String userId,
|
|
|
@RequestParam(value = "landId") Integer landId) {
|
|
|
//todo 确认下是否多倍收成
|
|
|
- ComPlayerLand comPlayerLand = comPlayerLandService.findById(landId);
|
|
|
+ ComPlayerLand comPlayerLand = comPlayerLandService.findByUserIdAndLandId(userId, landId);
|
|
|
//土地数据不存在
|
|
|
if (comPlayerLand == null) {
|
|
|
return Result.of(null, false, ResultEnum.LAND_DATA_ERROR.getMessage(), ResultEnum.LAND_DATA_ERROR.getCode());
|
|
|
@@ -141,53 +165,101 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
if (comPlayerLand.getIsPlant().equals(0)) {
|
|
|
return Result.of(null, false, ResultEnum.LAND_NOT_PLANT.getMessage(), ResultEnum.LAND_NOT_PLANT.getCode());
|
|
|
}
|
|
|
- //
|
|
|
+ //todo 判断土地租赁是否到期,是到期不给种植
|
|
|
+ //租赁的剩余天数 。
|
|
|
+ Long leaseDaysMill = comPlayerLand.getLeaseTime().getTime() - DateUtil.getNowDate().getTime();
|
|
|
+ if(leaseDaysMill <= 0){
|
|
|
+ //todo 清除记录的数据
|
|
|
+ //todo 清除记录的数据
|
|
|
+ // 1.土地租赁到期,删除土地租赁数据
|
|
|
+ comPlayerLandService.delete(comPlayerLand.getId());
|
|
|
+ //todo 2.把删除的这个土地的数据记录到com_explain_land中去
|
|
|
+ ComExplainLandVo comExplainLandVo = new ComExplainLandVo();
|
|
|
+ comExplainLandVo = CopyUtil.copy(comPlayerLand, ComExplainLandVo.class);
|
|
|
+ comExplainLandVo.setLandId(comPlayerLand.getConfigLandId());
|
|
|
+ comExplainLandVo.setLandCreate(comPlayerLand.getCreateTime());
|
|
|
+ comExplainLandVo.setExplainType(0);
|
|
|
+ comExplainLandVo.setExplainDescribe("收获果实时:土地租赁过期回收");
|
|
|
+ comExplainLandVo.setCreateTime(new Date());
|
|
|
+ comExplainLandVo.setUpdateTime(new Date());
|
|
|
+ comExplainLandService.save(comExplainLandVo);
|
|
|
+ return Result.of(null, false, ResultEnum.LAND_LEASE_EXPIRED.getMessage(), ResultEnum.LAND_LEASE_EXPIRED.getCode());
|
|
|
+ }
|
|
|
|
|
|
+ //获取种植的种子
|
|
|
ComMallSeedVo comMallSeedVo = comMallSeedService.findById(comPlayerLand.getPlantId());
|
|
|
-
|
|
|
if (comMallSeedVo == null) {
|
|
|
return Result.of(null, false, ResultEnum.SEED_DATA_ERROR.getMessage(), ResultEnum.SEED_DATA_ERROR.getCode());
|
|
|
}
|
|
|
+
|
|
|
// 收获,同时重置土地状态,先判断是否成熟
|
|
|
//当前时间减去 成熟期,判断是否成熟
|
|
|
- if(DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity()).getTime()<comPlayerLand.getPlantStart().getTime()){
|
|
|
+ Date _harvestTime = DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity());
|
|
|
+ // 两个时间差, 逻辑是_harvestTime 时间慢慢接近种植时间
|
|
|
+ long diff = comPlayerLand.getPlantStart().getTime() - _harvestTime.getTime();
|
|
|
+ //if (DateUtil.getNowDateMinusDay(comMallSeedVo.getMaturity()).getTime() < comPlayerLand.getPlantStart().getTime())
|
|
|
+ if (diff > 0) {
|
|
|
//如果当前时间减去种子的成熟期,还是小于种植日期,则判断未成熟
|
|
|
return Result.of(null, false, ResultEnum.SEED_DATE_ERROR.getMessage(), ResultEnum.SEED_DATE_ERROR.getCode());
|
|
|
}
|
|
|
+ try {
|
|
|
+ //设置一个未种植状态即可
|
|
|
+ comPlayerLand.setIsPlant(0);
|
|
|
+ ComPlayerLandVo comPlayerLandVo = CopyUtil.copy(comPlayerLand, ComPlayerLandVo.class);
|
|
|
+ comPlayerLandService.save(comPlayerLandVo);
|
|
|
+
|
|
|
+ //计算一个收获量, 租赁倍数* 租赁日期下的产量
|
|
|
+ Integer _amount = 0;
|
|
|
+ if (comPlayerLand.getLeaseDate().equals(1)) {
|
|
|
+ _amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
|
|
|
+ } else if (comPlayerLand.getLeaseDate().equals(2)) {
|
|
|
+ _amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
|
|
|
+ } else if (comPlayerLand.getLeaseDate().equals(3)) {
|
|
|
+ _amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
+ }
|
|
|
+ //果实 Type =1
|
|
|
+ //todo 收获果实时候
|
|
|
+ ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, comMallSeedVo.getHarvestId(), 1);
|
|
|
+
|
|
|
+ Integer _beforeAmount = 0;
|
|
|
+ if (comPlayerGoodsSimpleVo == null) {
|
|
|
+ //背包增加一个果实
|
|
|
+ comPlayerGoodsSimpleVo = new ComPlayerGoods();
|
|
|
+ comPlayerGoodsSimpleVo.setUserId(userId);
|
|
|
+ comPlayerGoodsSimpleVo.setGoodsIndex(comMallSeedVo.getHarvestId());
|
|
|
+ comPlayerGoodsSimpleVo.setGoodsType(1);
|
|
|
+ comPlayerGoodsSimpleVo.setName(comMallSeedVo.getHarvestName());
|
|
|
+ //用种子的picture
|
|
|
+ comPlayerGoodsSimpleVo.setPictureName(comMallSeedVo.getPicture());
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(_amount);
|
|
|
+
|
|
|
+ _beforeAmount = 0;
|
|
|
+ } else {
|
|
|
+ _beforeAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() + _amount);
|
|
|
+ }
|
|
|
|
|
|
- //设置一个未种植状态即可
|
|
|
- comPlayerLand.setIsPlant(0);
|
|
|
- ComPlayerLandVo comPlayerLandVo = CopyUtil.copy(comPlayerLand, ComPlayerLandVo.class);
|
|
|
- comPlayerLandService.save(comPlayerLandVo);
|
|
|
-
|
|
|
- //计算一个收获量, 租赁倍数* 租赁日期下的产量
|
|
|
- Integer _amount = 0;
|
|
|
- if (comPlayerLand.getLeaseDate().equals(1)) {
|
|
|
- _amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest1();
|
|
|
- } else if (comPlayerLand.getLeaseDate().equals(2)) {
|
|
|
- _amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest2();
|
|
|
- } else if (comPlayerLand.getLeaseDate().equals(3)) {
|
|
|
- _amount = comPlayerLand.getLeaseMultiple() * comMallSeedVo.getHarvest3();
|
|
|
- }
|
|
|
- //果实 Type =1
|
|
|
- ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId,comMallSeedVo.getHarvestId(), 1);
|
|
|
+ ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
|
|
|
- if (comPlayerGoodsSimpleVo == null) {
|
|
|
- //背包增加一个果实
|
|
|
- comPlayerGoodsSimpleVo = new ComPlayerGoods();
|
|
|
- comPlayerGoodsSimpleVo.setUserId(userId);
|
|
|
- comPlayerGoodsSimpleVo.setGoodsIndex(comMallSeedVo.getHarvestId());
|
|
|
- comPlayerGoodsSimpleVo.setGoodsType(1);
|
|
|
- comPlayerGoodsSimpleVo.setName(comMallSeedVo.getHarvestName());
|
|
|
- //用种子的picture
|
|
|
- comPlayerGoodsSimpleVo.setPictureName(comMallSeedVo.getPicture());
|
|
|
- comPlayerGoodsSimpleVo.setAmount(_amount);
|
|
|
- } else {
|
|
|
- comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() + _amount);
|
|
|
+ //todo 记录一个收获的操作日志
|
|
|
+ ComPlayerLog _playerLog = new ComPlayerLog();
|
|
|
+ _playerLog.setUserId(userId);
|
|
|
+ _playerLog.setTId(comMallSeedVo.getHarvestId());
|
|
|
+ _playerLog.setTName(comMallSeedVo.getHarvestName());
|
|
|
+ _playerLog.setTType(0);//设置一个默认水果id
|
|
|
+ _playerLog.setTAmount(_amount);
|
|
|
+ _playerLog.setBeforeAmount(_beforeAmount);
|
|
|
+ ////交易后的数据
|
|
|
+ _playerLog.setAfterAmount(comPlayerGoodsSimpleVo.getAmount());
|
|
|
+ _playerLog.setLMultiple(comPlayerLand.getLeaseMultiple());
|
|
|
+ ComPlayerLogVo _playerLogVo = CopyUtil.copy(_playerLog, ComPlayerLogVo.class);
|
|
|
+ comPlayerLogService.save(_playerLogVo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
|
|
|
- ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
- comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
Map map = new HashMap();
|
|
|
map.put("msg", "成功收取果实!");
|
|
|
return Result.of(map);
|
|
|
@@ -196,6 +268,8 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
|
|
|
/**
|
|
|
* 出售果实
|
|
|
+ * <p>
|
|
|
+ * todo 需要记录出售果实的snb操作记录
|
|
|
*
|
|
|
* @param userId
|
|
|
* @param amount
|
|
|
@@ -216,32 +290,66 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_DATA_ERROR.getMessage(), ResultEnum.FRUIT_DATA_ERROR.getCode());
|
|
|
}
|
|
|
//果实
|
|
|
- ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId,fruitId, 1);
|
|
|
+ ComPlayerGoods comPlayerGoodsSimpleVo = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, fruitId, 1);
|
|
|
|
|
|
//销售果实数量
|
|
|
if (comPlayerGoodsSimpleVo == null) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_DATA_ERROR.getMessage(), ResultEnum.FRUIT_DATA_ERROR.getCode());
|
|
|
}
|
|
|
|
|
|
- if(amount>comPlayerGoodsSimpleVo.getAmount()){
|
|
|
+ if (amount > comPlayerGoodsSimpleVo.getAmount()) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_ERROR.getMessage(), ResultEnum.FRUIT_AMOUNT_ERROR.getCode());
|
|
|
}
|
|
|
-
|
|
|
- if(comPlayerGoodsSimpleVo.getAmount().equals(amount)){
|
|
|
- //如果库存量和出售的果实数量一样,删除
|
|
|
- comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
- }else{
|
|
|
- comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
- ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
- comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ //todo 销售果实时候,收取5%手续费,最少出售20的倍数
|
|
|
+ // 1.判定销售数量, 如果果实输入是0,或者不是20的倍数,返回提示
|
|
|
+ if (amount.equals(0) || amount % 20 != 0) {
|
|
|
+ return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_IS_ZERO_AND_NOT_MULTIPLE.getMessage(), ResultEnum.FRUIT_AMOUNT_IS_ZERO_AND_NOT_MULTIPLE.getCode());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ if (comPlayerGoodsSimpleVo.getAmount().equals(amount)) {
|
|
|
+ //如果库存量和出售的果实数量一样,删除
|
|
|
+ comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
+ } else {
|
|
|
+ comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
+ ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ }
|
|
|
+ //todo 收取手续费之后
|
|
|
+ int _endAmount = (int) (amount * 0.95);
|
|
|
+ //添加SNB
|
|
|
+ ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
+ //交易前的snb数据
|
|
|
+ Integer _beforeSnb = comUsersVo.getSnb();
|
|
|
+ //数量乘以售价
|
|
|
+ int _saleSnb = comFruitVo.getPriceSnb() * _endAmount; //此时的售价数量已经扣除了手续费,相当于减少了几个果实
|
|
|
+ //当前操作的snb
|
|
|
+ Integer _currentSnb = comUsersVo.getSnb() + _saleSnb;
|
|
|
+ comUsersVo.setSnb(_currentSnb);
|
|
|
+ comUsersService.save(comUsersVo);
|
|
|
+ /**
|
|
|
+ * todo 果实出售snb数据记录
|
|
|
+ */
|
|
|
+ ComSnbTranVo _snbTran = new ComSnbTranVo();
|
|
|
+ //记录果实id
|
|
|
+ _snbTran.setTranId(comFruitVo.getId().toString());
|
|
|
+ _snbTran.setUserId(userId);
|
|
|
+ _snbTran.setTranName(comFruitVo.getName());
|
|
|
+ _snbTran.setTranType(0);
|
|
|
+ _snbTran.setTranAmount(amount); //此数量会操作背包记录
|
|
|
+ _snbTran.setTranPrice(comFruitVo.getPriceSnb());
|
|
|
+ //"出售果实价格:" + comFruitVo.getPriceSnb() + ",数量:" + amount
|
|
|
+ _snbTran.setTranDescribe("扣除5%手续费后果实数量为:" + _endAmount + ",销售价格:" + _saleSnb);
|
|
|
+ _snbTran.setIsAdd(1);//增加收入
|
|
|
+ _snbTran.setBeforeSnb(_beforeSnb);
|
|
|
+ _snbTran.setTranSnb(_saleSnb);
|
|
|
+ _snbTran.setAfterSnb(_currentSnb);
|
|
|
+ comSnbTranService.save(_snbTran);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
|
|
|
- //添加SNB
|
|
|
- ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
- //数量乘以售价
|
|
|
- int _saleSnb = comFruitVo.getPriceSnb()*amount;
|
|
|
- comUsersVo.setSnb(comUsersVo.getSnb()+_saleSnb);
|
|
|
- comUsersService.save(comUsersVo);
|
|
|
+
|
|
|
Map map = new HashMap();
|
|
|
map.put("msg", "成功出售果实!");
|
|
|
return Result.of(map);
|
|
|
@@ -252,7 +360,7 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
* 根据用户地址送果实
|
|
|
*
|
|
|
* @param userId
|
|
|
- * @param address 目标用户地址
|
|
|
+ * @param address 目标用户地址
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("grantFruit")
|
|
|
@@ -266,11 +374,11 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
|
|
|
//目标用户的背包
|
|
|
ComUsersVo _targetUserVo = comUsersService.findByAddress(address);
|
|
|
- if(_targetUserVo == null){
|
|
|
+ if (_targetUserVo == null) {
|
|
|
return Result.of(null, false, ResultEnum.USER_NOT_ADDRESS.getMessage(), ResultEnum.USER_NOT_ADDRESS.getCode());
|
|
|
}
|
|
|
|
|
|
- if(_targetUserVo.getUserId().equals(userId)){
|
|
|
+ if (_targetUserVo.getUserId().equals(userId)) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_SEND_SELF.getMessage(), ResultEnum.FRUIT_SEND_SELF.getCode());
|
|
|
}
|
|
|
|
|
|
@@ -287,40 +395,80 @@ public class ComPlayerGoodsController extends CommonController<ComPlayerGoodsVo,
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_DATA_ERROR.getMessage(), ResultEnum.FRUIT_DATA_ERROR.getCode());
|
|
|
}
|
|
|
|
|
|
- if(amount>comPlayerGoodsSimpleVo.getAmount()){
|
|
|
+ if (amount > comPlayerGoodsSimpleVo.getAmount()) {
|
|
|
return Result.of(null, false, ResultEnum.FRUIT_AMOUNT_ERROR.getMessage(), ResultEnum.FRUIT_AMOUNT_ERROR.getCode());
|
|
|
}
|
|
|
-
|
|
|
- if(comPlayerGoodsSimpleVo.getAmount().equals(amount)){
|
|
|
- //如果库存量和出售的果实数量一样,删除
|
|
|
- comPlayerGoodsService.delete(comPlayerGoodsSimpleVo.getGoodsId());
|
|
|
- }else{
|
|
|
- comPlayerGoodsSimpleVo.setAmount(comPlayerGoodsSimpleVo.getAmount() - amount);
|
|
|
- ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
- comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ try {
|
|
|
+ Integer _selfBeforeAmount = 0;
|
|
|
+ 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);
|
|
|
+ _selfAfterAmount = comPlayerGoodsSimpleVo.getAmount();
|
|
|
+ ComPlayerGoodsVo comPlayerGoodsVo = CopyUtil.copy(comPlayerGoodsSimpleVo, ComPlayerGoodsVo.class);
|
|
|
+ comPlayerGoodsService.save(comPlayerGoodsVo);
|
|
|
+ }
|
|
|
+ //todo 发送果实,记录当前用户的playerLog
|
|
|
+ //当前用户
|
|
|
+ ComPlayerLog _selfPlayerLog = new ComPlayerLog();
|
|
|
+ _selfPlayerLog.setUserId(userId);
|
|
|
+ _selfPlayerLog.setTId(comFruitVo.getId());
|
|
|
+ _selfPlayerLog.setTName(comFruitVo.getName());
|
|
|
+ _selfPlayerLog.setTType(2);//发送水果的类型:2
|
|
|
+ _selfPlayerLog.setTAmount(amount);
|
|
|
+ _selfPlayerLog.setBeforeAmount(_selfBeforeAmount);
|
|
|
+ ////交易后的数据
|
|
|
+ _selfPlayerLog.setAfterAmount(_selfAfterAmount);
|
|
|
+ _selfPlayerLog.setLMultiple(0);//收获时候,会有一个倍数
|
|
|
+ ComPlayerLogVo _selfPlayerLogVo = CopyUtil.copy(_selfPlayerLog, ComPlayerLogVo.class);
|
|
|
+ comPlayerLogService.save(_selfPlayerLogVo);
|
|
|
+
|
|
|
+ //接受人的背包数据
|
|
|
+ ComPlayerGoods _targetGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(_targetUserVo.getUserId(), comFruitVo.getId(), 1);
|
|
|
+ Integer _targetBeforeAmount = 0;
|
|
|
+ Integer _targetAfterAmount = 0;
|
|
|
+ if (_targetGoods == null) {
|
|
|
+ //背包增加一个果实
|
|
|
+ _targetGoods = new ComPlayerGoods();
|
|
|
+ //目标id
|
|
|
+ _targetGoods.setUserId(_targetUserVo.getUserId());
|
|
|
+ _targetGoods.setGoodsIndex(comFruitVo.getId());
|
|
|
+ _targetGoods.setGoodsType(1);
|
|
|
+ _targetGoods.setName(comFruitVo.getName());
|
|
|
+ //用种子的picture
|
|
|
+ _targetGoods.setPictureName(comFruitVo.getPicture());
|
|
|
+ _targetGoods.setAmount(amount);
|
|
|
+ _targetAfterAmount = _targetGoods.getAmount();
|
|
|
+ } else {
|
|
|
+ _targetBeforeAmount = _targetGoods.getAmount();
|
|
|
+ _targetGoods.setAmount(_targetGoods.getAmount() + amount);
|
|
|
+ _targetAfterAmount = _targetGoods.getAmount();
|
|
|
+ }
|
|
|
+ ComPlayerGoodsVo _targetGoodsVo = CopyUtil.copy(_targetGoods, ComPlayerGoodsVo.class);
|
|
|
+ comPlayerGoodsService.save(_targetGoodsVo);
|
|
|
+ //todo 接收果实,记录目标用户的playerLog
|
|
|
+ ComPlayerLog _targetPlayerLog = new ComPlayerLog();
|
|
|
+ _targetPlayerLog.setUserId(_targetUserVo.getUserId());
|
|
|
+ _targetPlayerLog.setTId(comFruitVo.getId());
|
|
|
+ _targetPlayerLog.setTName(comFruitVo.getName());
|
|
|
+ _targetPlayerLog.setTType(3);//接收用户赠送水果,type设置 3
|
|
|
+ _targetPlayerLog.setTAmount(amount);
|
|
|
+ _targetPlayerLog.setBeforeAmount(_targetBeforeAmount);
|
|
|
+ ////交易后的数据
|
|
|
+ _targetPlayerLog.setAfterAmount(_targetAfterAmount);
|
|
|
+ _targetPlayerLog.setLMultiple(0);
|
|
|
+ ComPlayerLogVo _targetPlayerLogVo = CopyUtil.copy(_targetPlayerLog, ComPlayerLogVo.class);
|
|
|
+ comPlayerLogService.save(_targetPlayerLogVo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- //接受人的背包数据
|
|
|
- ComPlayerGoods _targetGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(_targetUserVo.getUserId(),comFruitVo.getId(), 1);
|
|
|
- if (_targetGoods == null) {
|
|
|
- //背包增加一个果实
|
|
|
- _targetGoods = new ComPlayerGoods();
|
|
|
- //目标id
|
|
|
- _targetGoods.setUserId(_targetUserVo.getUserId());
|
|
|
- _targetGoods.setGoodsIndex(comFruitVo.getId());
|
|
|
- _targetGoods.setGoodsType(1);
|
|
|
- _targetGoods.setName(comFruitVo.getName());
|
|
|
- //用种子的picture
|
|
|
- _targetGoods.setPictureName(comFruitVo.getPicture());
|
|
|
- _targetGoods.setAmount(amount);
|
|
|
- } else {
|
|
|
- _targetGoods.setAmount(_targetGoods.getAmount() + amount);
|
|
|
- }
|
|
|
- ComPlayerGoodsVo _targetGoodsVo = CopyUtil.copy(_targetGoods, ComPlayerGoodsVo.class);
|
|
|
- comPlayerGoodsService.save(_targetGoodsVo);
|
|
|
-
|
|
|
Map map = new HashMap();
|
|
|
map.put("msg", "成功发送果实!");
|
|
|
return Result.of(map);
|