|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.github.sd4324530.jtuple.Tuple2;
|
|
import com.github.sd4324530.jtuple.Tuple3;
|
|
import com.github.sd4324530.jtuple.Tuple3;
|
|
import com.github.sd4324530.jtuple.Tuples;
|
|
import com.github.sd4324530.jtuple.Tuples;
|
|
import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
|
|
import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
|
|
@@ -21,6 +22,7 @@ import com.zanxiang.game.back.serve.pojo.vo.GameOceanengineOrderLogVO;
|
|
import com.zanxiang.game.back.serve.service.IGameBackPolicyService;
|
|
import com.zanxiang.game.back.serve.service.IGameBackPolicyService;
|
|
import com.zanxiang.game.back.serve.service.IGameOceanengineBackLogService;
|
|
import com.zanxiang.game.back.serve.service.IGameOceanengineBackLogService;
|
|
import com.zanxiang.game.back.serve.service.IGameOceanengineOrderLogService;
|
|
import com.zanxiang.game.back.serve.service.IGameOceanengineOrderLogService;
|
|
|
|
+import com.zanxiang.game.back.serve.service.IGameOceanengineOrderSplitLogService;
|
|
import com.zanxiang.game.back.serve.service.IGameOceanengineUserLogService;
|
|
import com.zanxiang.game.back.serve.service.IGameOceanengineUserLogService;
|
|
import com.zanxiang.game.back.serve.utils.BackPolicyUtil;
|
|
import com.zanxiang.game.back.serve.utils.BackPolicyUtil;
|
|
import com.zanxiang.game.back.serve.utils.OrderUtil;
|
|
import com.zanxiang.game.back.serve.utils.OrderUtil;
|
|
@@ -64,50 +66,83 @@ public class GameOceanengineOrderLogServiceImpl extends ServiceImpl<GameOceaneng
|
|
private IAgentRpc agentRpc;
|
|
private IAgentRpc agentRpc;
|
|
@Autowired
|
|
@Autowired
|
|
private NacosDynamicParamConfig dynamicParamConfig;
|
|
private NacosDynamicParamConfig dynamicParamConfig;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IGameOceanengineOrderSplitLogService gameOceanengineOrderSplitLogService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public boolean callback(GameOceanengineOrderLog orderLog, boolean mustBack, Long backMoneyOfInput) {
|
|
|
|
- boolean doBack;
|
|
|
|
- Long backMoney;
|
|
|
|
- String backMsg;
|
|
|
|
- if (mustBack) {
|
|
|
|
- doBack = true;
|
|
|
|
- backMoney = backMoneyOfInput;
|
|
|
|
- backMsg = "手动触发的回传";
|
|
|
|
- } else {
|
|
|
|
- if (!Objects.equals(orderLog.getOrderStatus(), OrderStatusEnum.SUCCESS_PAY.getValue())) {
|
|
|
|
- // 头条只要回传支付订单
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- // 用户回传失败
|
|
|
|
- GameOceanengineUserLog userLog = userLog(orderLog);
|
|
|
|
- if (userLog == null) {
|
|
|
|
- doBack = false;
|
|
|
|
- backMoney = orderLog.getAmount();
|
|
|
|
- backMsg = "回传失败!找不到回传用户";
|
|
|
|
- } else {
|
|
|
|
- GameBackPolicy gameBackPolicy = gameBackPolicyService.getById(orderLog.getBackPolicyId());
|
|
|
|
- Tuple3<Boolean, Long, String> backInfo = BackPolicyUtil.backOrder(orderLog.getOrderNo(), gameBackPolicy, orderLog.getAmount(),
|
|
|
|
- orderLog.getIsFirstOrder(),
|
|
|
|
- orderLog.getPayTime(),
|
|
|
|
- // 此处使用用户最近一次的重新染色时间
|
|
|
|
- userLog.getCreateTime(),
|
|
|
|
- orderLog.getOpenId(),
|
|
|
|
- new OceanengineOrderBackPolicyCheck(this, userLog, orderLog, gameBackPolicy)
|
|
|
|
|
|
+ public boolean callback(GameOceanengineOrderLog orderLog) {
|
|
|
|
+ if (!Objects.equals(orderLog.getOrderStatus(), OrderStatusEnum.SUCCESS_PAY.getValue())) {
|
|
|
|
+ // 头条只要回传支付订单
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ GameOceanengineUserLog userLog = userLog(orderLog);
|
|
|
|
+ if (userLog == null) {
|
|
|
|
+ // 找不到用户
|
|
|
|
+ return update(new LambdaUpdateWrapper<GameOceanengineOrderLog>()
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackStatus, BackStatusEnum.NO)
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMoney, orderLog.getAmount())
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMsg, "回传失败!找不到回传用户")
|
|
|
|
+ .eq(GameOceanengineOrderLog::getId, orderLog.getId())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ GameBackPolicy gameBackPolicy = gameBackPolicyService.getById(orderLog.getBackPolicyId());
|
|
|
|
+ Tuple3<Boolean, Long, String> backInfo = BackPolicyUtil.backOrder(orderLog.getOrderNo(), gameBackPolicy, orderLog.getAmount(),
|
|
|
|
+ orderLog.getIsFirstOrder(),
|
|
|
|
+ orderLog.getPayTime(),
|
|
|
|
+ // 此处使用用户最近一次的重新染色时间
|
|
|
|
+ userLog.getCreateTime(),
|
|
|
|
+ orderLog.getOpenId(),
|
|
|
|
+ new OceanengineOrderBackPolicyCheck(this, userLog, orderLog, gameBackPolicy)
|
|
|
|
+ );
|
|
|
|
+ boolean doBack = backInfo.first;
|
|
|
|
+ Long backMoney = backInfo.second;
|
|
|
|
+ String backMsg = backInfo.third;
|
|
|
|
+
|
|
|
|
+ if (!doBack) {
|
|
|
|
+ // 不回传
|
|
|
|
+ return update(new LambdaUpdateWrapper<GameOceanengineOrderLog>()
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackStatus, BackStatusEnum.NO.getBackStatus())
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMoney, backMoney)
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMsg, backMsg)
|
|
|
|
+ .eq(GameOceanengineOrderLog::getId, orderLog.getId())
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ // 拆单
|
|
|
|
+ Tuple3<Boolean, Long, List<Tuple2<Long, LocalDateTime>>> splitResult = BackPolicyUtil.splitOrder(gameBackPolicy, backMoney);
|
|
|
|
+ if (splitResult.first) {
|
|
|
|
+ // 需要拆单
|
|
|
|
+ List<GameOceanengineOrderSplitLog> 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(GameOceanengineOrderSplitLog.builder()
|
|
|
|
+ .backDay(splitOrder.second.toLocalDate())
|
|
|
|
+ .orderNo(orderLog.getOrderNo())
|
|
|
|
+ .backIndex(i + 1)
|
|
|
|
+ .backCount(splitResult.third.size())
|
|
|
|
+ .splitMoney(splitOrder.first)
|
|
|
|
+ .backTime(splitOrder.second)
|
|
|
|
+ .backStatus(BackStatusEnum.NO.getBackStatus())
|
|
|
|
+ .createTime(LocalDateTime.now())
|
|
|
|
+ .build()
|
|
);
|
|
);
|
|
- doBack = backInfo.first;
|
|
|
|
- backMoney = backInfo.second;
|
|
|
|
- backMsg = backInfo.third;
|
|
|
|
}
|
|
}
|
|
|
|
+ gameOceanengineOrderSplitLogService.saveBatch(splitOrderLogList);
|
|
|
|
+ return update(new LambdaUpdateWrapper<GameOceanengineOrderLog>()
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackStatus, BackStatusEnum.NO.getBackStatus())
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMoney, splitResult.second)
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMsg, backMsg)
|
|
|
|
+ .eq(GameOceanengineOrderLog::getId, orderLog.getId())
|
|
|
|
+ );
|
|
}
|
|
}
|
|
- BackStatusEnum backStatus = BackStatusEnum.NO;
|
|
|
|
- orderLog.setBackMoney(backMoney);
|
|
|
|
- if (doBack) {
|
|
|
|
- backStatus = doCallback(orderLog);
|
|
|
|
|
|
+
|
|
|
|
+ Tuple2<BackStatusEnum, String> backResult = doCallback(orderLog, backMoney);
|
|
|
|
+ if (StringUtils.isNotBlank(backResult.second)) {
|
|
|
|
+ backMsg = backMsg + ("回传失败:" + backResult.second);
|
|
}
|
|
}
|
|
return update(new LambdaUpdateWrapper<GameOceanengineOrderLog>()
|
|
return update(new LambdaUpdateWrapper<GameOceanengineOrderLog>()
|
|
- .set(GameOceanengineOrderLog::getBackStatus, backStatus.getBackStatus())
|
|
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackStatus, backResult.first.getBackStatus())
|
|
.set(GameOceanengineOrderLog::getBackMoney, backMoney)
|
|
.set(GameOceanengineOrderLog::getBackMoney, backMoney)
|
|
.set(GameOceanengineOrderLog::getBackMsg, backMsg)
|
|
.set(GameOceanengineOrderLog::getBackMsg, backMsg)
|
|
.eq(GameOceanengineOrderLog::getId, orderLog.getId())
|
|
.eq(GameOceanengineOrderLog::getId, orderLog.getId())
|
|
@@ -141,47 +176,31 @@ public class GameOceanengineOrderLogServiceImpl extends ServiceImpl<GameOceaneng
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- private List<GameOceanengineOrderLogVO> toVOBatch(List<GameOceanengineOrderLog> logList) {
|
|
|
|
- if (CollectionUtils.isEmpty(logList)) {
|
|
|
|
- return Collections.emptyList();
|
|
|
|
- }
|
|
|
|
- Set<String> agentKeys = logList.stream().map(GameOceanengineOrderLog::getAgentKey).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
|
|
|
|
- Map<String, AgentRpcVO> agentMap = CollectionUtils.isEmpty(agentKeys) ? Collections.emptyMap() : agentRpc.getByAgentKeys(new ArrayList<>(agentKeys))
|
|
|
|
- .getData().stream().collect(Collectors.toMap(AgentRpcVO::getAgentKey, Function.identity()));
|
|
|
|
- return logList.stream().map(log -> {
|
|
|
|
- GameOceanengineOrderLogVO vo = toVOSimple(log);
|
|
|
|
- if (StringUtils.isNotBlank(log.getAgentKey())) {
|
|
|
|
- AgentRpcVO agent = agentMap.get(log.getAgentKey());
|
|
|
|
- if (agent != null) {
|
|
|
|
- vo.setAgentName(agent.getAgentName());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return vo;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private GameOceanengineOrderLogVO toVOSimple(GameOceanengineOrderLog log) {
|
|
|
|
- if (log == null) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- GameOceanengineOrderLogVO vo = BeanUtil.copy(log, GameOceanengineOrderLogVO.class);
|
|
|
|
- vo.setRegPayIntervalTime(OrderUtil.regPayIntervalTime(log.getPayTime(), log.getRegTime()));
|
|
|
|
- return vo;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public boolean oceanengineOrderReport(List<Long> ids, Long backMoney) {
|
|
public boolean oceanengineOrderReport(List<Long> ids, Long backMoney) {
|
|
listByIds(ids).stream()
|
|
listByIds(ids).stream()
|
|
.filter(order -> !Objects.equals(order.getBackStatus(), BackStatusEnum.SUCCESS.getBackStatus()))
|
|
.filter(order -> !Objects.equals(order.getBackStatus(), BackStatusEnum.SUCCESS.getBackStatus()))
|
|
.forEach(orderLog -> {
|
|
.forEach(orderLog -> {
|
|
log.error("手动回传:{}-{}", orderLog.getId(), backMoney);
|
|
log.error("手动回传:{}-{}", orderLog.getId(), backMoney);
|
|
- callback(orderLog, true, backMoney);
|
|
|
|
|
|
+ orderLog.setBackMoney(backMoney);
|
|
|
|
+ Tuple2<BackStatusEnum, String> backResult = doCallback(orderLog, backMoney);
|
|
|
|
+ String backMsg = "手动触发回传";
|
|
|
|
+ if (StringUtils.isNotBlank(backResult.second)) {
|
|
|
|
+ backMsg += ("回传失败:" + backResult.second);
|
|
|
|
+ }
|
|
|
|
+ update(new LambdaUpdateWrapper<GameOceanengineOrderLog>()
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackStatus, backResult.first.getBackStatus())
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMoney, backMoney)
|
|
|
|
+ .set(GameOceanengineOrderLog::getBackMsg, backMsg)
|
|
|
|
+ .eq(GameOceanengineOrderLog::getId, orderLog.getId())
|
|
|
|
+ );
|
|
});
|
|
});
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- private BackStatusEnum doCallback(GameOceanengineOrderLog orderLog) {
|
|
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Tuple2<BackStatusEnum, String> doCallback(GameOceanengineOrderLog orderLog, Long backMoney) {
|
|
GameOceanengineUserLog userLog = userLog(orderLog);
|
|
GameOceanengineUserLog userLog = userLog(orderLog);
|
|
if (userLog == null) {
|
|
if (userLog == null) {
|
|
gameOceanengineBackLogService.save(GameOceanengineBackLog.builder()
|
|
gameOceanengineBackLogService.save(GameOceanengineBackLog.builder()
|
|
@@ -197,18 +216,16 @@ public class GameOceanengineOrderLogServiceImpl extends ServiceImpl<GameOceaneng
|
|
.backStatus(BackStatusEnum.FAILED.getBackStatus())
|
|
.backStatus(BackStatusEnum.FAILED.getBackStatus())
|
|
.errMsg("找不到用户注册信息")
|
|
.errMsg("找不到用户注册信息")
|
|
.build());
|
|
.build());
|
|
- return BackStatusEnum.FAILED;
|
|
|
|
|
|
+ return Tuple2.with(BackStatusEnum.FAILED, "找不到用户注册信息");
|
|
}
|
|
}
|
|
- Set<Long> keyAccountIds = StringUtils.isBlank(dynamicParamConfig.getBackOfKeyAccountIds()) ? Collections.emptySet() :
|
|
|
|
- Arrays.stream(dynamicParamConfig.getBackOfKeyAccountIds().split(",")).map(Long::parseLong).collect(Collectors.toSet());
|
|
|
|
- Integer eventType = keyAccountIds.contains(orderLog.getAccountId()) ? MiniGameCallback.EventType.GAME_ADDICTION.getEventType() : MiniGameCallback.EventType.ACTIVE_PAY.getEventType();
|
|
|
|
|
|
+ Integer eventType = MiniGameCallback.EventType.ACTIVE_PAY.getEventType();
|
|
MiniGameCallback.MiniGameCallbackRequest request = MiniGameCallback.MiniGameCallbackRequest.builder()
|
|
MiniGameCallback.MiniGameCallbackRequest request = MiniGameCallback.MiniGameCallbackRequest.builder()
|
|
.clue_token(userLog.getClueToken())
|
|
.clue_token(userLog.getClueToken())
|
|
.open_id(orderLog.getOpenId())
|
|
.open_id(orderLog.getOpenId())
|
|
.union_id(orderLog.getUnionId())
|
|
.union_id(orderLog.getUnionId())
|
|
.event_type(String.valueOf(eventType))
|
|
.event_type(String.valueOf(eventType))
|
|
.props(MiniGameCallback.MiniGameCallbackRequest.MiniGameCallbackRequestProps.builder()
|
|
.props(MiniGameCallback.MiniGameCallbackRequest.MiniGameCallbackRequestProps.builder()
|
|
- .pay_amount(orderLog.getBackMoney())
|
|
|
|
|
|
+ .pay_amount(backMoney)
|
|
.build())
|
|
.build())
|
|
.build();
|
|
.build();
|
|
BackStatusEnum backStatus = BackStatusEnum.SUCCESS;
|
|
BackStatusEnum backStatus = BackStatusEnum.SUCCESS;
|
|
@@ -237,7 +254,36 @@ public class GameOceanengineOrderLogServiceImpl extends ServiceImpl<GameOceaneng
|
|
.backStatus(backStatus.getBackStatus())
|
|
.backStatus(backStatus.getBackStatus())
|
|
.errMsg(errMsg)
|
|
.errMsg(errMsg)
|
|
.build());
|
|
.build());
|
|
- return backStatus;
|
|
|
|
|
|
+ return Tuple2.with(backStatus, errMsg);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<GameOceanengineOrderLogVO> toVOBatch(List<GameOceanengineOrderLog> logList) {
|
|
|
|
+ if (CollectionUtils.isEmpty(logList)) {
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
+ }
|
|
|
|
+ Set<String> agentKeys = logList.stream().map(GameOceanengineOrderLog::getAgentKey).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
|
|
|
|
+ Map<String, AgentRpcVO> agentMap = CollectionUtils.isEmpty(agentKeys) ? Collections.emptyMap() : agentRpc.getByAgentKeys(new ArrayList<>(agentKeys))
|
|
|
|
+ .getData().stream().collect(Collectors.toMap(AgentRpcVO::getAgentKey, Function.identity()));
|
|
|
|
+ return logList.stream().map(log -> {
|
|
|
|
+ GameOceanengineOrderLogVO vo = toVOSimple(log);
|
|
|
|
+ if (StringUtils.isNotBlank(log.getAgentKey())) {
|
|
|
|
+ AgentRpcVO agent = agentMap.get(log.getAgentKey());
|
|
|
|
+ if (agent != null) {
|
|
|
|
+ vo.setAgentName(agent.getAgentName());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return vo;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private GameOceanengineOrderLogVO toVOSimple(GameOceanengineOrderLog log) {
|
|
|
|
+ if (log == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ GameOceanengineOrderLogVO vo = BeanUtil.copy(log, GameOceanengineOrderLogVO.class);
|
|
|
|
+ vo.setRegPayIntervalTime(OrderUtil.regPayIntervalTime(log.getPayTime(), log.getRegTime()));
|
|
|
|
+ return vo;
|
|
}
|
|
}
|
|
|
|
|
|
private GameOceanengineUserLog userLog(GameOceanengineOrderLog orderLog) {
|
|
private GameOceanengineUserLog userLog(GameOceanengineOrderLog orderLog) {
|