Sfoglia il codice sorgente

优化团队列表、下注金额和游戏佣金统计

dos 3 mesi fa
parent
commit
762fba3f2d

+ 5 - 0
game-business/src/main/java/com/game/business/domain/AppUserCount.java

@@ -76,6 +76,11 @@ public class AppUserCount {
     @ApiModelProperty(value = "直播佣金")
     private Double liveCommission;
 
+    @Excel(name = "游戏-下注金额")
+    @TableField(value = "game_betting")
+    @ApiModelProperty(value = "游戏-下注金额")
+    private Double gameBetting;
+
     @Excel(name = "游戏-赢")
     @TableField(value = "game_win_amount")
     @ApiModelProperty(value = "游戏-赢")

+ 6 - 0
game-business/src/main/java/com/game/business/mapper/AppUserAgentMapper.java

@@ -74,6 +74,12 @@ public interface AppUserAgentMapper extends BaseMapper<AppUserAgent> {
      */
     public List<AppAgentTeamVo> teamList(@Param("teamDto") AppAgentTeamDto teamDto);
 
+    /**
+     * 查询团队列表(新)
+     *
+     */
+    public List<AppAgentTeamVo> teamListNew(@Param("teamDto") AppAgentTeamDto teamDto);
+
     /**
      * 查询所有下级团队列表(递归)
      *

+ 4 - 0
game-business/src/main/java/com/game/business/service/IAppUserCountService.java

@@ -1,6 +1,8 @@
 package com.game.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.game.business.domain.AppGameBetting;
+import com.game.business.domain.AppGameCommission;
 import com.game.business.domain.AppUserCount;
 
 import java.util.List;
@@ -22,4 +24,6 @@ public interface IAppUserCountService extends IService<AppUserCount> {
 
     public Date selectLastDate();
 
+    public void staticsUserBetting(AppGameBetting appGameBetting,List<AppGameCommission> gameRateList);
+
 }

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

@@ -192,7 +192,7 @@ public class AppUserAgentServiceImpl extends ServiceImpl<AppUserAgentMapper, App
         if(null == teamDto.getPid()) {
             teamDto.setPid(SecurityUtils.getUserId());
         }
-        List<AppAgentTeamVo> list = appUserAgentMapper.teamList(teamDto);
+        List<AppAgentTeamVo> list = appUserAgentMapper.teamListNew(teamDto);
         if(null != list && list.size() > 0){
             List<Long> ids = list.stream().map(e->{return e.getUserId();}).collect(Collectors.toList());
             //查询游戏分红比例

+ 36 - 12
game-business/src/main/java/com/game/business/service/impl/AppUserCountServiceImpl.java

@@ -133,31 +133,26 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
             lastDateStr = DateUtil.format(curDate, "yyyy-MM-dd").concat(" 00:00:00");
         }
         String endTimeStr = DateUtil.format(curDate,"yyyy-MM-dd HH:mm:ss");*/
-        AppUser queryUser = new AppUser();
-        queryUser.setAgentFlag(1);
-        List<AppUser> list = appUserService.selectAppUserList(queryUser);//查询所有代理用户
-        List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, null, null,gameId,gameDate);
         List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, null, null,gameId,gameDate);
-        if (null != list && list.size() > 0) {
+        if (null != gameBettingList && gameBettingList.size() > 0) {
             String finalDateTime = dateTime;
             Date finalCurDate = curDate;
-            list.forEach(appUser -> {
+            List<Long> userIds = gameBettingList.stream().map(AppGameBetting::getUserId).distinct().collect(Collectors.toList());
+            userIds.forEach(userId -> {
                 AppUserCount appUserCount = new AppUserCount();
-                appUserCount.setUserId(appUser.getUserid());
+                appUserCount.setUserId(userId);
                 appUserCount.setStrDate(finalDateTime);
-                appUserCount.setAgentUserId(appUser.getPid());
+                appUserCount.setAgentUserId(userId);
                 appUserCount.setUpdateTime(finalCurDate);
-                //游戏佣金
-                appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(appUser.getUserid())).mapToDouble(e -> e.getCommission()).sum());
                 //游戏输
                 appUserCount.setGameLoseAmount(gameBettingList.stream().filter(
-                        e -> e.getUserId().equals(appUser.getUserid()) && e.getIsWinning().intValue() == 2
+                        e -> e.getUserId().equals(userId) && e.getIsWinning().intValue() == 2
                 ).mapToDouble(e ->
                         e.getBettingAmount()
                 ).sum());
                 //游戏赢
                 appUserCount.setGameWinAmount(gameBettingList.stream().filter(
-                        e -> e.getUserId().equals(appUser.getUserid()) && e.getIsWinning().intValue() == 1
+                        e -> e.getUserId().equals(userId) && e.getIsWinning().intValue() == 1
                 ).mapToDouble(e ->
                         e.getBettingAmount() * e.getBettingMultiple()
                 ).sum());
@@ -193,6 +188,35 @@ public class AppUserCountServiceImpl extends ServiceImpl<AppUserCountMapper, App
        return DateUtil.offsetMillisecond(appUserCount.getCountTime(), 1);  //往前加1毫秒用于增量更新
     }
 
+    @Override
+    public void staticsUserBetting(AppGameBetting appGameBetting,List<AppGameCommission> gameRateList) {
+        Date curDate = DateUtils.getNowDate();
+        String dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
+
+        List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, null, null,appGameBetting.getGameId(),appGameBetting.getGameDate());
+        if (null != gameRateList && gameRateList.size() > 0) {
+            List<Long> userIds = gameRateList.stream().map(AppGameCommission::getUserId).collect(Collectors.toList());
+            userIds.add(appGameBetting.getUserId());
+            userIds = userIds.stream().distinct().collect(Collectors.toList());
+            String finalDateTime = dateTime;
+            Date finalCurDate = curDate;
+            userIds.forEach(userId -> {
+                AppUserCount appUserCount = new AppUserCount();
+                appUserCount.setUserId(userId);
+                appUserCount.setStrDate(finalDateTime);
+                appUserCount.setAgentUserId(userId);
+                appUserCount.setUpdateTime(finalCurDate);
+                //游戏佣金 更新所有用户
+                appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(userId)).mapToDouble(e -> e.getCommission()).sum());
+                //游戏下注金额 更新当前下注用户
+                if(userId.equals(appGameBetting.getUserId())) {
+                    appUserCount.setGameBetting(appUserCount.getGameBetting() + appGameBetting.getBettingAmount());
+                }
+                this.createAppUserCount(appUserCount);
+            });
+        }
+    }
+
     /**
      * 金额为负数则转为正数
      * */

