Răsfoiți Sursa

首页统计

kk 1 lună în urmă
părinte
comite
a465e2d35c

+ 14 - 2
game-business/src/main/java/com/game/business/controller/FinTranRecordController.java

@@ -2,6 +2,9 @@ package com.game.business.controller;
 
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
+
+import com.game.business.dto.FinTranRecordDTO;
+import com.game.common.core.domain.R;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -16,8 +19,6 @@ import com.game.common.annotation.Log;
 import com.game.common.core.controller.BaseController;
 import com.game.common.core.domain.AjaxResult;
 import com.game.common.enums.BusinessType;
-import com.game.common.annotation.DataSource;
-import com.game.common.enums.DataSourceType;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import com.game.business.domain.FinTranRecord;
@@ -52,6 +53,17 @@ public class FinTranRecordController extends BaseController
         return getDataTable(list);
     }
 
+    /**
+     * 查询消费统计
+     */
+    @PreAuthorize("@ss.hasPermi('business:tran_record:count')")
+    @GetMapping("/count")
+    @ApiOperation(value = "查询消费记录统计", notes = "查询消费记录统计")
+    public R count(FinTranRecordDTO finTranRecord)
+    {
+        return finTranRecordService.selecFinTranRecordCount(finTranRecord);
+    }
+
     /**
      * 导出消费记录列表
      */

+ 27 - 0
game-business/src/main/java/com/game/business/dto/FinTranRecordDTO.java

@@ -0,0 +1,27 @@
+package com.game.business.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+@ApiModel("消费记录统计参数")
+public class FinTranRecordDTO implements Serializable {
+
+    /** 用户ID */
+    @ApiModelProperty(value = "用户ID")
+    private Long userId;
+
+    /** 开始时间 */
+    @ApiModelProperty(value = "开始时间 格式yyyy-MM-dd")
+    private String beginTime;
+
+    /** 结束时间 */
+    @ApiModelProperty(value = "结束时间 格式yyyy-MM-dd")
+    private String endTime;
+
+
+
+}

+ 5 - 0
game-business/src/main/java/com/game/business/mapper/AppGameBettingMapper.java

@@ -3,16 +3,21 @@ package com.game.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.FinTranRecordDTO;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
 import com.game.business.vo.AppUserGameBettingCountVO;
 import com.game.business.vo.AppUserGameBettingDetailsCountVO;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 public interface AppGameBettingMapper extends BaseMapper<AppGameBetting> {
 
     List<AppGameBettingDetailsCountVO> getCount(@Param(value = "strDate") String strDate, @Param(value = "userId") Long userId,  @Param(value = "bettingType") Integer bettingType);
     List<AppUserGameBettingCountVO> getUserCount(@Param(value = "gameId") Long gameId, @Param(value = "userId") Long userId, @Param(value = "bettingType") Integer bettingType);
     List<AppUserGameBettingDetailsCountVO> getUserBettingItemCount(@Param(value = "gameId") Long gameId, @Param(value = "gameDate") String gameDate, @Param(value = "userId") Long userId, @Param(value = "bettingType") Integer bettingType);
+    Map<String, BigDecimal> getBettingAmountSum(Long userId);
+    Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO);
 }

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

@@ -1,8 +1,12 @@
 package com.game.business.mapper;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.AppUser;
+import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
 /**
@@ -69,4 +73,6 @@ public interface AppUserMapper extends BaseMapper<AppUser> {
      * 更新用户钱包
      * */
     public int updateUserMoney(AppUser appUser);
+
+    Map<String, BigDecimal> getUserCount(Long userId);
 }

+ 14 - 0
game-business/src/main/java/com/game/business/mapper/FinTranRecordMapper.java

@@ -1,8 +1,12 @@
 package com.game.business.mapper;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
