|
@@ -0,0 +1,456 @@
|
|
|
+package com.zanxiang.game.back.serve.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.sd4324530.jtuple.Tuple2;
|
|
|
+import com.github.sd4324530.jtuple.Tuple3;
|
|
|
+import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
|
|
|
+import com.zanxiang.game.back.serve.dao.mapper.GameTencentAppApiOrderMapper;
|
|
|
+import com.zanxiang.game.back.serve.pojo.TencentAppReport;
|
|
|
+import com.zanxiang.game.back.serve.pojo.dto.OrderReportDTO;
|
|
|
+import com.zanxiang.game.back.serve.pojo.entity.*;
|
|
|
+import com.zanxiang.game.back.serve.pojo.enums.ActionTypeEnum;
|
|
|
+import com.zanxiang.game.back.serve.pojo.enums.BackStatusEnum;
|
|
|
+import com.zanxiang.game.back.serve.pojo.enums.BackUnitEnum;
|
|
|
+import com.zanxiang.game.back.serve.service.*;
|
|
|
+import com.zanxiang.game.back.serve.utils.BackPolicyUtil;
|
|
|
+import com.zanxiang.module.util.DateUtil;
|
|
|
+import com.zanxiang.module.util.NumberUtil;
|
|
|
+import com.zanxiang.module.util.URIUtil;
|
|
|
+import com.zanxiang.module.util.encryption.Md5Util;
|
|
|
+import com.zanxiang.module.util.exception.BaseException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class GameTencentAppApiOrderServiceImpl extends ServiceImpl<GameTencentAppApiOrderMapper, GameTencentAppApiOrder>
|
|
|
+implements IGameTencentAppApiOrderService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameTencentAppApiBackLogService gameTencentAppApiBackLogService;
|
|
|
+ @Autowired
|
|
|
+ private IGameBackPolicyService gameBackPolicyService;
|
|
|
+ @Autowired
|
|
|
+ private IGameTencentAppApiUserService gameTencentAppApiUserService;
|
|
|
+ @Autowired
|
|
|
+ private IGameTencentAppApiOrderSplitLogService gameTencentAppApiOrderSplitLogService;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+ @Autowired
|
|
|
+ private IGameTencentAppCallbackService gameTencentAppCallbackService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean orderBack(GameTencentAppApiOrder orderLog) {
|
|
|
+ if (!Objects.equals(orderLog.getOrderStatus(), OrderStatusEnum.SUCCESS_PAY.getValue())) {
|
|
|
+ // 只要回传 支付行为
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ GameTencentAppApiUser userLog = gameTencentAppApiUserService.getOne(new LambdaQueryWrapper<GameTencentAppApiUser>()
|
|
|
+ .eq(GameTencentAppApiUser::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiUser::getUserId, orderLog.getUserId())
|
|
|
+ .eq(GameTencentAppApiUser::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .orderByDesc(GameTencentAppApiUser::getCreateTime)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ if (userLog == null) {
|
|
|
+ return update(new LambdaUpdateWrapper<GameTencentAppApiOrder>()
|
|
|
+ .set(GameTencentAppApiOrder::getIsBack, BackStatusEnum.FAILED.getBackStatus())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMoney, orderLog.getRechargeMoney())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMsg, "回传失败!找不到回传用户")
|
|
|
+ .eq(GameTencentAppApiOrder::getId, orderLog.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ GameBackPolicy gameBackPolicy = gameBackPolicyService.getById(orderLog.getBackPolicyId());
|
|
|
+ Tuple3<Boolean, Long, String> backInfo = BackPolicyUtil.backOrder(orderLog.getOrderId(), gameBackPolicy, orderLog.getRechargeMoney(),
|
|
|
+ orderLog.getIsFirstOrder(),
|
|
|
+ orderLog.getPayTime(),
|
|
|
+ // 此处使用用户最近一次的重新染色时间
|
|
|
+ userLog.getCreateTime(),
|
|
|
+ orderLog.getUserId(),
|
|
|
+ new TencentOrderBackPolicyCheck(this, gameBackPolicy, userLog, orderLog));
|
|
|
+ boolean doBack = backInfo.first;
|
|
|
+ Long backMoney = backInfo.second;
|
|
|
+ String backMsg = backInfo.third;
|
|
|
+ if (!doBack) {
|
|
|
+ return update(new LambdaUpdateWrapper<GameTencentAppApiOrder>()
|
|
|
+ .set(GameTencentAppApiOrder::getIsBack, BackStatusEnum.NO.getBackStatus())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMoney, backMoney)
|
|
|
+ .set(GameTencentAppApiOrder::getBackMsg, backMsg)
|
|
|
+ .eq(GameTencentAppApiOrder::getId, orderLog.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // 拆单
|
|
|
+ Tuple3<Boolean, Long, List<Tuple2<Long, LocalDateTime>>> splitResult = BackPolicyUtil.splitOrder(gameBackPolicy, backMoney);
|
|
|
+ if (splitResult.first) {
|
|
|
+ // 需要拆单
|
|
|
+ List<GameTencentAppApiOrderSplitLog> splitOrderLogList = new ArrayList<>(splitResult.third.size());
|
|
|
+ for (int i = 0; i < splitResult.third.size(); i++) {
|
|
|
+ Tuple2<Long, LocalDateTime> splitOrder = splitResult.third.get(i);
|
|
|
+ splitOrderLogList.add(GameTencentAppApiOrderSplitLog.builder()
|
|
|
+ .backDay(splitOrder.second.toLocalDate())
|
|
|
+ .orderNo(orderLog.getOrderId())
|
|
|
+ .backIndex(i + 1)
|
|
|
+ .backCount(splitResult.third.size())
|
|
|
+ .splitMoney(splitOrder.first)
|
|
|
+ .backTime(splitOrder.second)
|
|
|
+ .backStatus(BackStatusEnum.NO.getBackStatus())
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ gameTencentAppApiOrderSplitLogService.saveBatch(splitOrderLogList);
|
|
|
+ return update(new LambdaUpdateWrapper<GameTencentAppApiOrder>()
|
|
|
+ .set(GameTencentAppApiOrder::getIsBack, BackStatusEnum.NO.getBackStatus())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMoney, splitResult.second)
|
|
|
+ .set(GameTencentAppApiOrder::getBackMsg, backMsg)
|
|
|
+ .eq(GameTencentAppApiOrder::getId, orderLog.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Tuple2<BackStatusEnum, String> backResult = doCallback(orderLog, orderLog.getPayTime(), backMoney);
|
|
|
+ if (StringUtils.isNotBlank(backResult.second)) {
|
|
|
+ backMsg = backMsg + ("回传失败:" + backResult.second);
|
|
|
+ }
|
|
|
+ return update(new LambdaUpdateWrapper<GameTencentAppApiOrder>()
|
|
|
+ .set(GameTencentAppApiOrder::getIsBack, backResult.first.getBackStatus())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMoney, backMoney)
|
|
|
+ .set(GameTencentAppApiOrder::getBackMsg, backMsg)
|
|
|
+ .eq(GameTencentAppApiOrder::getId, orderLog.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean tencentOrderReport(OrderReportDTO dto) {
|
|
|
+ listByIds(dto.getOrderIds()).stream()
|
|
|
+ .filter(order -> !Objects.equals(order.getIsBack(), BackStatusEnum.SUCCESS.getBackStatus()))
|
|
|
+ .forEach(orderLog -> {
|
|
|
+ if (dto.getSplitOrder()) {
|
|
|
+ AtomicLong total = new AtomicLong(0);
|
|
|
+ dto.getSplitMoney().forEach(money -> {
|
|
|
+ total.addAndGet(NumberUtil.multiply100(money).longValue());
|
|
|
+ });
|
|
|
+ if (!orderLog.getRechargeMoney().equals(total.get())) {
|
|
|
+ throw new BaseException("订单充值金额和回传金额对不上");
|
|
|
+ }
|
|
|
+ log.error("手动拆单回传:{}-{}", orderLog.getId(), StringUtils.join(dto.getSplitMoney(), ","));
|
|
|
+ List<GameTencentAppApiOrderSplitLog> splitOrderLogList = new ArrayList<>(dto.getSplitMoney().size());
|
|
|
+ LocalDateTime beginTime = LocalDateTime.now();
|
|
|
+ long backMoneyTotal = 0L;
|
|
|
+ for (int i = 0; i < dto.getSplitMoney().size(); i++) {
|
|
|
+ long backMoney = NumberUtil.multiply100(dto.getSplitMoney().get(i)).longValue();
|
|
|
+ LocalDateTime backTime = beginTime;
|
|
|
+ backMoneyTotal += backMoney;
|
|
|
+ splitOrderLogList.add(GameTencentAppApiOrderSplitLog.builder()
|
|
|
+ .backDay(backTime.toLocalDate())
|
|
|
+ .orderNo(orderLog.getOrderId())
|
|
|
+ .backIndex(i + 1)
|
|
|
+ .backCount(dto.getSplitMoney().size())
|
|
|
+ .splitMoney(backMoney)
|
|
|
+ .backTime(backTime)
|
|
|
+ .backStatus(BackStatusEnum.NO.getBackStatus())
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .build());
|
|
|
+ beginTime = beginTime.plusMinutes(RandomUtils.nextInt(dto.getBetweenMinuteMin(), dto.getBetweenMinuteMax()));
|
|
|
+ }
|
|
|
+ gameTencentAppApiOrderSplitLogService.saveBatch(splitOrderLogList);
|
|
|
+ update(new LambdaUpdateWrapper<GameTencentAppApiOrder>()
|
|
|
+ .set(GameTencentAppApiOrder::getIsBack, BackStatusEnum.NO.getBackStatus())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMoney, backMoneyTotal)
|
|
|
+ .set(GameTencentAppApiOrder::getBackMsg, "手动触发回传(拆单回传)")
|
|
|
+ .eq(GameTencentAppApiOrder::getId, orderLog.getId())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ log.error("手动直接回传:{}-{}", orderLog.getId(), dto.getBackMoney());
|
|
|
+ long backMoney = NumberUtil.multiply100(dto.getBackMoney()).longValue();
|
|
|
+ Tuple2<BackStatusEnum, String> backResult = doCallback(orderLog, orderLog.getPayTime(), backMoney);
|
|
|
+ String backMsg = "手动触发回传!";
|
|
|
+ if (StringUtils.isNotBlank(backResult.second)) {
|
|
|
+ backMsg += ("回传失败:" + backResult.second);
|
|
|
+ }
|
|
|
+ update(new LambdaUpdateWrapper<GameTencentAppApiOrder>()
|
|
|
+ .set(GameTencentAppApiOrder::getIsBack, backResult.first.getBackStatus())
|
|
|
+ .set(GameTencentAppApiOrder::getBackMoney, backMoney)
|
|
|
+ .set(GameTencentAppApiOrder::getBackMsg, backMsg)
|
|
|
+ .eq(GameTencentAppApiOrder::getId, orderLog.getId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Tuple2<BackStatusEnum, String> doCallback(GameTencentAppApiOrder orderLog, LocalDateTime backTime, Long backMoney) {
|
|
|
+
|
|
|
+ GameTencentAppCallback callback = gameTencentAppCallbackService.getUserCallback(orderLog.getGameId(), orderLog.getImei(), orderLog.getOaid(), orderLog.getAndroidId(), orderLog.getIdfa(), orderLog.getCaid());
|
|
|
+ if(callback == null) {
|
|
|
+ return Tuple2.with(BackStatusEnum.FAILED, "找不到监测链接");
|
|
|
+ }
|
|
|
+ String callbackUrl = URIUtil.decodeURIComponent(callback.getCallback());
|
|
|
+
|
|
|
+ Map<String, Object> actionParam = new HashMap<>(2);
|
|
|
+ actionParam.put("claim_type", 4);
|
|
|
+ actionParam.put("value", backMoney);
|
|
|
+ TencentAppReport reportData = TencentAppReport.builder()
|
|
|
+ .actions(Collections.singletonList(TencentAppReport.Action.builder()
|
|
|
+ .action_time(DateUtil.localDateTimeToSecond(orderLog.getRegisterTime()))
|
|
|
+ .userr_id(TencentAppReport.UserId.builder()
|
|
|
+ .hash_imei(StringUtils.isBlank(orderLog.getImei()) ? null : Md5Util.encrypt32(orderLog.getImei().toLowerCase()).toLowerCase())
|
|
|
+ .hash_oaid(StringUtils.isBlank(orderLog.getOaid()) ? null : Md5Util.encrypt32(orderLog.getOaid()).toLowerCase())
|
|
|
+ .hash_android_id(StringUtils.isBlank(orderLog.getAndroidId()) ? null : Md5Util.encrypt32(orderLog.getAndroidId()).toLowerCase())
|
|
|
+ .hash_idfa(StringUtils.isBlank(orderLog.getIdfa()) ? null : Md5Util.encrypt32(orderLog.getIdfa().toUpperCase()).toLowerCase())
|
|
|
+ .caid(orderLog.getCaid())
|
|
|
+ .build())
|
|
|
+ .action_type("PURCHASE")
|
|
|
+ .trace(callback.getClickId())
|
|
|
+ .action_param(actionParam)
|
|
|
+ .build()))
|
|
|
+ .build();
|
|
|
+
|
|
|
+
|
|
|
+ BackStatusEnum backStatus;
|
|
|
+ String backLog;
|
|
|
+ try {
|
|
|
+ ResponseEntity<String> response = restTemplate.postForEntity(callbackUrl, reportData, String.class);
|
|
|
+ if (response.getStatusCode().is2xxSuccessful()) {
|
|
|
+ backStatus = BackStatusEnum.SUCCESS;
|
|
|
+ backLog = "回传成功";
|
|
|
+ } else {
|
|
|
+ backStatus = BackStatusEnum.FAILED;
|
|
|
+ backLog = "回传识别,失败信息:" + response.getBody();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ backStatus = BackStatusEnum.FAILED;
|
|
|
+ backLog = "回传识别,失败原因:" + e.getMessage();
|
|
|
+ }
|
|
|
+
|
|
|
+ String actionType = ActionTypeEnum.PURCHASE.getActionType();
|
|
|
+
|
|
|
+ GameTencentAppApiBackLog gameTencentBackLog = GameTencentAppApiBackLog.builder()
|
|
|
+ .gameId(orderLog.getGameId())
|
|
|
+ .userId(orderLog.getUserId())
|
|
|
+ .adAccountId(orderLog.getAdAccountId())
|
|
|
+ .actionTime(backTime)
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
+ .actionType(actionType)
|
|
|
+ .orderId(orderLog.getOrderId())
|
|
|
+ .imei(orderLog.getImei())
|
|
|
+ .oaid(orderLog.getOaid())
|
|
|
+ .androidId(orderLog.getAndroidId())
|
|
|
+ .idfa(orderLog.getIdfa())
|
|
|
+ .caid(orderLog.getCaid())
|
|
|
+ .backLog(backLog)
|
|
|
+ .actionParam(actionParam.toString())
|
|
|
+ .build();
|
|
|
+ gameTencentAppApiBackLogService.save(gameTencentBackLog);
|
|
|
+ return Tuple2.with(backStatus, gameTencentBackLog.getBackLog());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class TencentOrderBackPolicyCheck implements BackPolicyUtil.IBackPolicyCheck {
|
|
|
+ private final IGameTencentAppApiOrderService gameTencentAppApiOrderService;
|
|
|
+ private final GameBackPolicy gameBackPolicy;
|
|
|
+ private final GameTencentAppApiUser userLog;
|
|
|
+ private final GameTencentAppApiOrder orderLog;
|
|
|
+
|
|
|
+ public TencentOrderBackPolicyCheck(IGameTencentAppApiOrderService gameTencentAppApiOrderService,
|
|
|
+ GameBackPolicy gameBackPolicy,
|
|
|
+ GameTencentAppApiUser userLog,
|
|
|
+ GameTencentAppApiOrder orderLog) {
|
|
|
+ this.gameTencentAppApiOrderService = gameTencentAppApiOrderService;
|
|
|
+ this.gameBackPolicy = gameBackPolicy;
|
|
|
+ this.userLog = userLog;
|
|
|
+ this.orderLog = orderLog;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long backCountForFixedRate(int numberOfRound, BackUnitEnum backUnit, Boolean firstPolicy) {
|
|
|
+ numberOfRound = numberOfRound - 1;
|
|
|
+ if (backUnit == BackUnitEnum.UNIT_ONCE) {
|
|
|
+ return gameTencentAppApiOrderService.list(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsFirstOrder, firstPolicy)
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ .orderByDesc(GameTencentAppApiOrder::getCreateTime)
|
|
|
+ .last("limit " + numberOfRound)
|
|
|
+ ).stream().filter(log -> log.getIsBack().equals(BackStatusEnum.SUCCESS.getBackStatus())).count();
|
|
|
+ } else if (backUnit == BackUnitEnum.UNIT_DAY) {
|
|
|
+ return gameTencentAppApiOrderService.list(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .apply(firstPolicy, "date(recharge_time) = date(pay_time)")
|
|
|
+ .apply(!firstPolicy, "date(recharge_time) != date(pay_time)")
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ .orderByDesc(GameTencentAppApiOrder::getCreateTime)
|
|
|
+ .last("limit " + numberOfRound)
|
|
|
+ ).stream().filter(log -> log.getIsBack().equals(BackStatusEnum.SUCCESS.getBackStatus())).count();
|
|
|
+ } else if (backUnit == BackUnitEnum.UNIT_TIME_DAY) {
|
|
|
+ return gameTencentAppApiOrderService.list(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .apply(firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) < 24")
|
|
|
+ .apply(!firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) >= 24")
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ .orderByDesc(GameTencentAppApiOrder::getCreateTime)
|
|
|
+ .last("limit " + numberOfRound)
|
|
|
+ ).stream().filter(log -> log.getIsBack().equals(BackStatusEnum.SUCCESS.getBackStatus())).count();
|
|
|
+ } else if (backUnit == BackUnitEnum.UNIT_TIME_2DAY) {
|
|
|
+ return gameTencentAppApiOrderService.list(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .apply(firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) < 48")
|
|
|
+ .apply(!firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) >= 48")
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ .orderByDesc(GameTencentAppApiOrder::getCreateTime)
|
|
|
+ .last("limit " + numberOfRound)
|
|
|
+ ).stream().filter(log -> log.getIsBack().equals(BackStatusEnum.SUCCESS.getBackStatus())).count();
|
|
|
+ } else if (backUnit == BackUnitEnum.LARGE_AMOUNT) {
|
|
|
+ return gameTencentAppApiOrderService.list(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ .orderByDesc(GameTencentAppApiOrder::getCreateTime)
|
|
|
+ .last("limit " + numberOfRound)
|
|
|
+ ).stream().filter(log -> log.getIsBack().equals(BackStatusEnum.SUCCESS.getBackStatus())).count();
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("不支持的回传单位[" + backUnit.getValue() + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long backCountForUser(BackUnitEnum backUnit, String userId, Boolean firstPolicy) {
|
|
|
+ if (backUnit == BackUnitEnum.UNIT_ONCE) {
|
|
|
+ if (firstPolicy) {
|
|
|
+ // 首单直接返回 0,必定回传
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return gameTencentAppApiOrderService.count(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, userId)
|
|
|
+ .eq(GameTencentAppApiOrder::getIsFirstOrder, firstPolicy)
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ } else if (backUnit == BackUnitEnum.UNIT_DAY) {
|
|
|
+ return gameTencentAppApiOrderService.count(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, userId)
|
|
|
+ .apply(firstPolicy, "date(recharge_time) = date(pay_time)")
|
|
|
+ .apply(!firstPolicy, "date(recharge_time) != date(pay_time)")
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ } else if (backUnit == BackUnitEnum.UNIT_TIME_DAY) {
|
|
|
+ return gameTencentAppApiOrderService.count(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, userId)
|
|
|
+ .apply(firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) < 24")
|
|
|
+ .apply(!firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) >= 24")
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ } else if (backUnit == BackUnitEnum.UNIT_TIME_2DAY) {
|
|
|
+ return gameTencentAppApiOrderService.count(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, userId)
|
|
|
+ .apply(firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) < 48")
|
|
|
+ .apply(!firstPolicy, "TIMESTAMPDIFF(HOUR, recharge_time, pay_time) >= 48")
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ } else if (backUnit == BackUnitEnum.LARGE_AMOUNT) {
|
|
|
+ return gameTencentAppApiOrderService.count(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, userId)
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("不支持的回传单位[" + backUnit.getValue() + "]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long markUpOfFixedRate(int numberOfRound, Long markUpTime) {
|
|
|
+ numberOfRound = numberOfRound - 1;
|
|
|
+ return gameTencentAppApiOrderService.list(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .apply("TIMESTAMPDIFF(MINUTE, recharge_time, pay_time) > {0}", markUpTime)
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ .orderByDesc(GameTencentAppApiOrder::getCreateTime)
|
|
|
+ .last("limit " + numberOfRound)
|
|
|
+ ).stream().filter(log -> log.getIsBack().equals(BackStatusEnum.SUCCESS.getBackStatus())).count();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long markUpForUser(String userId, Long markUpTime) {
|
|
|
+ return gameTencentAppApiOrderService.count(new LambdaQueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, userId)
|
|
|
+ .apply("TIMESTAMPDIFF(MINUTE, recharge_time, pay_time) > {0}", markUpTime)
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long totalRechargeAmount() {
|
|
|
+ return gameTencentAppApiOrderService.count(new QueryWrapper<GameTencentAppApiOrder>()
|
|
|
+ .select("ifnull(sum(recharge_money), 0) as recharge_money").lambda()
|
|
|
+ .eq(GameTencentAppApiOrder::getGameId, orderLog.getGameId())
|
|
|
+ .eq(GameTencentAppApiOrder::getAdAccountId, orderLog.getAdAccountId())
|
|
|
+ .eq(GameTencentAppApiOrder::getBackPolicyId, gameBackPolicy.getId())
|
|
|
+ .eq(GameTencentAppApiOrder::getOrderStatus, OrderStatusEnum.SUCCESS_PAY.getValue())
|
|
|
+ .eq(GameTencentAppApiOrder::getUserId, orderLog.getUserId())
|
|
|
+ .ne(GameTencentAppApiOrder::getOrderId, orderLog.getOrderId())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|