|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|