|
|
@@ -18,23 +18,25 @@ import com.td.boss.game.complayersattri.pojo.ComPlayersAttri;
|
|
|
import com.td.boss.game.complayersattri.pojo.ComPlayersLucky;
|
|
|
import com.td.boss.game.complayersattri.repository.ComPlayersAttriRepository;
|
|
|
import com.td.boss.game.complayersattri.repository.ComPlayersLuckyRepository;
|
|
|
+import com.td.boss.game.complayersattri.vo.ComPlayersAttriSimpleVo;
|
|
|
import com.td.boss.game.complayersattri.vo.ComPlayersLuckyLandLevelUpVo;
|
|
|
import com.td.boss.game.complayersattri.vo.ComPlayersLuckyToolsVo;
|
|
|
import com.td.boss.game.complayersattri.vo.ComPlayersLuckyVo;
|
|
|
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.ComUsersSimpleVo;
|
|
|
import com.td.boss.game.comusers.vo.ComUsersVo;
|
|
|
+import com.td.boss.util.CopyUtil;
|
|
|
import com.td.boss.util.RedisData;
|
|
|
import com.td.boss.util.RedisLock;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import javax.persistence.EntityManager;
|
|
|
+import javax.persistence.PersistenceContext;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@@ -121,38 +123,48 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
//更新幸运值
|
|
|
playersAttri.setLucky(afterLucky);
|
|
|
comPlayersAttriRepository.save(playersAttri);
|
|
|
- return Result.of(null, true, "使用工具成功");
|
|
|
+ Map map = new HashMap();
|
|
|
+ ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttri, ComPlayersAttriSimpleVo.class);
|
|
|
+ map.put("playerAttribute", comPlayersAttriSimpleVo);
|
|
|
+
|
|
|
+ return Result.of(map, true, "使用工具成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 土地升级
|
|
|
*
|
|
|
* @param userId
|
|
|
- * @param levelId
|
|
|
- * @param landId
|
|
|
+ * @param configLandId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Result<?> landLevelUp(String userId, Integer levelId, Integer landId) {
|
|
|
+ public Result<?> landLevelUp(String userId, Integer configLandId) {
|
|
|
//验证土地级别是否存在
|
|
|
- ComPlayersLuckyLandLevelUpVo landLevelUpVo = getLandLevelUp().stream().filter(a -> a.getId().equals(levelId)).findFirst().orElse(null);
|
|
|
- if (landLevelUpVo == null) {
|
|
|
- return Result.of(null, false, "升级失败,无效升级!");
|
|
|
- }
|
|
|
+ //ComPlayersLuckyLandLevelUpVo landLevelUpVo = getLandLevelUp().stream().filter(a -> a.getId().equals(levelId)).findFirst().orElse(null);
|
|
|
+ //if (landLevelUpVo == null) {
|
|
|
+ // return Result.of(null, false, "升级失败,无效升级!");
|
|
|
+ //}
|
|
|
//验证土地是否存在
|
|
|
- ComPlayerLand comPlayerLand = comPlayerLandRepository.findById(landId).orElse(null);
|
|
|
+ ComPlayerLand comPlayerLand = comPlayerLandRepository.findByUserIdAndConfigLandId(userId, configLandId).orElse(null);
|
|
|
if (comPlayerLand == null || comPlayerLand.getUserId().equals(userId) == false) {
|
|
|
return Result.of(null, false, "升级失败,无效土地!");
|
|
|
}
|
|
|
- //验证 将要升级的土地级别是否大于当前土地级别
|
|
|
- if (comPlayerLand.getLandLevel() >= levelId) {
|
|
|
- return Result.of(null, false, "升级失败,无效级别!");
|
|
|
- }
|
|
|
//土地租赁到期了,不能升级
|
|
|
if (comPlayerLand.getLeaseTime().before(new Date())) {
|
|
|
return Result.of(null, false, "升级失败,土地已到期!");
|
|
|
}
|
|
|
+ //Slambb added code
|
|
|
+ //直接获取升级的 levelId
|
|
|
+ Integer levelId = comPlayerLand.getLandLevel() == null ? 1 : comPlayerLand.getLandLevel() + 1;
|
|
|
+ ComPlayersLuckyLandLevelUpVo landLevelUpVo = getLandLevelUp().stream().filter(a -> a.getId().equals(levelId)).findFirst().orElse(null);
|
|
|
+ if (landLevelUpVo == null) {
|
|
|
+ return Result.of(null, false, "升级失败,无效升级!");
|
|
|
+ }
|
|
|
+ //验证 将要升级的土地级别是否大于当前土地级别
|
|
|
+ //if (comPlayerLand.getLandLevel() >= levelId) {
|
|
|
+ // return Result.of(null, false, "升级失败,无效级别!");
|
|
|
+ //}
|
|
|
|
|
|
long time = System.currentTimeMillis() + RedisData.getPlayerLandLevelupTimeout();
|
|
|
String _redisKey = "LOCK:COM_PLAYER_LAND_LEVELUP:" + userId;
|
|
|
@@ -177,7 +189,7 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
comPlayersLucky.setLuckyType(ComPlayerLuckyLogEnum.level.getCode());
|
|
|
comPlayersLucky.setLuckyName(landLevelUpVo.getName());
|
|
|
comPlayersLucky.setLevelId(levelId);
|
|
|
- comPlayersLucky.setLandId(landId);
|
|
|
+ comPlayersLucky.setLandId(configLandId);
|
|
|
comPlayersLucky.setUserId(userId);
|
|
|
comPlayersLucky.setCreateTime(new Date());
|
|
|
repository.save(comPlayersLucky);
|
|
|
@@ -189,7 +201,7 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
//更新土地级别
|
|
|
comPlayerLand.setLandLevel(levelId);
|
|
|
comPlayerLandRepository.save(comPlayerLand);
|
|
|
- return Result.of(null, true, "升级成功");
|
|
|
+ return Result.of(landLevelUpVo, true, "升级成功");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -224,10 +236,10 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
return Result.of(null, false, ResultEnum.SEED_SALE_SAVE_LOCK.getMessage(), ResultEnum.SEED_SALE_SAVE_LOCK.getCode());
|
|
|
}
|
|
|
//获得snb用户对象
|
|
|
- ComUsersVo player = comUsersService.findByUserId(userId);
|
|
|
+ //ComUsersVo player = comUsersService.findByUserId(userId);
|
|
|
//获得幸运值用户对象
|
|
|
ComPlayersAttri playersAttri = comPlayersAttriRepository.findByUserId(userId).orElse(null);
|
|
|
- if (playersAttri == null || player == null) {
|
|
|
+ if (playersAttri == null || comUsersVo == null) {
|
|
|
return Result.of(null, false, "无效用户");
|
|
|
}
|
|
|
//剩余幸运值
|
|
|
@@ -238,16 +250,22 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
//兑换snb数量
|
|
|
int snbNum = luckNum / snb;
|
|
|
//插入明细
|
|
|
- mingxi(userId, luckNum, playersAttri.getLucky(), player.getSnb(), snbNum);
|
|
|
+ mingxi(userId, luckNum, playersAttri.getLucky(), comUsersVo.getSnb(), snbNum,comUsersVo.getSnbPart());
|
|
|
|
|
|
//更新用户snb
|
|
|
- player.setSnb(player.getSnb() + snbNum);
|
|
|
- comUsersService.save(player);
|
|
|
+ comUsersVo.setSnb(comUsersVo.getSnb() + snbNum);
|
|
|
+ comUsersService.save(comUsersVo);
|
|
|
|
|
|
//更新用户幸运值
|
|
|
playersAttri.setLucky(num);
|
|
|
comPlayersAttriRepository.save(playersAttri);
|
|
|
- return Result.of(null, true, StrUtil.format("成功兑换{}个snb,消耗{}个幸运值", snbNum, luckNum));
|
|
|
+
|
|
|
+ Map map = new HashMap();
|
|
|
+ ComPlayersAttriSimpleVo comPlayersAttriSimpleVo = CopyUtil.copy(playersAttri, ComPlayersAttriSimpleVo.class);
|
|
|
+ map.put("playerAttribute",comPlayersAttriSimpleVo);
|
|
|
+ map.put("userInfo", CopyUtil.copy(comUsersVo, ComUsersSimpleVo.class));
|
|
|
+
|
|
|
+ return Result.of(map, true, StrUtil.format("成功兑换{}个snb,消耗{}个幸运值", snbNum, luckNum));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -257,7 +275,7 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
* @param beforeSNB 兑换前的snb数量
|
|
|
* @param snbNum 兑换snb的数量
|
|
|
*/
|
|
|
- private void mingxi(String userId, int luckNum, int beforeLuck, int beforeSNB, int snbNum) {
|
|
|
+ private void mingxi(String userId, int luckNum, int beforeLuck, int beforeSNB, int snbNum,double snbPart) {
|
|
|
//记录幸运值明细
|
|
|
ComPlayersLucky comPlayersLucky = new ComPlayersLucky();
|
|
|
comPlayersLucky.setAfterLucky(beforeLuck - luckNum);
|
|
|
@@ -278,7 +296,7 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
//记录兑换id
|
|
|
snbTran.setTranId(Convert.toStr(comPlayersLucky.getId()));
|
|
|
snbTran.setUserId(userId);
|
|
|
- snbTran.setTranName("兑换SNB");
|
|
|
+ snbTran.setTranName(StrUtil.format("幸运值{}兑换SNB", luckNum));
|
|
|
snbTran.setTranType(9);
|
|
|
snbTran.setTranAmount(snbNum);
|
|
|
snbTran.setTranDescribe(StrUtil.format("user幸运值兑换SNB、本次兑换:{},消耗:{}幸运值", snbNum, luckNum));
|
|
|
@@ -288,8 +306,8 @@ public class ComPlayersLuckyServiceImpl extends CommonServiceImpl<ComPlayersLuck
|
|
|
snbTran.setAfterSnb(beforeSNB + snbNum);
|
|
|
snbTran.setCreateTime(new Date());
|
|
|
snbTran.setTranSnbPart(0d);
|
|
|
- snbTran.setAfterSnbPart(0d);
|
|
|
- snbTran.setBeforeSnbPart(0d);
|
|
|
+ snbTran.setAfterSnbPart(snbPart);
|
|
|
+ snbTran.setBeforeSnbPart(snbPart);
|
|
|
snbTran.setTranAmountPart(0d);
|
|
|
snbTran.setTranPrice(0);
|
|
|
comSnbTranService.save(snbTran);
|