Ver código fonte

修改为保留4位小数

dos 2 meses atrás
pai
commit
50e4e7ee81

+ 15 - 15
game-business/src/main/java/com/game/business/controller/AppAgentController.java

@@ -123,7 +123,7 @@ public class AppAgentController extends BaseController {
                     double winLose = 0;
                     winLose = AppUserAgent.calMoney(e, winLose);
                     if (winLose > 0) {
-                        return BigDecimal.valueOf(winLose * e.getDividendGuaranteeRate() / 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                        return BigDecimal.valueOf(winLose * e.getDividendGuaranteeRate() / 100).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
                     } else {
                         return 0;
                     }
@@ -137,7 +137,7 @@ public class AppAgentController extends BaseController {
             }).sum();
 
             if(winLose > 0){
-                money +=  BigDecimal.valueOf(winLose * teamUser.getDividendGuaranteeRate() / 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                money +=  BigDecimal.valueOf(winLose * teamUser.getDividendGuaranteeRate() / 100).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
             }
 
         }
@@ -149,33 +149,33 @@ public class AppAgentController extends BaseController {
             money = 0;
         }*/
         //预计分红
-        vo.setMyCommission(BigDecimal.valueOf(money>0?money:0).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
-        vo.setLiveCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getLiveCommission()).sum()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
-        vo.setGameCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getGameCommission()).sum()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setMyCommission(BigDecimal.valueOf(money>0?money:0).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setLiveCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getLiveCommission()).sum()).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setGameCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getGameCommission()).sum()).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队人数
         vo.setTeamUser(appUserAgentList.stream().collect(Collectors.toList()).size());
         //团队充值
         vo.setTeamRecharge(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->{
             return e.getRechargeAmount();
-        }).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        }).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队充值赠送金额
-        vo.setRechargeGive(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getRechargeGive()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setRechargeGive(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getRechargeGive()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队充值手续费
-        vo.setRechargeCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getRechargeCommission()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setRechargeCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getRechargeCommission()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队提现手续费
-        vo.setWithdrawalCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getWithdrawalCommission()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setWithdrawalCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getWithdrawalCommission()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队投注
-        vo.setTeamBetting(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getGameBetting()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setTeamBetting(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getGameBetting()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队直播消费
-        vo.setTeamLive(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getLiveUseAmount()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setTeamLive(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getLiveUseAmount()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队投注赢
         vo.setTeamWin(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(
                 e->{
                     return e.getGameWinAmount();
                 }
-        ).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        ).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //团队投注输
-        vo.setTeamLose(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getGameLoseAmount()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setTeamLose(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(e->e.getGameLoseAmount()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //活跃人数
         vo.setActiveUser(appUserCountList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()-> new TreeSet<>(Comparator.comparing(f->f.getUserId()))), ArrayList::new)).size());
         //昨日新增
@@ -189,9 +189,9 @@ public class AppAgentController extends BaseController {
 
         //直播收益
         Long finalUserId = userId;
-        vo.setLiveProfit(BigDecimal.valueOf(appUserCountList.stream().filter(e->e.getUserId().equals(finalUserId)).mapToDouble(e->e.getLiveProfit()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setLiveProfit(BigDecimal.valueOf(appUserCountList.stream().filter(e->e.getUserId().equals(finalUserId)).mapToDouble(e->e.getLiveProfit()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
         //直播邀请奖励
-        vo.setLiveInvite(BigDecimal.valueOf(appUserCountList.stream().filter(e->e.getUserId().equals(finalUserId)).mapToDouble(e->e.getLiveInvite()).sum()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+        vo.setLiveInvite(BigDecimal.valueOf(appUserCountList.stream().filter(e->e.getUserId().equals(finalUserId)).mapToDouble(e->e.getLiveInvite()).sum()).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue());
 
         return HttpRet.success(MessageUtils.message("11022"),vo);
     }

+ 1 - 1
game-business/src/main/java/com/game/business/controller/AppGameItemController.java

@@ -108,7 +108,7 @@ public class AppGameItemController extends BaseController
                 }else{
                     BigDecimal lotteryCount = new BigDecimal(gameItem.getLotteryCount());
                     BigDecimal lotteryRate = lotteryCount.divide(lotteryCountSum,4, BigDecimal.ROUND_HALF_UP);
-                    appGameItemVO.setLotteryRate(lotteryRate.multiply(new BigDecimal(100)).setScale(2,  BigDecimal.ROUND_HALF_UP).toString());
+                    appGameItemVO.setLotteryRate(lotteryRate.multiply(new BigDecimal(100)).setScale(4,  BigDecimal.ROUND_HALF_UP).toString());
                 }
 
                 resultList.add(appGameItemVO);

+ 3 - 3
game-business/src/main/java/com/game/business/controller/AppUserController.java

@@ -180,10 +180,10 @@ public class AppUserController extends BaseController
                 rateTran.setId(null);
                 BeanUtils.copyProperties(tran,rateTran);
                 if(TranCurrencyType.Balance.getType() == rateTran.getCurrencyType()){
-                    rate = BigDecimal.valueOf(rateTran.getDiamondCoinChange() * userChargeDto.getRate()).setScale(2,BigDecimal.ROUND_HALF_UP);
+                    rate = BigDecimal.valueOf(rateTran.getDiamondCoinChange() * userChargeDto.getRate()).setScale(4,BigDecimal.ROUND_HALF_UP);
                     rateTran.setDiamondCoinChange(rate.doubleValue() * -1);
                 }else if(TranCurrencyType.Coin.getType() == rateTran.getCurrencyType()){
-                    rate = BigDecimal.valueOf(rateTran.getCoinChange() * userChargeDto.getRate()).setScale(2,BigDecimal.ROUND_HALF_UP);
+                    rate = BigDecimal.valueOf(rateTran.getCoinChange() * userChargeDto.getRate()).setScale(4,BigDecimal.ROUND_HALF_UP);
                     rateTran.setCoinChange(rate.doubleValue() * -1);
                 }
                 /*rateTran.setTranType3(FinTranType3.CHARGE_OUT_RATE.getType());
@@ -201,7 +201,7 @@ public class AppUserController extends BaseController
                 double giveRate = todayGiveMoney>0?0.02:0.1; //当然首充10% 否则2%
                 if(todayGiveMoney < 2000) { //当日2000封顶
                     give = BigDecimal.valueOf(userChargeDto.getAmount().doubleValue()
-                            * giveRate).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                            * giveRate).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
                     if((give + todayGiveMoney) > 2000){
                         give = give - (give + todayGiveMoney - 2000); //赠送金额超过2000则扣减多出的余额
                     }

+ 8 - 8
game-business/src/main/java/com/game/business/service/impl/AppUserAgentServiceImpl.java

@@ -256,35 +256,35 @@ public class AppUserAgentServiceImpl extends ServiceImpl<AppUserAgentMapper, App
                         if (null != appUserCountList && appUserCountList.size() > 0) {
                             DecimalFormat df = new DecimalFormat("#.##");
                             //下注金额
-                            e.setBettingAmount(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getGameBetting).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            e.setBettingAmount(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getGameBetting).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //直播返点
-                            e.setLiveCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getLiveCommission).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            e.setLiveCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getLiveCommission).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //游戏返点
                             e.setGameCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(j->
                                 {
                                     return j.getGameCommission() - j.getLiveBettingCommission() + j.getRechargeCommission() + j.getWithdrawalCommission();
                                 }
-                            ).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            ).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //直播间下注返点
                             e.setLiveBettingCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(j->
                                 {
                                     return j.getLiveBettingCommission();
                                 }
-                            ).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            ).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //盈亏
                             e.setGameAmount(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(userCount -> {
                                 return ((userCount.getGameWinAmount() - (userCount.getGameBetting() - userCount.getGameLoseAmount()))
                                         - userCount.getGameLoseAmount()) + userCount.getGameCommission() + userCount.getRechargeGive()
                                         + userCount.getRechargeCommission() + userCount.getWithdrawalCommission();
-                            }).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            }).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //充值金额(由于统计的金额是扣除了手续费并且加上赠送金额的值 故这么计算出原始充值金额)
                             e.setRechargeAmount(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(userCount -> {
                                 return userCount.getRechargeAmount();
-                            }).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            }).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //充值手续费
-                            e.setRechargeCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getRechargeCommission).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            e.setRechargeCommission(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getRechargeCommission).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                             //充值赠送金额
-                            e.setRechargeGive(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getRechargeGive).sum()).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                            e.setRechargeGive(BigDecimal.valueOf(appUserCountList.stream().mapToDouble(AppUserCount::getRechargeGive).sum()).setScale(4, RoundingMode.DOWN).doubleValue());
                         } else {
                             //下注金额
                             e.setBettingAmount(0.00);

+ 5 - 4
game-business/src/main/java/com/game/business/task/AppAgentGameBettingTask.java

@@ -134,7 +134,7 @@ public class AppAgentGameBettingTask {
         BigDecimal gameRate = new BigDecimal((topCommission.getGameRate() / 100.00) + "");
 
         // 总佣金
-        BigDecimal bettingCommission = bettingAmount.multiply(gameRate).setScale(1, BigDecimal.ROUND_HALF_DOWN);
+        BigDecimal bettingCommission = bettingAmount.multiply(gameRate).setScale(1, RoundingMode.DOWN);
 
         AppGameBetting updateBettingCommission = new AppGameBetting();
         updateBettingCommission.setId(appGameBetting.getId());
@@ -158,8 +158,8 @@ public class AppAgentGameBettingTask {
 
             if(appGameCommission.getGameRate() > 0){
                 // 计算佣金
-                userGgameRate = new BigDecimal(((appGameCommission.getGameRate() - indexCommission) / 100.00) + "").setScale(4, BigDecimal.ROUND_HALF_DOWN);
-                userCommission = bettingAmount.multiply(userGgameRate).setScale(2, BigDecimal.ROUND_HALF_DOWN);
+                userGgameRate = new BigDecimal(((appGameCommission.getGameRate() - indexCommission) / 100.00) + "").setScale(4, RoundingMode.DOWN);
+                userCommission = bettingAmount.multiply(userGgameRate).setScale(4, RoundingMode.DOWN);
             }
 
             // 上一次费率
@@ -271,7 +271,7 @@ public class AppAgentGameBettingTask {
 
         // 主播分佣
         double gameRateAmount = appGameBetting.getBettingAmount() * 0.003;
-        gameRateAmount = new BigDecimal(gameRateAmount + "").setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
+        gameRateAmount = new BigDecimal(gameRateAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
 
         // 更新用户余额
         //if(appGameBetting.getBettingType() == 0){
@@ -363,4 +363,5 @@ public class AppAgentGameBettingTask {
         appUserService.updateUserAmount(finTranRecord);
 
     }
+
 }

+ 3 - 2
game-business/src/main/java/com/game/business/task/AppGameBettingTask.java

@@ -22,6 +22,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -460,7 +461,7 @@ public class AppGameBettingTask {
             List<String> bettingItemsList = Arrays.asList(bettingItems);
 
             double bettingAmount = appGameBetting.getBettingAmount() * appGameBetting.getBettingMultiple();
-            bettingAmount = new BigDecimal(bettingAmount + "").setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
+            bettingAmount = new BigDecimal(bettingAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
 
             if(appGameBetting.getBettingGameType() == 0){
                 if(!bettingItemsList.contains(appGameBetting.getBettingItem())){
@@ -496,7 +497,7 @@ public class AppGameBettingTask {
                         AppGameItemBettingVO appGameItemBettingVO = itemList.get(k);
                         if(bettingItemsList.contains(appGameItemBettingVO.getBettingItem())){
                             bettingAmount = appGameBetting.getBettingAmount() * appGameItemBettingVO.getBettingMultiple();
-                            bettingAmount = new BigDecimal(bettingAmount + "").setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
+                            bettingAmount = new BigDecimal(bettingAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
                             break;
                         }
                     }

+ 3 - 2
game-business/src/main/java/com/game/business/task/AppGameLotteryTask.java

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
@@ -98,7 +99,7 @@ public class AppGameLotteryTask {
             List<String> bettingItemsList = Arrays.asList(bettingItems);
 
             double bettingAmount = appGameBetting.getBettingAmount() * appGameBetting.getBettingMultiple();
-            bettingAmount = new BigDecimal(bettingAmount + "").setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
+            bettingAmount = new BigDecimal(bettingAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
 
             if(appGameBetting.getBettingGameType() == 0){
                 if(!bettingItemsList.contains(appGameBetting.getBettingItem())){
@@ -134,7 +135,7 @@ public class AppGameLotteryTask {
                         AppGameItemBettingVO appGameItemBettingVO = itemList.get(k);
                         if(bettingItemsList.contains(appGameItemBettingVO.getBettingItem())){
                             bettingAmount = appGameBetting.getBettingAmount() * appGameItemBettingVO.getBettingMultiple();
-                            bettingAmount = new BigDecimal(bettingAmount + "").setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
+                            bettingAmount = new BigDecimal(bettingAmount + "").setScale(4, RoundingMode.DOWN).doubleValue();
                             break;
                         }
                     }

+ 2 - 2
game-business/src/main/java/com/game/business/task/AppUserCountTask.java

@@ -404,7 +404,7 @@ public class AppUserCountTask {
                                     return;
                                 }
                                 double rate = userAgent.getDividendGuaranteeRate();
-                                double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+                                double dividends = BigDecimal.valueOf(money * rate/100).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();
                                 AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
                                 appUserCountDividend.setUserId(userAgent.getUserId());
                                 appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
@@ -499,7 +499,7 @@ public class AppUserCountTask {
                     if (money > 0) {
                         //金额大于0 满足分红
                         double rate = userAgent.getDividendGuaranteeRate();
-                        double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+                        double dividends = BigDecimal.valueOf(money * rate/100).setScale(4,BigDecimal.ROUND_HALF_UP).doubleValue();
                         AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
                         appUserCountDividend.setUserId(userAgent.getUserId());
                         appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));

+ 2 - 2
game-business/src/main/java/com/game/business/task/AppUserLiveDividedTask.java

@@ -103,7 +103,7 @@ public class AppUserLiveDividedTask {
         BigDecimal liveRate = new BigDecimal((topUserAgent.getLiveRate() / 100.00) + "");
 
         // 总佣金
-        BigDecimal liveCommission = item.getMoney().multiply(liveRate).setScale(2, BigDecimal.ROUND_HALF_DOWN);
+        BigDecimal liveCommission = item.getMoney().multiply(liveRate).setScale(4, RoundingMode.DOWN);
 
         double indexCommission = 0;
 
@@ -122,7 +122,7 @@ public class AppUserLiveDividedTask {
             if(appUserAgent.getLiveRate() > 0){
                 userLiveRate = new BigDecimal(((appUserAgent.getLiveRate() - indexCommission) / 100.00) + "");
             }
-            BigDecimal userCommission = item.getMoney().multiply(userLiveRate).setScale(2, BigDecimal.ROUND_HALF_DOWN);
+            BigDecimal userCommission = item.getMoney().multiply(userLiveRate).setScale(4, RoundingMode.DOWN);
 
             // 上一次费率
             indexCommission = appUserAgent.getLiveRate();