|
@@ -250,87 +250,169 @@ 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);
|
|
|
- //查询所有总代理用户
|
|
|
- AppUser queryUser = new AppUser();
|
|
|
- queryUser.setAgentFlag(1);
|
|
|
- List<AppUser> list = appUserService.selectAppUserList(queryUser);
|
|
|
+ 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);
|
|
|
// List<AppUser> list = appUserService.selectTeamUserList();
|
|
|
- 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");
|
|
|
- //查询用户所有下级本周盈亏
|
|
|
+ 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");
|
|
|
+ //查询用户所有下级本周盈亏
|
|
|
/*LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
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 -> 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) - withdrawalCommission - gameCommission - liveCommission;
|
|
|
- double money = (loseAmount - winAmount) - gameCommission - rechargeGive;
|
|
|
- if (money > 0) {
|
|
|
- //金额大于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);
|
|
|
- }
|
|
|
+ double money = (loseAmount - winAmount) - gameCommission - rechargeGive;
|
|
|
+ if (money > 0) {
|
|
|
+ //金额大于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);
|
|
|
+// List<AppUser> list = appUserService.selectTeamUserList();
|
|
|
+ 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");
|
|
|
+ //查询用户所有下级本周盈亏
|
|
|
+ /*LambdaQueryWrapper<AppUserCount> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ 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 -> 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) - withdrawalCommission - gameCommission - liveCommission;
|
|
|
+ double money = (loseAmount - winAmount) - gameCommission - rechargeGive;
|
|
|
+ if (money > 0) {
|
|
|
+ //金额大于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());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|