+
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.FinTranRecord;
+import com.game.business.dto.FinTranRecordDTO;
 
 /**
  * 消费记录Mapper接口
@@ -60,4 +64,14 @@ public interface FinTranRecordMapper extends BaseMapper<FinTranRecord> {
     public int deleteFinTranRecordByIds(Long[] ids);
 
     Long nextId();
+
+    Map<String, BigDecimal> getRechargeSum(Long userId);
+
+    Map<String, BigDecimal> getExchangeSum(Long userId);
+
+    BigDecimal getWithdrawSum(Long userId);
+
+    List<Map<String, Object>> getWithdrawByDateSum(FinTranRecordDTO finTranRecordDTO);
+
+    List<Map<String, Object>> getRechargeByDateSum(FinTranRecordDTO finTranRecordDTO);
 }

+ 7 - 0
game-business/src/main/java/com/game/business/service/IAppGameBettingService.java

@@ -2,11 +2,14 @@ package com.game.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.FinTranRecordDTO;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
 import com.game.business.vo.AppUserGameBettingCountVO;
 import com.game.business.vo.AppUserGameBettingDetailsCountVO;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 public interface IAppGameBettingService extends IService<AppGameBetting> {
 
@@ -32,4 +35,8 @@ public interface IAppGameBettingService extends IService<AppGameBetting> {
      * 根据日期查询投注情况
      * */
     List<AppGameBetting> selectListByDate( Long userId, String beginTime, String endTime,Long gameId,String gameDate);
+
+    Map<String, BigDecimal> getBettingAmountSum(Long userId);
+
+    Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO);
 }

+ 5 - 0
game-business/src/main/java/com/game/business/service/IAppUserService.java

@@ -1,6 +1,9 @@
 package com.game.business.service;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
+
 import com.game.business.domain.AppUser;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.domain.FinTranRecord;
@@ -83,4 +86,6 @@ public interface IAppUserService extends IService<AppUser> {
      * 更新用户余额、插入流水
      * */
     int updateUserAmount(FinTranRecord finTranRecord)  throws Exception;
+
+    Map<String, BigDecimal> getUserCount(Long userId);
 }

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

@@ -7,8 +7,9 @@ import com.game.business.domain.FinTranRecord;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.dto.AppUserTeamTranserDto;
 import com.game.business.dto.AppUserTeamTranserRecordDto;
-import com.game.business.vo.AppUserTeamTranserRecordVo;
+import com.game.business.dto.FinTranRecordDTO;
 import com.game.common.core.domain.HttpRet;