+ 6 - 0
game-business/src/main/java/com/game/business/task/AppAgentGameBettingTask.java

@@ -41,6 +41,9 @@ public class AppAgentGameBettingTask {
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private IAppUserCountService appUserCountService;
+
     @Async("asyncExecutor")
     public void agentGameBettingTask(AppGameBetting appGameBetting) {
 
@@ -65,6 +68,9 @@ public class AppAgentGameBettingTask {
 
         commissionHandler(gameRateList, appGameBetting);
 
+        //统计游戏下注、返佣情况
+        appUserCountService.staticsUserBetting(appGameBetting,gameRateList);
+
     }
 
     private void getGameRate(Long gameId, Long pid, Long userId, List<AppGameCommission> gameRateList){

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

@@ -113,6 +113,8 @@ public class AppUserCountTask {
                     }).mapToDouble(e -> dealMoney(e.getCoinChange())).sum());
                     //直播佣金
                     appUserCount.setLiveCommission(liveDividedRecordList.stream().filter(e -> e.getUserId().equals(appUser.getUserid())).mapToDouble(e -> e.getMoney().doubleValue()).sum());
+                    //游戏下注金额
+                    appUserCount.setGameBetting(gameBettingList.stream().filter(e->e.getUserId().equals(appUser.getUserid())).mapToDouble(AppGameBetting::getBettingAmount).sum());
                     //游戏佣金
                     appUserCount.setGameCommission(gameRecordCountList.stream().filter(e -> e.getUserId().equals(appUser.getUserid())).mapToDouble(e -> e.getCommission()).sum());
                     //游戏输

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

@@ -176,6 +176,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
              and c.username = #{teamDto.nickName}
         </if>
     </select>
+    <select id="teamListNew" resultType="com.game.business.vo.AppAgentTeamVo">
+        select
+            a.user_id as userId,
+            c.username as nickName,
+            c.coin as coin,
+            c.diamond_coin as diamondCoin,
+            a.pid as pid,
+            IFNULL(sum(b.game_betting),0) as bettingAmount,
+            IFNULL(sum(b.game_commission),0) as gameCommission,
+            IFNULL(sum(b.live_commission),0) as liveCommission,
+            IFNULL(sum(b.game_win_amount - b.game_lose_amount),0) as gameAmount,
+            IFNULL(sum(b.recharge_amount),0) as rechargeAmount,
+            IFNULL(sum(b.recharge_commission),0) as rechargeCommission,
+            IFNULL(sum(b.recharge_give),0) as rechargeGive,
+            a.live_rate as liveRate,
+            a.dividend_guarantee_rate as dividendGuaranteeRate
+        from app_user_agent as a inner join app_user_count as b on a.user_id = b.user_id left join mugozbg_live.app_user as c on a.user_id = c.userid where (a.pid = #{teamDto.pid} or a.user_id = #{teamDto.pid})
+        <if test="teamDto.userId != null ">
+             and a.user_id = #{teamDto.userId}
+        </if>
+        <if test="teamDto.nickName != null and teamDto.nickName != ''">
+             and c.username = #{teamDto.nickName}
+        </if>
+        <if test="teamDto.beginTime != null and teamDto.beginTime != ''">
+            and <![CDATA[ b.str_date >= #{teamDto.beginTime} ]]>
+        </if>
+        <if test="teamDto.endTime != null and teamDto.endTime != ''">
+            and <![CDATA[ b.str_date <= #{teamDto.endTime} ]]>
+        </if>
+        group by a.user_id order by a.user_id
+    </select>
 
     <select id="selectAllAgentList" resultMap="AppUserAgentResult">
         WITH RECURSIVE useragent AS