Prechádzať zdrojové kódy

更改团队展示逻辑以及团队分红

dos 3 mesiacov pred
rodič
commit
9d85509d4d

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

@@ -95,16 +95,42 @@ public class AppAgentController extends BaseController {
         if(null == appUserCountList){
             appUserCountList = new ArrayList<>();
         }
+        //处理下级代理树形列表
+        AppUserAgent teamUser = AppUserAgent.buildTree(appUserAgentList,userId,appUserCountList);
         //佣金
         double money = 0;
-        if(null != appUserCountList && appUserCountList.size() > 0 && appUserAgentList != null && appUserAgentList.size()>0){
+        if(null != appUserCountList && appUserCountList.size() > 0){
             List<AppUserCount> finalAppUserCountList = appUserCountList;
-            money = appUserAgentList.stream().mapToDouble(appUserAgent1 -> {
+            /*money = appUserAgentList.stream().mapToDouble(appUserAgent1 -> {
                 return finalAppUserCountList.stream().mapToDouble(e->{
                     return (e.getGameLoseAmount() - e.getGameWinAmount() - e.getGameCommission() - e.getRechargeGive()) * appUserAgent1.getDividendGuaranteeRate()/100;
                 }).sum();
+            }).sum();*/
+            /*if(teamUser.getChildrenList() != null && teamUser.getChildrenList().size()>0) {
+                money = teamUser.getChildrenList().stream().mapToDouble(e -> {
+                    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();
+                    } else {
+                        return 0;
+                    }
+                }).sum();
+            }*/
+            money = dealChildel(teamUser,money);
+
+            //计算当前用户分红
+            /*double winLose = appUserCountList.stream().mapToDouble(e->{
+               return e.getGameLoseAmount() - e.getGameWinAmount() - e.getGameCommission() - e.getRechargeGive();
             }).sum();
+
+            if(winLose > 0){
+                money +=  BigDecimal.valueOf(winLose * teamUser.getDividendGuaranteeRate() / 100).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+            }*/
+
         }
+
+
         /*if(null != appUserAgent.getDividendGuaranteeRate()){
             money = money * appUserAgent.getDividendGuaranteeRate() / 100 ;
         }else{
@@ -292,4 +318,17 @@ public class AppAgentController extends BaseController {
         return curTime.getTime() >= beginTime.getTime() && curTime.getTime() <= endTime.getTime();
     }
 
+    public double dealChildel(AppUserAgent appUserAgent,double money){
+        double winlose = 0;
+        winlose = AppUserAgent.calMoney(appUserAgent,winlose);
+        if(winlose > 0){
+            money += winlose * appUserAgent.getDividendGuaranteeRate() / 100;
+        }
+        if(null != appUserAgent.getChildrenList() && appUserAgent.getChildrenList().size() > 0){
+            for(AppUserAgent child : appUserAgent.getChildrenList()){
+                money = dealChildel(child,money);
+            }
+        }
+        return money;
+    }
 }

+ 52 - 0
game-business/src/main/java/com/game/business/domain/AppUserAgent.java

@@ -12,7 +12,9 @@ import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModel;
 import lombok.Data;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 用户代理表对象 app_user_agent
@@ -84,4 +86,54 @@ private static final long serialVersionUID=1L;
     @TableField(value = "update_time")
     private Date updateTime;
 
+    @TableField(exist = false)
+    private Double teamWinLose = 0.00;
+
+    @TableField(exist = false)
+    private List<AppUserAgent> childrenList = new ArrayList<>();
+
+    public static AppUserAgent buildTree(List<AppUserAgent> appUserAgentList,Long parentId,List<AppUserCount> appUserCountList){
+        AppUserAgent appUserAgent = new AppUserAgent();
+        if(null != appUserAgentList && appUserAgentList.size() > 0){
+            for(AppUserAgent child : appUserAgentList){
+                if(child.getUserId().equals(parentId)){
+                    appUserAgent = child;
+                    appUserAgent.setTeamWinLose(deal(appUserCountList,appUserAgent.getUserId()));
+                    break;
+                }
+            }
+            buildChildrenList(appUserAgent,appUserAgentList,appUserCountList);
+        }
+        return appUserAgent;
+    }
+
+    public static void buildChildrenList(AppUserAgent appUserAgent,List<AppUserAgent> appUserAgentList,List<AppUserCount> appUserCountList){
+        for(AppUserAgent appUserAgentChild : appUserAgentList){
+             if(appUserAgentChild.getPid().equals(appUserAgent.getUserId())){
+                appUserAgentChild.setTeamWinLose(deal(appUserCountList,appUserAgentChild.getUserId()));
+                appUserAgent.getChildrenList().add(appUserAgentChild);
+                buildChildrenList(appUserAgentChild,appUserAgentList,appUserCountList);
+            }
+        }
+    }
+
+    private static double deal(List<AppUserCount> appUserCountList,Long userId){
+       return appUserCountList.stream().filter(e->e.getUserId().equals(userId)).mapToDouble(e->{
+            return e.getGameLoseAmount() - e.getGameWinAmount() - e.getGameCommission() - e.getRechargeGive();
+        }).sum();
+    }
+
+    //递归用户盈亏
+    public static double calMoney(AppUserAgent appUserAgent,double money){
+        money += appUserAgent.getTeamWinLose();
+        if(null != appUserAgent.getChildrenList() && appUserAgent.getChildrenList().size() > 0){
+            for(AppUserAgent child : appUserAgent.getChildrenList()){
+                money = calMoney(child,money);
+            }
+        }
+        return money;
+    }
+
+
+
 }

+ 1 - 1
game-business/src/main/java/com/game/business/service/IAppUserAgentService.java

@@ -92,7 +92,7 @@ public interface IAppUserAgentService extends IService<AppUserAgent> {
     public HttpRet<String> transfer(AppUserTeamTranserDto transfer);
 
     /**
-     * 递归查询所有下级代理
+     * 递归查询所有下级代理(包含自己)
      * */
     public List<AppUserAgent> selectAllAgentList(Long pid,Long userId,String beginTime,String endTime);
 

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

@@ -250,87 +250,169 @@ public class AppUserCountTask {
     public void calculateDividends(String dateTime){
         try {
             log.info("开始每周代理分红");
-            Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
-            if (StringUtils.isNotBlank(dateTime)) {
-                curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
-            } else {
-                dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
-            }
-            Date beginTime = DateUtil.beginOfWeek(curDate);
-            Date endTime = DateUtil.endOfWeek(curDate);
-            //查询所有总代理用户
-            AppUser queryUser = new AppUser();
-            queryUser.setAgentFlag(1);
-            List<AppUser> list = appUserService.selectAppUserList(queryUser);
+            dealDividendsNew(dateTime);
+            log.info("每周代理分红完成");
+        }catch (Exception e){
+            log.info("每周分红失败:{}",e.getMessage());
+        }
+
+    }
+
+    /**
+     * 分红(已废弃)
+     * */
+    private void dealDividends(String dateTime){
+        Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
+        if (StringUtils.isNotBlank(dateTime)) {
+            curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
+        } else {
+            dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
+        }
+        Date beginTime = DateUtil.beginOfWeek(curDate);
+        Date endTime = DateUtil.endOfWeek(curDate);
+        //查询所有总代理用户
+        AppUser queryUser = new AppUser();
+        queryUser.setAgentFlag(1);
+        List<AppUser> list = appUserService.selectAppUserList(queryUser);
 //            List<AppUser> list = appUserService.selectTeamUserList();
-            if (null != list && list.size() > 0) {
-                list.forEach(appUser -> {
-                    String beginTimeStr = DateUtil.format(beginTime,"yyyy-MM-dd");
-                    String endTimeStr = DateUtil.format(endTime,"yyyy-MM-dd");
-                    //查询用户所有下级本周盈亏
+        if (null != list && list.size() > 0) {
+            list.forEach(appUser -> {
+                String beginTimeStr = DateUtil.format(beginTime,"yyyy-MM-dd");
+                String endTimeStr = DateUtil.format(endTime,"yyyy-MM-dd");
+                //查询用户所有下级本周盈亏
                     /*LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
                     queryWrapper.ge(AppUserCount::getStrDate, beginTimeStr);
                     queryWrapper.le(AppUserCount::getStrDate, endTimeStr);
                     queryWrapper.eq(AppUserCount::getAgentUserId, appUser.getUserid());
                     List<AppUserCount> appUserCountList = appUserCountService.list(queryWrapper);*/
-                    List<AppUserCount> appUserCountList = appUserCountService.getAppUserCountNew(appUser.getUserid(),beginTimeStr,endTimeStr);
-                    if (null != appUserCountList && appUserCountList.size() > 0) {
-                        //游戏输钱
-                        double loseAmount = appUserCountList.stream().mapToDouble(e -> e.getGameLoseAmount()).sum();
-                        //游戏赢钱
-                        double winAmount = appUserCountList.stream().mapToDouble(e -> e.getGameWinAmount()).sum();
-                        //提现手续费
-                        double withdrawalCommission = appUserCountList.stream().mapToDouble(e -> e.getWithdrawalCommission()).sum();
-                        //游戏佣金
-                        double gameCommission = appUserCountList.stream().mapToDouble(e -> e.getGameCommission()).sum();
-                        //直播佣金
-                        double liveCommission = appUserCountList.stream().mapToDouble(e -> e.getLiveCommission()).sum();
-                        //充值赠送
-                        double rechargeGive = appUserCountList.stream().mapToDouble(e -> e.getRechargeGive()).sum();
+                List<AppUserCount> appUserCountList = appUserCountService.getAppUserCountNew(appUser.getUserid(),beginTimeStr,endTimeStr);
+                if (null != appUserCountList && appUserCountList.size() > 0) {
+                    //游戏输钱
+                    double loseAmount = appUserCountList.stream().mapToDouble(e -> e.getGameLoseAmount()).sum();
+                    //游戏赢钱
+                    double winAmount = appUserCountList.stream().mapToDouble(e -> e.getGameWinAmount()).sum();
+                    //提现手续费
+                    double withdrawalCommission = appUserCountList.stream().mapToDouble(e -> e.getWithdrawalCommission()).sum();
+                    //游戏佣金
+                    double gameCommission = appUserCountList.stream().mapToDouble(e -> e.getGameCommission()).sum();
+                    //直播佣金
+                    double liveCommission = appUserCountList.stream().mapToDouble(e -> e.getLiveCommission()).sum();
+                    //充值赠送
+                    double rechargeGive = appUserCountList.stream().mapToDouble(e -> e.getRechargeGive()).sum();
 
-                        //计算分红金额 (输-赢)
+                    //计算分红金额 (输-赢)
 //                        double money = (loseAmount - winAmount) - withdrawalCommission - gameCommission - liveCommission;
-                        double money = (loseAmount - winAmount)  - gameCommission - rechargeGive;
-                        if (money > 0) {
-                            //金额大于0 满足分红
-                            //查询当前用户所有下级
-                            AppUserAgent queryAppUserAgent = new AppUserAgent();
-                            queryAppUserAgent.setPid(appUser.getUserid());
-                            List<AppUserAgent> appUserAgentList = appUserAgentService.selectAppUserAgentList(queryAppUserAgent);
-                            if (null != appUserAgentList && appUserAgentList.size() > 0) {
-                                appUserAgentList.forEach(userAgent -> {
-                                    if (userAgent.getDividendGuaranteeRate() <= 0.00) {
-                                        log.info("用户{},团队亏损{},或未设置分红比例,停止分红", userAgent.getUserId(), money);
-                                        return;
-                                    }
-                                    double rate = userAgent.getDividendGuaranteeRate();
-                                    double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
-                                    AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
-                                    appUserCountDividend.setUserId(userAgent.getUserId());
-                                    appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
-                                    appUserCountDividend.setBeginTime(beginTime);
-                                    appUserCountDividend.setEndTime(endTime);
-                                    appUserCountDividend.setProfitLoss(money);
-                                    appUserCountDividend.setRate(rate);
-                                    appUserCountDividend.setCoin(0.00);
-                                    appUserCountDividend.setDiamondCoin(dividends);
-                                    appUserCountDividend.setStatus(0);
-                                    appUserCountDividendService.insertAppUserCountDividend(appUserCountDividend);
-                                });
-                            } else {
-                                log.info("用户{},所有下级亏损{},查询下级为空,停止分红", appUser.getUserid(), money);
-                            }
+                    double money = (loseAmount - winAmount)  - gameCommission - rechargeGive;
+                    if (money > 0) {
+                        //金额大于0 满足分红
+                        //查询当前用户所有下级
+                        AppUserAgent queryAppUserAgent = new AppUserAgent();
+                        queryAppUserAgent.setPid(appUser.getUserid());
+                        List<AppUserAgent> appUserAgentList = appUserAgentService.selectAppUserAgentList(queryAppUserAgent);
+                        if (null != appUserAgentList && appUserAgentList.size() > 0) {
+                            appUserAgentList.forEach(userAgent -> {
+                                if (userAgent.getDividendGuaranteeRate() <= 0.00) {
+                                    log.info("用户{},团队亏损{},或未设置分红比例,停止分红", userAgent.getUserId(), money);
+                                    return;
+                                }
+                                double rate = userAgent.getDividendGuaranteeRate();
+                                double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+                                AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
+                                appUserCountDividend.setUserId(userAgent.getUserId());
+                                appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
+                                appUserCountDividend.setBeginTime(beginTime);
+                                appUserCountDividend.setEndTime(endTime);
+                                appUserCountDividend.setProfitLoss(money);
+                                appUserCountDividend.setRate(rate);
+                                appUserCountDividend.setCoin(0.00);
+                                appUserCountDividend.setDiamondCoin(dividends);
+                                appUserCountDividend.setStatus(0);
+                                appUserCountDividendService.insertAppUserCountDividend(appUserCountDividend);
+                            });
                         } else {
-                            log.info("用户{},所有下级亏损{},不满足分红条件", appUser.getUserid(), money);
+                            log.info("用户{},所有下级亏损{},查询下级为空,停止分红", appUser.getUserid(), money);
                         }
+                    } else {
+                        log.info("用户{},所有下级亏损{},不满足分红条件", appUser.getUserid(), money);
                     }
-                });
-            }
-            log.info("每周代理分红完成");
-        }catch (Exception e){
-            log.info("每周分红失败:{}",e.getMessage());
+                }
+            });
         }
+    }
 
+    /**
+     * 分红
+     * */
+    private void dealDividendsNew(String dateTime){
+        Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
+        if (StringUtils.isNotBlank(dateTime)) {
+            curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
+        } else {
+            dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
+        }
+        Date beginTime = DateUtil.beginOfWeek(curDate);
+        Date endTime = DateUtil.endOfWeek(curDate);
+        //查询所有总代理用户
+        AppUser queryUser = new AppUser();
+        queryUser.setAgentFlag(1);
+        List<AppUser> list = appUserService.selectAppUserList(queryUser);
+//            List<AppUser> list = appUserService.selectTeamUserList();
+        if (null != list && list.size() > 0) {
+            list.forEach(appUser -> {
+                AppUserAgent userAgent = appUserAgentService.selectInfo(appUser.getUserid());
+                if (userAgent.getDividendGuaranteeRate() <= 0.00) {
+                    log.info("用户{},未设置分红比例,停止分红", userAgent.getUserId());
+                    return;
+                }
+                String beginTimeStr = DateUtil.format(beginTime,"yyyy-MM-dd");
+                String endTimeStr = DateUtil.format(endTime,"yyyy-MM-dd");
+                //查询用户所有下级本周盈亏
+                    /*LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
+                    queryWrapper.ge(AppUserCount::getStrDate, beginTimeStr);
+                    queryWrapper.le(AppUserCount::getStrDate, endTimeStr);
+                    queryWrapper.eq(AppUserCount::getAgentUserId, appUser.getUserid());
+                    List<AppUserCount> appUserCountList = appUserCountService.list(queryWrapper);*/
+                List<AppUserCount> appUserCountList = appUserCountService.getAppUserCountNew(appUser.getUserid(),beginTimeStr,endTimeStr);
+                if (null != appUserCountList && appUserCountList.size() > 0) {
+                    //游戏输钱
+                    double loseAmount = appUserCountList.stream().mapToDouble(e -> e.getGameLoseAmount()).sum();
+                    //游戏赢钱
+                    double winAmount = appUserCountList.stream().mapToDouble(e -> e.getGameWinAmount()).sum();
+                    //提现手续费
+                    double withdrawalCommission = appUserCountList.stream().mapToDouble(e -> e.getWithdrawalCommission()).sum();
+                    //游戏佣金
+                    double gameCommission = appUserCountList.stream().mapToDouble(e -> e.getGameCommission()).sum();
+                    //直播佣金
+                    double liveCommission = appUserCountList.stream().mapToDouble(e -> e.getLiveCommission()).sum();
+                    //充值赠送
+                    double rechargeGive = appUserCountList.stream().mapToDouble(e -> e.getRechargeGive()).sum();
+
+                    //计算分红金额 (输-赢)
+//                        double money = (loseAmount - winAmount) - withdrawalCommission - gameCommission - liveCommission;
+                    double money = (loseAmount - winAmount)  - gameCommission - rechargeGive;
+                    if (money > 0) {
+                        //金额大于0 满足分红
+                        double rate = userAgent.getDividendGuaranteeRate();
+                        double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+                        AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
+                        appUserCountDividend.setUserId(userAgent.getUserId());
+                        appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
+                        appUserCountDividend.setBeginTime(beginTime);
+                        appUserCountDividend.setEndTime(endTime);
+                        appUserCountDividend.setProfitLoss(money);
+                        appUserCountDividend.setRate(rate);
+                        appUserCountDividend.setCoin(0.00);
+                        appUserCountDividend.setDiamondCoin(dividends);
+                        appUserCountDividend.setStatus(0);
+                        appUserCountDividendService.insertAppUserCountDividend(appUserCountDividend);
+                    } else {
+                        log.info("用户{},所有下级亏损{},没有亏损停止分红", appUser.getUserid(), money);
+                    }
+                } else {
+                    log.info("用户{},团队没有流水停止分红", appUser.getUserid());
+                }
+            });
+        }
     }
 
     /**

+ 2 - 0
game-business/src/main/resources/mapper/business/AppUserAgentMapper.xml

@@ -243,5 +243,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <if test="userId != null">
             and user_id = #{userId}
         </if>
+        union all
+        select * from app_user_agent where user_id = #{pid}
     </select>
 </mapper>