|
@@ -0,0 +1,222 @@
|
|
|
+package com.game.business.task;
|
|
|
+
|
|
|
+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.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("appUserLiveDividedTask")
|
|
|
+public class AppUserLiveDividedTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppUserLiveDividedService appUserLiveDividedService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppUserLiveDividedRecordService appUserLiveDividedRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppUserAgentService appUserAgentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppUserService appUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFinTranRecordService finTranRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+
|
|
|
+ public void gameDataTask(){
|
|
|
+
|
|
|
+ AppUserLiveDivided appUserLiveDivided = new AppUserLiveDivided();
|
|
|
+ appUserLiveDivided.setStatus(0);
|
|
|
+ List<AppUserLiveDivided> list = appUserLiveDividedService.selectAppUserLiveDividedList(appUserLiveDivided);
|
|
|
+
|
|
|
+ if(list == null || list.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ AppUserLiveDivided item = list.get(i);
|
|
|
+
|
|
|
+ List<AppUserAgent> liveRateList = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ getLiveRate(item.getUserId(), liveRateList);
|
|
|
+
|
|
|
+ if(liveRateList.isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ liveRateHandler(liveRateList, item);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getLiveRate(Long userId, List<AppUserAgent> liveRateList){
|
|
|
+
|
|
|
+ AppUserAgent userIdObject = new AppUserAgent();
|
|
|
+ userIdObject.setUserId(userId);
|
|
|
+ List<AppUserAgent> userAgents = appUserAgentService.selectAppUserAgentList(userIdObject);
|
|
|
+
|
|
|
+ if(userAgents == null || userAgents.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ AppUserAgent userAgent = userAgents.get(0);
|
|
|
+ if(userAgent.getPid() == null || userAgent.getPid() == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ liveRateList.add(userAgent);
|
|
|
+
|
|
|
+ getLiveRate(userAgent.getPid(), liveRateList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void liveRateHandler(List<AppUserAgent> liveRateList, AppUserLiveDivided item){
|
|
|
+
|
|
|
+
|
|
|
+ Collections.sort(liveRateList, Comparator.comparing(AppUserAgent::getLiveRate));
|
|
|
+
|
|
|
+ AppUserAgent topUserAgent = liveRateList.get(liveRateList.size() - 1);
|
|
|
+ BigDecimal gameRate = new BigDecimal((topUserAgent.getLiveRate() / 100.00) + "");
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal liveCommission = item.getMoney().multiply(gameRate).setScale(2, RoundingMode.DOWN);
|
|
|
+
|
|
|
+ double indexCommission = 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < liveRateList.size(); i++) {
|
|
|
+
|
|
|
+
|
|
|
+ AppUserAgent appUserAgent = liveRateList.get(i);
|
|
|
+
|
|
|
+ AppUser appUser = appUserService.selectAppUserByUserid(appUserAgent.getPid());
|
|
|
+ if(appUser == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal pidLiveRate = new BigDecimal("0.00");
|
|
|
+ if(appUserAgent.getLiveRate() != null){
|
|
|
+ pidLiveRate = new BigDecimal(((appUserAgent.getLiveRate() - indexCommission) / 100.00) + "");
|
|
|
+ }
|
|
|
+ BigDecimal userCommission = item.getMoney().multiply(pidLiveRate).setScale(2, RoundingMode.DOWN);
|
|
|
+
|
|
|
+
|
|
|
+ indexCommission = appUserAgent.getLiveRate();
|
|
|
+
|
|
|
+
|
|
|
+ if(item.getCurrencyType() == 4){
|
|
|
+ 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());
|
|
|
+
|
|
|
+
|
|
|
+ AppUserLiveDividedRecord appUserLiveDividedRecord = new AppUserLiveDividedRecord();
|
|
|
+ appUserLiveDividedRecord.setRate(pidLiveRate);
|
|
|
+ appUserLiveDividedRecord.setUserId(appUser.getUserid());
|
|
|
+ appUserLiveDividedRecord.setUserLiveDividedId(item.getId());
|
|
|
+ appUserLiveDividedRecord.setMoney(userCommission);
|
|
|
+ appUserLiveDividedRecord.setCurrencyType(item.getCurrencyType());
|
|
|
+ appUserLiveDividedRecord.setCreateTime(new Date());
|
|
|
+ appUserLiveDividedRecordService.insertAppUserLiveDividedRecord(appUserLiveDividedRecord);
|
|
|
+
|
|
|
+ FinTranRecord finTranRecord = new FinTranRecord();
|
|
|
+
|
|
|
+ if(item.getCurrencyType() == 4){
|
|
|
+ finTranRecord.setCurrencyType(4);
|
|
|
+ finTranRecord.setAfterDiamondCoin(appUser.getDiamondCoin());
|
|
|
+ finTranRecord.setDiamondCoinChange(userCommission.doubleValue());
|
|
|
+
|
|
|
+ finTranRecord.setAfterCoin(appUser.getCoin());
|
|
|
+ finTranRecord.setCoinChange(0.00);
|
|
|
+ }else{
|
|
|
+ finTranRecord.setCurrencyType(2);
|
|
|
+ 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(item.getUserId());
|
|
|
+
|
|
|
+ finTranRecord.setSceneId1(0L);
|
|
|
+ finTranRecord.setSceneId2(null);
|
|
|
+ finTranRecord.setSceneType(0L);
|
|
|
+
|
|
|
+ finTranRecord.setTranGroupId(item.getId());
|
|
|
+
|
|
|
+ if(item.getCurrencyType() == 4){
|
|
|
+ finTranRecord.setTranType1(FinTranType1.U_Income_Coin_Balance.getType());
|
|
|
+ }else if(item.getCurrencyType() == 2){
|
|
|
+ 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(item.getId());
|
|
|
+ finTranRecordService.insertFinTranRecord(finTranRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ AppUserLiveDivided appUserLiveDivided = new AppUserLiveDivided();
|
|
|
+ appUserLiveDivided.setId(item.getId());
|
|
|
+ appUserLiveDivided.setStatus(1);
|
|
|
+ appUserLiveDivided.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ appUserLiveDividedService.updateAppUserLiveDivided(appUserLiveDivided);
|
|
|
+ }
|
|
|
+}
|