|
|
@@ -4,6 +4,7 @@ import com.td.boss.common.pojo.Result;
|
|
|
import com.td.boss.common.service.CommonServiceImpl;
|
|
|
import com.td.boss.game.commallseed.service.ComMallSeedService;
|
|
|
import com.td.boss.game.commallseed.vo.ComMallSeedVo;
|
|
|
+import com.td.boss.game.complayergoods.pojo.ComPlayerGoods;
|
|
|
import com.td.boss.game.complayergoods.service.ComPlayerGoodsService;
|
|
|
import com.td.boss.game.complayergoods.vo.ComPlayerGoodsVo;
|
|
|
import com.td.boss.game.complayerscore.pojo.ComPlayerScore;
|
|
|
@@ -11,6 +12,7 @@ import com.td.boss.game.complayerscore.repository.ComPlayerScoreRepository;
|
|
|
import com.td.boss.game.complayerscore.vo.ComPlayerScoreVo;
|
|
|
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.DappUtil;
|
|
|
import com.td.boss.util.UUIDUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -20,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.persistence.EntityManager;
|
|
|
import javax.persistence.PersistenceContext;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreVo, ComPlayerScore, Integer> implements ComPlayerScoreService {
|
|
|
@@ -45,7 +49,7 @@ public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreV
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Result<String> exchange(String userId,
|
|
|
+ public Result<Map> exchange(String userId,
|
|
|
Integer amount,
|
|
|
Integer seedId) {
|
|
|
ComUsersVo comUsersVo = comUsersService.findByUserId(userId);
|
|
|
@@ -58,8 +62,8 @@ public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreV
|
|
|
return Result.of(null, false, "消费土地的总cnt不足");
|
|
|
}
|
|
|
ComMallSeedVo mallSeed = comMallSeedService.findById(seedId);
|
|
|
- // 5 = 固定积分兑换种子
|
|
|
- if (mallSeed == null || mallSeed.getAmount().equals(0) || !"5".equals(mallSeed.getMallType())) {
|
|
|
+ // 固定积分兑换种子,使用的是已存在的种子
|
|
|
+ if (mallSeed == null || mallSeed.getAmount().equals(0) || !mallSeed.getMallType().equals(0)) {
|
|
|
return Result.of(null, false, "种子不存在或已被下架");
|
|
|
}
|
|
|
// 本次总消费
|
|
|
@@ -85,20 +89,42 @@ public class ComPlayerScoreServiceImpl extends CommonServiceImpl<ComPlayerScoreV
|
|
|
comPlayerScore.setPriceCnt(mallSeed.getPriceCnt());
|
|
|
comPlayerScore.setCreateTime(new Date());
|
|
|
comPlayerScoreRepository.save(comPlayerScore);
|
|
|
- // 保存进仓库
|
|
|
- ComPlayerGoodsVo comPlayerGoods = new ComPlayerGoodsVo();
|
|
|
- comPlayerGoods.setGoodsId(UUIDUtil.getUUID());
|
|
|
- comPlayerGoods.setGoodsIndex(seedId);
|
|
|
- comPlayerGoods.setGoodsType(0);
|
|
|
- comPlayerGoods.setUserId(userId);
|
|
|
- comPlayerGoods.setName(mallSeed.getName());
|
|
|
- comPlayerGoods.setPictureName(mallSeed.getPicture());
|
|
|
- comPlayerGoods.setAmount(amount);
|
|
|
- comPlayerGoods.setAmountPart(0d);
|
|
|
- comPlayerGoods.setCreateTime(new Date());
|
|
|
- comPlayerGoods.setMallType(0);
|
|
|
- comPlayerGoodsService.save(comPlayerGoods);
|
|
|
+ // 保存进仓库,处理种子
|
|
|
|
|
|
- return Result.of(null, true, "兑换成功");
|
|
|
+ ComPlayerGoods comPlayerGoods = comPlayerGoodsService.findByUserIdAndIndexAndType(userId, seedId, 0);
|
|
|
+ if(comPlayerGoods == null){
|
|
|
+ comPlayerGoods = new ComPlayerGoods();
|
|
|
+ comPlayerGoods.setGoodsIndex(seedId);
|
|
|
+ comPlayerGoods.setGoodsType(0);
|
|
|
+ comPlayerGoods.setUserId(userId);
|
|
|
+ comPlayerGoods.setName(mallSeed.getName());
|
|
|
+ comPlayerGoods.setPictureName(mallSeed.getPicture());
|
|
|
+ comPlayerGoods.setAmount(amount);
|
|
|
+ comPlayerGoods.setAmountPart(0d);
|
|
|
+ comPlayerGoods.setMallType(0);
|
|
|
+ }else{
|
|
|
+ Integer _amount = comPlayerGoods.getAmount() + amount;
|
|
|
+ comPlayerGoods.setAmount(_amount);
|
|
|
+ }
|
|
|
+ comPlayerGoodsService.save(CopyUtil.copy(comPlayerGoods,ComPlayerGoodsVo.class));
|
|
|
+
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("score", getScore(userId));
|
|
|
+ return Result.of( map,true, "兑换成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Map getScore(String userId) {
|
|
|
+ // 链端获取cnt总数
|
|
|
+ Integer totalCount = DappUtil.getChildrenBuyLandAmount(userId);
|
|
|
+ Integer oldTotalCnt = comPlayerScoreRepository.findAllByUserId(userId).stream()
|
|
|
+ .map(ComPlayerScore::getTotalCnt).reduce(0, Integer::sum);
|
|
|
+
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("totalCount",totalCount);
|
|
|
+ map.put("oldTotalCnt",oldTotalCnt);
|
|
|
+ return map;
|
|
|
}
|
|
|
}
|