|
@@ -6,6 +6,7 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.game.business.domain.*;
|
|
|
import com.game.business.service.*;
|
|
|
+import com.game.common.constant.CacheConstants;
|
|
|
import com.game.common.constant.finance.FinTranType1;
|
|
|
import com.game.common.constant.finance.FinTranType3;
|
|
|
import com.game.common.core.redis.RedisCache;
|
|
@@ -16,6 +17,7 @@ import lombok.extern.log4j.Log4j2;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -71,6 +73,8 @@ public class AppUserCountTask {
|
|
|
if (StringUtils.isNotBlank(dateTime)) {
|
|
|
curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
|
|
|
} else {
|
|
|
+
|
|
|
+
|
|
|
dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
}
|
|
|
AppUser queryUser = new AppUser();
|
|
@@ -82,6 +86,7 @@ public class AppUserCountTask {
|
|
|
List<AppUserLiveDividedRecord> liveDividedRecordList = appUserLiveDividedRecordService.selectByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"));
|
|
|
List<AppUserGameRecordCount> gameRecordCountList = appUserGameRecordCountService.selectByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"),null,null);
|
|
|
List<AppGameBetting> gameBettingList = appGameBettingService.selectListByDate(null, dateTime.concat(" 00:00:00"), dateTime.concat(" 23:59:59"),null,null);
|
|
|
+ Date nowDate = new Date();
|
|
|
if (null != list && list.size() > 0) {
|
|
|
List<AppUserCount> appUserCountList = new ArrayList<>();
|
|
|
String finalDateTime = dateTime;
|
|
@@ -91,6 +96,9 @@ public class AppUserCountTask {
|
|
|
appUserCount.setStrDate(finalDateTime);
|
|
|
appUserCount.setAgentUserId(appUser.getPid());
|
|
|
appUserCount.setUpdate(true);
|
|
|
+ appUserCount.setCountTime(nowDate);
|
|
|
+ appUserCount.setGameCountTime(nowDate);
|
|
|
+ appUserCount.setUpdateTime(nowDate);
|
|
|
|
|
|
appUserCount.setRechargeAmount(appUsersChargeList.stream().filter(e -> e.getUid().equals(appUser.getUserid())).mapToDouble(e -> e.getCoin().doubleValue()).sum());
|
|
|
|
|
@@ -137,6 +145,8 @@ public class AppUserCountTask {
|
|
|
appUserCountService.createAppUserCount(appUserCount);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ appUserCountService.setGameCache(gameRecordCountList);
|
|
|
|
|
|
|
|
|
if (null != gameBettingList && gameBettingList.size() > 0) {
|
|
@@ -249,90 +259,171 @@ public class AppUserCountTask {
|
|
|
public void calculateDividends(String dateTime){
|
|
|
try {
|
|
|
log.info("开始每周代理分红");
|
|
|
- Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
|
|
|
- if (StringUtils.isNotBlank(dateTime)) {
|
|
|
- curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
|
|
|
- } else {
|
|
|
- dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
- }
|
|
|
- Date beginTime = DateUtil.beginOfWeek(curDate);
|
|
|
- Date endTime = DateUtil.endOfWeek(curDate);
|
|
|
-
|
|
|
-
|
|
|
- queryUser.setAgentFlag(1);
|
|
|
- List<AppUser> list = appUserService.selectAppUserList(queryUser);*/
|
|
|
- List<AppUser> list = appUserService.selectTeamUserList();
|
|
|
- if (null != list && list.size() > 0) {
|
|
|
- list.forEach(appUser -> {
|
|
|
-
|
|
|
+ dealDividendsNew(dateTime);
|
|
|
+ log.info("每周代理分红完成");
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("每周分红失败:{}",e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 分红(已废弃)
|
|
|
+ * */
|
|
|
+ private void dealDividends(String dateTime){
|
|
|
+ Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
|
|
|
+ if (StringUtils.isNotBlank(dateTime)) {
|
|
|
+ curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
|
|
|
+ } else {
|
|
|
+ dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
+ }
|
|
|
+ Date beginTime = DateUtil.beginOfWeek(curDate);
|
|
|
+ Date endTime = DateUtil.endOfWeek(curDate);
|
|
|
+
|
|
|
+ AppUser queryUser = new AppUser();
|
|
|
+ queryUser.setAgentFlag(1);
|
|
|
+ List<AppUser> list = appUserService.selectAppUserList(queryUser);
|
|
|
+
|
|
|
+ if (null != list && list.size() > 0) {
|
|
|
+ list.forEach(appUser -> {
|
|
|
+ String beginTimeStr = DateUtil.format(beginTime,"yyyy-MM-dd");
|
|
|
+ String endTimeStr = DateUtil.format(endTime,"yyyy-MM-dd");
|
|
|
+
|
|
|
|
|
|
- queryWrapper.ge(AppUserCount::getStrDate, beginTime);
|
|
|
- queryWrapper.le(AppUserCount::getStrDate, endTime);
|
|
|
+ queryWrapper.ge(AppUserCount::getStrDate, beginTimeStr);
|
|
|
+ queryWrapper.le(AppUserCount::getStrDate, endTimeStr);
|
|
|
queryWrapper.eq(AppUserCount::getAgentUserId, appUser.getUserid());
|
|
|
List<AppUserCount> appUserCountList = appUserCountService.list(queryWrapper);*/
|
|
|
- String beginTimeStr = DateUtil.format(beginTime,"yyyy-MM-dd");
|
|
|
- String endTimeStr = DateUtil.format(endTime,"yyyy-MM-dd");
|
|
|
- List<AppUserCount> appUserCountList = appUserCountService.getAppUserCountNew(appUser.getUserid(),beginTimeStr,endTimeStr);
|
|
|
- if (null != appUserCountList && appUserCountList.size() > 0) {
|
|
|
-
|
|
|
- double loseAmount = appUserCountList.stream().mapToDouble(e -> e.getGameLoseAmount()).sum();
|
|
|
-
|
|
|
- double winAmount = appUserCountList.stream().mapToDouble(e -> e.getGameWinAmount()).sum();
|
|
|
-
|
|
|
- double withdrawalCommission = appUserCountList.stream().mapToDouble(e -> e.getWithdrawalCommission()).sum();
|
|
|
-
|
|
|
- double gameCommission = appUserCountList.stream().mapToDouble(e -> e.getGameCommission()).sum();
|
|
|
-
|
|
|
- double liveCommission = appUserCountList.stream().mapToDouble(e -> e.getLiveCommission()).sum();
|
|
|
-
|
|
|
- double rechargeGive = appUserCountList.stream().mapToDouble(e -> e.getRechargeGive()).sum();
|
|
|
-
|
|
|
-
|
|
|
+ List<AppUserCount> appUserCountList = appUserCountService.getAppUserCountNew(appUser.getUserid(),beginTimeStr,endTimeStr);
|
|
|
+ if (null != appUserCountList && appUserCountList.size() > 0) {
|
|
|
+
|
|
|
+ double loseAmount = appUserCountList.stream().mapToDouble(e -> e.getGameLoseAmount()).sum();
|
|
|
+
|
|
|
+ double winAmount = appUserCountList.stream().mapToDouble(e -> e.getGameWinAmount()).sum();
|
|
|
+
|
|
|
+ double withdrawalCommission = appUserCountList.stream().mapToDouble(e -> e.getWithdrawalCommission()).sum();
|
|
|
+
|
|
|
+ double gameCommission = appUserCountList.stream().mapToDouble(e -> e.getGameCommission()).sum();
|
|
|
+
|
|
|
+ double liveCommission = appUserCountList.stream().mapToDouble(e -> e.getLiveCommission()).sum();
|
|
|
+
|
|
|
+ double rechargeGive = appUserCountList.stream().mapToDouble(e -> e.getRechargeGive()).sum();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- double money = (loseAmount - winAmount) - gameCommission - rechargeGive;
|
|
|
- if (money > 0) {
|
|
|
-
|
|
|
-
|
|
|
- if (null != appUserCountList && appUserCountList.size() > 0) {
|
|
|
- appUserCountList.forEach(userCount -> {
|
|
|
-
|
|
|
- AppUserAgent userAgent = appUserAgentService.selectInfo(userCount.getUserId());
|
|
|
- if(null == userAgent) {
|
|
|
- log.info("用户{},不是代理或者代理信息为空,停止分红",userCount.getUserId());
|
|
|
- return;
|
|
|
- }
|
|
|
- if (userAgent.getDividendGuaranteeRate() <= 0.00) {
|
|
|
- log.info("用户{},团队亏损{},或未设置分红比例,停止分红", userAgent.getUserId(), money);
|
|
|
- return;
|
|
|
- }
|
|
|
- double rate = userAgent.getDividendGuaranteeRate();
|
|
|
- double dividends = money * rate/100;
|
|
|
- AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
|
|
|
- appUserCountDividend.setUserId(userAgent.getUserId());
|
|
|
- appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
|
|
|
- appUserCountDividend.setBeginTime(beginTime);
|
|
|
- appUserCountDividend.setEndTime(endTime);
|
|
|
- appUserCountDividend.setProfitLoss(money);
|
|
|
- appUserCountDividend.setRate(rate);
|
|
|
- appUserCountDividend.setCoin(0.00);
|
|
|
- appUserCountDividend.setDiamondCoin(dividends);
|
|
|
- appUserCountDividend.setStatus(0);
|
|
|
- appUserCountDividendService.insertAppUserCountDividend(appUserCountDividend);
|
|
|
- });
|
|
|
- } else {
|
|
|
- log.info("用户{},所有下级亏损{},查询下级为空,停止分红", appUser.getUserid(), money);
|
|
|
- }
|
|
|
+ double money = (loseAmount - winAmount) - gameCommission - rechargeGive;
|
|
|
+ if (money > 0) {
|
|
|
+
|
|
|
+
|
|
|
+ AppUserAgent queryAppUserAgent = new AppUserAgent();
|
|
|
+ queryAppUserAgent.setPid(appUser.getUserid());
|
|
|
+ List<AppUserAgent> appUserAgentList = appUserAgentService.selectAppUserAgentList(queryAppUserAgent);
|
|
|
+ if (null != appUserAgentList && appUserAgentList.size() > 0) {
|
|
|
+ appUserAgentList.forEach(userAgent -> {
|
|
|
+ if (userAgent.getDividendGuaranteeRate() <= 0.00) {
|
|
|
+ log.info("用户{},团队亏损{},或未设置分红比例,停止分红", userAgent.getUserId(), money);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ double rate = userAgent.getDividendGuaranteeRate();
|
|
|
+ double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
|
|
|
+ appUserCountDividend.setUserId(userAgent.getUserId());
|
|
|
+ appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
|
|
|
+ appUserCountDividend.setBeginTime(beginTime);
|
|
|
+ appUserCountDividend.setEndTime(endTime);
|
|
|
+ appUserCountDividend.setProfitLoss(money);
|
|
|
+ appUserCountDividend.setRate(rate);
|
|
|
+ appUserCountDividend.setCoin(0.00);
|
|
|
+ appUserCountDividend.setDiamondCoin(dividends);
|
|
|
+ appUserCountDividend.setStatus(0);
|
|
|
+ appUserCountDividendService.insertAppUserCountDividend(appUserCountDividend);
|
|
|
+ });
|
|
|
} else {
|
|
|
- log.info("用户{},所有下级亏损{},不满足分红条件", appUser.getUserid(), money);
|
|
|
+ log.info("用户{},所有下级亏损{},查询下级为空,停止分红", appUser.getUserid(), money);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ log.info("用户{},所有下级亏损{},不满足分红条件", appUser.getUserid(), money);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- log.info("每周代理分红完成");
|
|
|
- }catch (Exception e){
|
|
|
- log.info("每周分红失败:{}",e.getMessage());
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ * 分红
|
|
|
+ * */
|
|
|
+ private void dealDividendsNew(String dateTime){
|
|
|
+ Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
|
|
|
+ if (StringUtils.isNotBlank(dateTime)) {
|
|
|
+ curDate = DateUtil.parse(dateTime, "yyyy-MM-dd");
|
|
|
+ } else {
|
|
|
+ dateTime = DateUtils.parseDateToStr("yyyy-MM-dd", curDate);
|
|
|
+ }
|
|
|
+ Date beginTime = DateUtil.beginOfWeek(curDate);
|
|
|
+ Date endTime = DateUtil.endOfWeek(curDate);
|
|
|
+
|
|
|
+ AppUser queryUser = new AppUser();
|
|
|
+ queryUser.setAgentFlag(1);
|
|
|
+ List<AppUser> list = appUserService.selectAppUserList(queryUser);
|
|
|
+
|
|
|
+ if (null != list && list.size() > 0) {
|
|
|
+ list.forEach(appUser -> {
|
|
|
+ AppUserAgent userAgent = appUserAgentService.selectInfo(appUser.getUserid());
|
|
|
+ if (userAgent.getDividendGuaranteeRate() <= 0.00) {
|
|
|
+ log.info("用户{},未设置分红比例,停止分红", userAgent.getUserId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String beginTimeStr = DateUtil.format(beginTime,"yyyy-MM-dd");
|
|
|
+ String endTimeStr = DateUtil.format(endTime,"yyyy-MM-dd");
|
|
|
+
|
|
|
+
|
|
|
+ queryWrapper.ge(AppUserCount::getStrDate, beginTimeStr);
|
|
|
+ queryWrapper.le(AppUserCount::getStrDate, endTimeStr);
|
|
|
+ queryWrapper.eq(AppUserCount::getAgentUserId, appUser.getUserid());
|
|
|
+ List<AppUserCount> appUserCountList = appUserCountService.list(queryWrapper);*/
|
|
|
+ List<AppUserCount> appUserCountList = appUserCountService.getAppUserCountNew(appUser.getUserid(),beginTimeStr,endTimeStr);
|
|
|
+ if (null != appUserCountList && appUserCountList.size() > 0) {
|
|
|
+
|
|
|
+ double loseAmount = appUserCountList.stream().mapToDouble(e -> e.getGameLoseAmount()).sum();
|
|
|
+
|
|
|
+ double winAmount = appUserCountList.stream().mapToDouble(e -> {
|
|
|
+ return e.getGameWinAmount() - (e.getGameBetting() - e.getGameLoseAmount());
|
|
|
+ }).sum();
|
|
|
+
|
|
|
+ double withdrawalCommission = appUserCountList.stream().mapToDouble(e -> e.getWithdrawalCommission()).sum();
|
|
|
+
|
|
|
+ double gameCommission = appUserCountList.stream().mapToDouble(e -> e.getGameCommission()).sum();
|
|
|
+
|
|
|
+ double liveCommission = appUserCountList.stream().mapToDouble(e -> e.getLiveCommission()).sum();
|
|
|
+
|
|
|
+ double rechargeGive = appUserCountList.stream().mapToDouble(e -> e.getRechargeGive()).sum();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ double money = (loseAmount - winAmount) - gameCommission - rechargeGive;
|
|
|
+ if (money > 0) {
|
|
|
+
|
|
|
+ double rate = userAgent.getDividendGuaranteeRate();
|
|
|
+ double dividends = BigDecimal.valueOf(money * rate/100).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ AppUserCountDividend appUserCountDividend = new AppUserCountDividend();
|
|
|
+ appUserCountDividend.setUserId(userAgent.getUserId());
|
|
|
+ appUserCountDividend.setDateNo(DateUtil.format(endTime, "yyyy-MM-dd"));
|
|
|
+ appUserCountDividend.setBeginTime(beginTime);
|
|
|
+ appUserCountDividend.setEndTime(endTime);
|
|
|
+ appUserCountDividend.setProfitLoss(money);
|
|
|
+ appUserCountDividend.setRate(rate);
|
|
|
+ appUserCountDividend.setCoin(0.00);
|
|
|
+ appUserCountDividend.setDiamondCoin(dividends);
|
|
|
+ appUserCountDividend.setStatus(0);
|
|
|
+ appUserCountDividendService.insertAppUserCountDividend(appUserCountDividend);
|
|
|
+ } else {
|
|
|
+ log.info("用户{},所有下级亏损{},没有亏损停止分红", appUser.getUserid(), money);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("用户{},团队没有流水停止分红", appUser.getUserid());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -354,6 +445,11 @@ public class AppUserCountTask {
|
|
|
appUserCountDividendService.reloadCache(dateTime,StringUtils.isBlank(topUserId)?null:Arrays.asList(Long.valueOf(topUserId)));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public void cleanCache(){
|
|
|
+ redisCache.deleteObject(CacheConstants.USER_GAME_RECORD_COUNT.concat("*"));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 金额为负数则转为正数
|
|
|
* */
|