Browse Source

游戏投注分佣

kk 3 months ago
parent
commit
aca2f166d5

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

@@ -7,6 +7,9 @@ import com.game.business.vo.AppGameBettingDetailsCountVO;
 import com.game.business.service.*;
 import com.game.business.service.*;
 import com.game.business.vo.AppGameBettingVO;
 import com.game.business.vo.AppGameBettingVO;
 import com.game.common.annotation.Anonymous;
 import com.game.common.annotation.Anonymous;
+import com.game.common.constant.finance.FinTranType1;
+import com.game.common.constant.finance.FinTranType2;
+import com.game.common.constant.finance.FinTranType3;
 import com.game.common.core.controller.BaseController;
 import com.game.common.core.controller.BaseController;
 import com.game.common.core.domain.HttpRet;
 import com.game.common.core.domain.HttpRet;
 import com.game.common.core.domain.HttpRetPageArr;
 import com.game.common.core.domain.HttpRetPageArr;
@@ -161,9 +164,9 @@ public class AppGameBettingController extends BaseController{
             finTranRecord.setSceneType(0L);
             finTranRecord.setSceneType(0L);
 
 
             finTranRecord.setTranGroupId(gameBetting.getId());
             finTranRecord.setTranGroupId(gameBetting.getId());
-            finTranRecord.setTranType1(16L);
-            finTranRecord.setTranType2(200L);
-            finTranRecord.setTranType3(20001L);
+            finTranRecord.setTranType1(FinTranType1.U_Outcome_Balance.getType());
+            finTranRecord.setTranType2(FinTranType2.CONSUM_GAME.getType());
+            finTranRecord.setTranType3(FinTranType3.CONSUM_GAME_ANCHOR_ZHUANPAN.getType());
 
 
             finTranRecord.setRemarks("游戏下注");
             finTranRecord.setRemarks("游戏下注");
 
 

+ 10 - 0
game-business/src/main/java/com/game/business/domain/AppGameBetting.java

@@ -41,6 +41,11 @@ public class AppGameBetting {
     @ApiModelProperty(value = "游戏期号")
     @ApiModelProperty(value = "游戏期号")
     private String gameDate;
     private String gameDate;
 
 
+    @Excel(name = "投注类型:0:余额 1:金币")
+    @TableField(value = "betting_type")
+    @ApiModelProperty(value = "投注类型:0:余额 1:金币")
+    private Integer bettingType;
+
     @Excel(name = "投注选项")
     @Excel(name = "投注选项")
     @TableField(value = "betting_item")
     @TableField(value = "betting_item")
     @ApiModelProperty(value = "投注选项")
     @ApiModelProperty(value = "投注选项")
@@ -56,6 +61,11 @@ public class AppGameBetting {
     @ApiModelProperty(value = "投注金额")
     @ApiModelProperty(value = "投注金额")
     private Double bettingAmount;
     private Double bettingAmount;
 
 
+    @Excel(name = "投注佣金")
+    @TableField(value = "betting_commission")
+    @ApiModelProperty(value = "投注佣金")
+    private Double bettingCommission;
+
     @Excel(name = "是否中奖:0:未开奖 1:是 2:否")
     @Excel(name = "是否中奖:0:未开奖 1:是 2:否")
     @TableField(value = "is_winning")
     @TableField(value = "is_winning")
     @ApiModelProperty(value = "是否中奖:0:未开奖 1:是 2:否")
     @ApiModelProperty(value = "是否中奖:0:未开奖 1:是 2:否")

+ 3 - 3
game-business/src/main/java/com/game/business/domain/FinTranRecord.java

@@ -206,19 +206,19 @@ private static final long serialVersionUID=1L;
     @ApiModelProperty(value = " 1级交易类型")
     @ApiModelProperty(value = " 1级交易类型")
     @Excel(name = " 1级交易类型")
     @Excel(name = " 1级交易类型")
     @TableField(value = "tran_type1")
     @TableField(value = "tran_type1")
-    private Long tranType1;
+    private Integer tranType1;
 
 
     /**  2级交易类型 FinTranType2 */
     /**  2级交易类型 FinTranType2 */
     @ApiModelProperty(value = " 2级交易类型 FinTranType2")
     @ApiModelProperty(value = " 2级交易类型 FinTranType2")
     @Excel(name = " 2级交易类型 FinTranType2")
     @Excel(name = " 2级交易类型 FinTranType2")
     @TableField(value = "tran_type2")
     @TableField(value = "tran_type2")
-    private Long tranType2;
+    private Integer tranType2;
 
 
     /**  3级交易类型 FinTranType3 */
     /**  3级交易类型 FinTranType3 */
     @ApiModelProperty(value = " 3级交易类型 FinTranType3")
     @ApiModelProperty(value = " 3级交易类型 FinTranType3")
     @Excel(name = " 3级交易类型 FinTranType3")
     @Excel(name = " 3级交易类型 FinTranType3")
     @TableField(value = "tran_type3")
     @TableField(value = "tran_type3")
-    private Long tranType3;
+    private Integer tranType3;
 
 
     /**  用户ID */
     /**  用户ID */
     @ApiModelProperty(value = " 用户ID")
     @ApiModelProperty(value = " 用户ID")

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

@@ -0,0 +1,213 @@
+package com.game.business.task;
+
+import cn.hutool.core.util.IdUtil;
+import com.game.business.domain.*;
+import com.game.business.service.*;
+import com.game.common.constant.finance.FinTranType1;
+import com.game.common.constant.finance.FinTranType2;
+import com.game.common.constant.finance.FinTranType3;
+import com.game.common.core.domain.HttpRet;
+import com.game.common.core.redis.RedisCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.*;
+
+@Component
+public class AppAgentGameBettingTask {
+
+    @Autowired
+    private IAppUserAgentService appUserAgentService;
+
+    @Autowired
+    private IAppGameCommissionService appGameCommissionService;
+
+    @Autowired
+    private IAppGameBettingService appGameBettingService;
+
+    @Autowired
+    private IFinTranRecordService finTranRecordService;
+
+    @Autowired
+    private IAppUserService appUserService;
+
+    @Autowired
+    private RedisCache redisCache;
+
+    @Async("asyncExecutor")
+    public void agentGameBettingTask(AppGameBetting appGameBetting) {
+
+        AppUserAgent userIdObject = new AppUserAgent();
+        userIdObject.setUserId(appGameBetting.getUserId());
+        List<AppUserAgent> userAgents = appUserAgentService.selectAppUserAgentList(userIdObject);
+        if(userAgents == null || userAgents.isEmpty()){
+            return;
+        }
+
+        AppUserAgent userAgent = userAgents.get(0);
+        if(userAgent.getPid() == null || userAgent.getPid() == 1){
+            return;
+        }
+
+        List<AppGameCommission> gameRateList = new ArrayList<>();
+        getGameRate(appGameBetting.getGameId(), userAgent.getPid(), userAgent.getUserId(), gameRateList);
+        if(gameRateList.isEmpty()){
+            return;
+        }
+
+        commissionHandler(gameRateList, appGameBetting);
+
+    }
+
+    public void getGameRate(Long gameId, Long pid, Long userId, List<AppGameCommission> gameRateList){
+
+        AppGameCommission commissionWhere = new AppGameCommission();
+        commissionWhere.setPid(pid);
+        commissionWhere.setUserId(userId);
+        commissionWhere.setGameId(gameId);
+
+        List<AppGameCommission> gameCommissions = appGameCommissionService.selectAppGameCommissionList(commissionWhere);
+        if(gameCommissions == null || gameCommissions.isEmpty()){
+            return;
+        }
+
+        AppGameCommission gameCommission = gameCommissions.get(0);
+        if(gameCommission.getGameRate() == null || gameCommission.getGameRate() <= 0){
+            return;
+        }
+
+        gameRateList.add(gameCommission);
+
+        AppUserAgent userIdObject = new AppUserAgent();
+        userIdObject.setUserId(pid);
+        List<AppUserAgent> userAgents = appUserAgentService.selectAppUserAgentList(userIdObject);
+
+        if(userAgents == null || userAgents.isEmpty()){
+            return;
+        }
+
+        AppUserAgent userAgent = userAgents.get(0);
+        if(userAgent.getPid() == null || userAgent.getPid() == 1){
+            return;
+        }
+
+        getGameRate(gameId, userAgent.getPid(), userAgent.getUserId(), gameRateList);
+
+    }
+
+    @Transactional
+    public void commissionHandler(List<AppGameCommission> gameRateList, AppGameBetting appGameBetting){
+
+        // 升序排序
+        Collections.sort(gameRateList, Comparator.comparing(AppGameCommission::getGameRate));
+
+        AppGameCommission topCommission = gameRateList.get(gameRateList.size() - 1);
+        BigDecimal bettingAmount = new BigDecimal(appGameBetting.getBettingAmount() + "");
+        BigDecimal gameRate = new BigDecimal((topCommission.getGameRate() / 100) + "");
+
+        // 总佣金
+        BigDecimal bettingCommission = bettingAmount.multiply(gameRate).setScale(2, RoundingMode.DOWN);
+
+        AppGameBetting updateBettingCommission = new AppGameBetting();
+        updateBettingCommission.setId(updateBettingCommission.getId());
+        updateBettingCommission.setBettingCommission(bettingCommission.doubleValue());
+        updateBettingCommission.setUpdateTime(new Date());
+        appGameBettingService.updateById(updateBettingCommission);
+
+        double indexCommission = 0;
+
+        for (int i = 0; i < gameRateList.size(); i++) {
+
+            // 给上级分佣金
+            AppGameCommission appGameCommission = gameRateList.get(i);
+            AppUser appUser = appUserService.selectAppUserByUserid(appGameCommission.getPid());
+            if(appUser == null){
+                continue;
+            }
+
+            // 计算上级佣金
+            BigDecimal pidGameRate = new BigDecimal(((appGameCommission.getGameRate() - indexCommission) / 100) + "");
+            BigDecimal userCommission = bettingCommission.multiply(pidGameRate).setScale(2, RoundingMode.DOWN);
+
+            // 上一次费率
+            indexCommission = appGameCommission.getGameRate();
+
+            // 更新用户余额
+            if(appGameBetting.getBettingType() == 0){
+                appUser.setDiamondCoin(appUser.getDiamondCoin() + userCommission.doubleValue());
+                appUser.setDiamondCoinTotal(appUser.getDiamondCoinTotal() + userCommission.doubleValue());
+                appUserService.updateAppUser(appUser);
+            // 更新用户金币
+            }else{
+                appUser.setCoin(appUser.getCoin() + userCommission.doubleValue());
+                appUserService.updateAppUser(appUser);
+            }
+
+            redisCache.deleteObject("U:UserInfo:" + appUser.getUserid());
+
+            FinTranRecord finTranRecord = new FinTranRecord();
+
+            if(appGameBetting.getBettingType() == 0){
+                finTranRecord.setCurrencyType(4L);
+                finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
+                finTranRecord.setDiamondCoinChange(userCommission.doubleValue());
+
+                finTranRecord.setAfterCoin(appUser.getCoin());
+                finTranRecord.setCoinChange(0.00);
+            }else{
+                finTranRecord.setCurrencyType(2L);
+                finTranRecord.setAfterCoin(appUser.getCoin());
+                finTranRecord.setCoinChange(userCommission.doubleValue());
+
+                finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
+                finTranRecord.setDiamondCoinChange(0.00);
+            }
+
+            finTranRecord.setAfterMoney(0.00);
+            finTranRecord.setMoneyChange(0.00);
+
+            finTranRecord.setAfterTicket(0.00);
+            finTranRecord.setTicketChange(0.00);
+
+            finTranRecord.setToUid(appUser.getUserid());
+            finTranRecord.setUid(appUser.getUserid());
+            finTranRecord.setFromUid(appGameBetting.getUserId());
+
+            finTranRecord.setSceneId1(0L);
+            finTranRecord.setSceneId2(null);
+            finTranRecord.setSceneType(0L);
+
+            finTranRecord.setTranGroupId(appGameCommission.getId());
+            finTranRecord.setTranType1(FinTranType1.U_Income_Coin.getType());
+            finTranRecord.setTranType2(FinTranType2.REWARD_Income.getType());
+            finTranRecord.setTranType3(FinTranType3.RECOMMEND_ADD_AMOUNT.getType());
+
+            finTranRecord.setRemarks("游戏分佣");
+
+            finTranRecord.setConsumptionCoin(0.00);
+            finTranRecord.setConsumptionMoney(0.00);
+            finTranRecord.setCommissionRelatedUid(0L);
+            finTranRecord.setAgentId(appUser.getAgentId());
+
+            finTranRecord.setCreateTime(new Date());
+
+            finTranRecord.setFromUid(0L);
+            finTranRecord.setGoodsId(0L);
+            finTranRecord.setGuildId(0L);
+            finTranRecord.setManagerCoId(0L);
+            finTranRecord.setManagerId(0L);
+
+            finTranRecord.setPerc(0.00);
+            finTranRecord.setProId(0L);
+            finTranRecord.setProCount(0L);
+
+            finTranRecord.setOrderId(appGameBetting.getId());
+            finTranRecord.setId(IdUtil.getSnowflakeNextId());
+            finTranRecordService.insertFinTranRecord(finTranRecord);
+        }
+    }
+}

+ 17 - 0
game-business/src/main/java/com/game/business/vo/AppGameRateVO.java

@@ -0,0 +1,17 @@
+package com.game.business.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "游戏费率", description = "游戏费率")
+public class AppGameRateVO {
+
+    @ApiModelProperty(value = "用户ID")
+    private Long userId;
+
+    @ApiModelProperty(value = "游戏费率")
+    private Double gameRate;
+
+}