+import com.game.common.core.domain.R;
 
 /**
  * 消费记录Service接口
@@ -87,4 +88,6 @@ public interface IFinTranRecordService extends IService<FinTranRecord> {
     public List<FinTranRecord> transferRecord(AppUserTeamTranserRecordDto transerRecordDto);
 
     public List<FinTranRecord> selecListByWrapper(LambdaQueryWrapper<FinTranRecord> queryWrapper);
+
+    public R selecFinTranRecordCount(FinTranRecordDTO finTranRecordDTO);
 }

+ 13 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameBettingServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.FinTranRecordDTO;
 import com.game.business.vo.AppGameBettingDetailsCountVO;
 import com.game.business.mapper.AppGameBettingMapper;
 import com.game.business.service.IAppGameBettingService;
@@ -13,8 +14,10 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper, AppGameBetting> implements IAppGameBettingService {
@@ -117,4 +120,14 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
         }
         return appGameBettingMapper.selectList(queryWrapper);
     }
+
+    @Override
+    public Map<String, BigDecimal> getBettingAmountSum(Long userId) {
+        return appGameBettingMapper.getBettingAmountSum(userId);
+    }
+
+    @Override
+    public Map<String, BigDecimal> getBettingAmountByDateSum(FinTranRecordDTO finTranRecordDTO) {
+        return appGameBettingMapper.getBettingAmountByDateSum(finTranRecordDTO);
+    }
 }

+ 7 - 0
game-business/src/main/java/com/game/business/service/impl/AppUserServiceImpl.java

@@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import java.math.BigDecimal;
 import java.rmi.ServerException;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import com.game.business.domain.FinTranRecord;
@@ -223,4 +225,9 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
         }
         return res;
     }
+
+    @Override
+    public Map<String, BigDecimal> getUserCount(Long userId) {
+        return appUserMapper.getUserCount(userId);
+    }
 }

+ 56 - 3
game-business/src/main/java/com/game/business/service/impl/FinTranRecordServiceImpl.java

@@ -1,20 +1,24 @@
 package com.game.business.service.impl;
 
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
-import java.util.Collections;
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 import com.game.business.domain.AppUser;
 import com.game.business.domain.CfgCommon;
 import com.game.business.dto.AppUserTeamTranserDto;
 import com.game.business.dto.AppUserTeamTranserRecordDto;
+import com.game.business.dto.FinTranRecordDTO;
+import com.game.business.service.IAppGameBettingService;
 import com.game.business.service.IAppUserService;
 import com.game.business.service.ICfgCommonService;
 import com.game.business.util.Md5Utils;
-import com.game.business.vo.AppUserTeamTranserRecordVo;
 import com.game.common.annotation.DataSource;
 import com.game.common.constant.AppSceneType;
 import com.game.common.constant.finance.FinTranAddedInfo;
@@ -22,6 +26,7 @@ import com.game.common.constant.finance.FinTranType1;
 import com.game.common.constant.finance.FinTranType3;
 import com.game.common.constant.finance.TranCurrencyType;
 import com.game.common.core.domain.HttpRet;
+import com.game.common.core.domain.R;
 import com.game.common.core.redis.RedisCache;
 import com.game.common.enums.DataSourceType;
 import com.game.common.utils.DateUtils;
@@ -32,7 +37,6 @@ import org.springframework.stereotype.Service;
 import com.game.business.mapper.FinTranRecordMapper;
 import com.game.business.domain.FinTranRecord;
 import com.game.business.service.IFinTranRecordService;
-import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 消费记录Service业务层处理
@@ -58,6 +62,9 @@ public class FinTranRecordServiceImpl extends ServiceImpl<FinTranRecordMapper, F
     @Autowired
     private ICfgCommonService cfgCommonService;
 
+    @Autowired
+    private IAppGameBettingService appGameBettingService;
+
     /**
      * 查询消费记录
      *
@@ -261,4 +268,50 @@ public class FinTranRecordServiceImpl extends ServiceImpl<FinTranRecordMapper, F
         List<FinTranRecord> list = finTranRecordMapper.selectList(queryWrapper);
         return list;
     }
+
+    @Override
+    public R selecFinTranRecordCount(FinTranRecordDTO finTranRecordDTO) {
+
+        JSONObject jsonObject = new JSONObject();
+
+        // 用户总统计(金币、可兑换金币、剩余余额)
+        Map<String, BigDecimal> userCount = appUserService.getUserCount(finTranRecordDTO.getUserId());
+        jsonObject.put("userCount", userCount);
+
+        // 用户总统计(游戏投注)
+        Map<String, BigDecimal> bettingAmountSum = appGameBettingService.getBettingAmountSum(finTranRecordDTO.getUserId());
+        jsonObject.put("bettingAmountSum", bettingAmountSum);
+
+        // 用户总统计(充值)
+        Map<String, BigDecimal> rechargeCount = finTranRecordMapper.getRechargeSum(finTranRecordDTO.getUserId());
+        jsonObject.put("rechargeCount", rechargeCount);
+
+        // 用户总统计(兑换)
+        Map<String, BigDecimal> exchangeCount = finTranRecordMapper.getExchangeSum(finTranRecordDTO.getUserId());
+        jsonObject.put("exchangeCount", exchangeCount);
+
+        // 用户总统计(提现)
+        BigDecimal withdraw = finTranRecordMapper.getWithdrawSum(finTranRecordDTO.getUserId());
+        jsonObject.put("withdraw", withdraw);
+
+        // 根据时间查询投注
+        Map<String, BigDecimal> bettingAmountDateSum = appGameBettingService.getBettingAmountByDateSum(finTranRecordDTO);
+        jsonObject.put("bettingAmountDateSum", bettingAmountDateSum);
+
+        // 根据时间查询充值分类统计
+        List<Map<String, Object>> rechargeByDateSum =  finTranRecordMapper.getRechargeByDateSum(finTranRecordDTO);
+        if(rechargeByDateSum == null){
+            rechargeByDateSum = new ArrayList<>();
+        }
+        jsonObject.put("rechargeByDateSum", rechargeByDateSum);
+
+
+        // 根据时间查询提现分类统计
+        List<Map<String, Object>> withdrawByDateSum =  finTranRecordMapper.getWithdrawByDateSum(finTranRecordDTO);
+        if(withdrawByDateSum == null){
+            withdrawByDateSum = new ArrayList<>();
+        }
+        jsonObject.put("withdrawByDateSum", withdrawByDateSum);
+        return R.ok(jsonObject);
+    }
 }

+ 27 - 0
game-business/src/main/resources/mapper/business/AppGameBettingMapper.xml

@@ -42,4 +42,31 @@
           and user_id = #{userId} and betting_type = #{bettingType} and betting_game_type = 0
           group by betting_item
     </select>
+
+    <select id="getBettingAmountSum" resultType="java.math.BigDecimal">
+        select
+            ifnull(sum(case when betting_type = 1 then betting_amount else 0.00 end), 0.00) as coinSum,
+            ifnull(sum(case when betting_type = 0 then betting_amount else 0.00 end), 0.00) as diamondCoinSum
+        from app_game_betting
+        <where>
+            <if test="userId != null">
+                and user_id = #{userId}
+            </if>
+        </where>
+    </select>
+
+    <select id="getBettingAmountByDateSum" resultType="java.util.Map" parameterType="com.game.business.dto.FinTranRecordDTO">
+        select
+            ifnull(sum(case when betting_type = 1 then betting_amount else 0.00 end), 0.00) as coinSum,
+            ifnull(sum(case when betting_type = 0 then betting_amount else 0.00 end), 0.00) as diamondCoinSum
+        from app_game_betting
+        <where>
+            <if test="userId != null">
+                and user_id = #{userId}
+            </if>
+            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
+                and (create_time &gt;= #{beginTime} and create_time &lt;= #{endTime}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 16 - 0
game-business/src/main/resources/mapper/business/AppUserMapper.xml

@@ -846,4 +846,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </trim>
         where userid = #{userid}
     </update>
+
+    <select id="getUserCount" resultType="java.util.Map">
+        select
+
+            ifnull(sum(diamond_coin), 0.00) as diamondCoin,
+            ifnull(sum(diamond_coin_cash), 0.00) as diamondCoinCash,
+            ifnull(sum(coin), 0.00) as coin,
+            ifnull(sum(coin_cash), 0.00) as coinCash
+
+        from app_user
+        <where>
+            <if test="userId != null">
+                and userid = #{userId}
+            </if>
+        </where>
+    </select>
 </mapper>

+ 86 - 0
game-business/src/main/resources/mapper/business/FinTranRecordMapper.xml

@@ -218,4 +218,90 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="nextId" resultType="java.lang.Long">
         select max(id) + 1 from fin_tran_record
     </select>
+
+    <select id="getRechargeSum" resultType="java.util.Map">
+        select
+
+        ifnull(sum(case when tran_type1 = 11 then coin_change else 0.00 end), 0.00) as coinSum,
+        ifnull(sum(case when tran_type1 = 17 then diamond_coin_change else 0.00 end), 0.00) as diamondCoinSum
+
+        from fin_tran_record where tran_type1 in(11, 17) and tran_type3 in (1001, 1101, 1108)
+        <if test="userId != null">
+            and uid = #{userId}
+        </if>
+    </select>
+
+    <select id="getExchangeSum" resultType="java.util.Map">
+        select
+
+        ifnull(sum(case when tran_type1 = 11 and tran_type3 = 1303 then coin_change else 0.00 end), 0.00) as coinSum,
+        ifnull(sum(case when tran_type1 = 17 and tran_type3 = 1304 then diamond_coin_change else 0.00 end), 0.00) as diamondCoinSum
+
+        from fin_tran_record where tran_type1 in(11, 17) and tran_type3 in (1303, 1304)
+        <if test="userId != null">
+            and uid = #{userId}
+        </if>
+    </select>
+
+    <select id="getWithdrawSum" resultType="java.math.BigDecimal">
+        select
+
+        ifnull(sum(money), 0.00) as diamondCoinSum
+
+        from app_users_cashrecord where status = 1
+
+        <if test="userId != null">
+            and uid = #{userId}
+        </if>
+    </select>
+
+    <select id="getWithdrawByDateSum" resultType="java.util.Map"  parameterType="com.game.business.dto.FinTranRecordDTO">
+        select
+
+        type,
+        ifnull(sum(money), 0.00) as moneySum,
+        ifnull(sum(actual_money), 0.00) as actualMoneySum,
+        ifnull(sum(platform_service), 0.00) as platformServiceSum
+
+        from app_users_cashrecord where status = 1
+
+        <if test="userId != null">
+            and uid = #{userId}
+        </if>
+        <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
+            and (uptime &gt;= #{beginTime} and uptime &lt;= #{endTime}
+        </if>
+        group by type
+    </select>
+
+    <select id="getRechargeByDateSum" resultType="java.util.Map" parameterType="com.game.business.dto.FinTranRecordDTO">
+        select
+
+        type,
+
+        ifnull(sum(case when coin_type = 0 and rule_id > 0 then (money + platform_service) else 0.00 end) ,0.00) as coinUpSum,
+        ifnull(sum(case when coin_type = 0 and rule_id > 0 then money else 0.00 end) ,0.00) as actualCoinUpSum,
+        ifnull(sum(case when coin_type = 0 and rule_id > 0 then platform_service else 0.00 end) ,0.00) as platformServiceCoinUpSum,
+        ifnull(sum(case when coin_type = 1 and rule_id > 0 then (money + platform_service) else 0.00 end) ,0.00) as diamondCoinUpSum,
+        ifnull(sum(case when coin_type = 1 and rule_id > 0 then money else 0.00 end) ,0.00) as actualDiamondCoinUpSum,
+        ifnull(sum(case when coin_type = 1 and rule_id > 0 then platform_service else 0.00 end) ,0.00) as platformServiceDiamondCoinUpSum,
+
+        ifnull(sum(case when coin_type = 0 and rule_id = 0 then (money + platform_service) else 0.00 end) ,0.00) as coinDownSum,
+        ifnull(sum(case when coin_type = 0 and rule_id = 0 then money else 0.00 end) ,0.00) as actualCoinDownSum,
+        ifnull(sum(case when coin_type = 0 and rule_id = 0 then platform_service else 0.00 end) ,0.00) as platformServiceCoinDownSum,
+        ifnull(sum(case when coin_type = 1 and rule_id = 0 then (money + platform_service) else 0.00 end) ,0.00) as diamondCoinDownSum,
+        ifnull(sum(case when coin_type = 1 and rule_id = 0 then money else 0.00 end) ,0.00) as actualDiamondCoinDownSum,
+        ifnull(sum(case when coin_type = 1 and rule_id = 0 then platform_service else 0.00 end) ,0.00) as platformServiceDiamondCoinDownSum
+
+        from app_users_charge where status = 1
+
+        <if test="userId != null">
+            and uid = #{userId}
+        </if>
+        <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
+            and (addtime &gt;= #{beginTime} and addtime &lt;= #{endTime}
+        </if>
+        group by type
+    </select>
+
 </mapper>