|
@@ -1,11 +1,30 @@
|
|
|
package com.zanxiang.game.module.sdk.service.impl;
|
|
|
|
|
|
-import com.zanxiang.game.module.sdk.service.ICallBackService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IOrderService;
|
|
|
-import com.zanxiang.game.module.sdk.service.IUserService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.zanxiang.game.back.base.ServerInfo;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.pojo.dto.AccountReportRpcDTO;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.pojo.dto.OrderReportRpcDTO;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.pojo.dto.UserActiveReportRpcDTO;
|
|
|
+import com.zanxiang.game.back.base.oceanengine.rpc.IWechatMiniGameDataReportRpc;
|
|
|
+import com.zanxiang.game.back.base.tencent.pojo.dto.TencentOrderDTO;
|
|
|
+import com.zanxiang.game.back.base.tencent.pojo.dto.TencentUserDTO;
|
|
|
+import com.zanxiang.game.back.base.tencent.rpc.IGameBackTencentRpc;
|
|
|
+import com.zanxiang.game.module.base.pojo.enums.GameCategoryEnum;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.Agent;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.Game;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.GameApplet;
|
|
|
+import com.zanxiang.game.module.mybatis.entity.User;
|
|
|
+import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
|
|
|
+import com.zanxiang.game.module.sdk.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
|
* @author : lingfeng
|
|
@@ -16,93 +35,160 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class CallBackServiceImpl implements ICallBackService {
|
|
|
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private IGameBackTencentRpc gameBackTencentRpc;
|
|
|
+
|
|
|
+ @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
|
|
|
+ private IWechatMiniGameDataReportRpc wechatMiniGameDataReportRpc;
|
|
|
+
|
|
|
@Autowired
|
|
|
- private IUserService userService;
|
|
|
+ private IAgentService agentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGameService gameService;
|
|
|
|
|
|
@Autowired
|
|
|
- private IOrderService orderService;
|
|
|
+ private IGameAppletService gameAppletService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void userCallBack(User user, Tuple2<Long, Map<String, String>> tuple2) {
|
|
|
+ Long agentId = tuple2.getT1();
|
|
|
+ Map<String, String> urlParamMap = tuple2.getT2();
|
|
|
+
|
|
|
+ if (agentId == 0L || CollectionUtils.isEmpty(urlParamMap)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Agent agent = agentService.getById(user.getAgentId());
|
|
|
+ if (agent == null) {
|
|
|
+ log.error("用户回传不存在渠道信息, userId : {}", user.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
|
+ .eq(GameApplet::getGameId, user.getGameId()));
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_TENCENT)) {
|
|
|
+ TencentUserDTO tencentUserDTO = this.transform(user, agent, gameApplet);
|
|
|
+ gameBackTencentRpc.backUser(tencentUserDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(urlParamMap) && Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_BYTE)) {
|
|
|
+ Game game = gameService.getById(user.getGameId());
|
|
|
+
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getCategory())) {
|
|
|
+ UserActiveReportRpcDTO activeReportRpcDTO = this.transform(user, agent, gameApplet, urlParamMap);
|
|
|
+ wechatMiniGameDataReportRpc.userActiveReport(activeReportRpcDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("用户回传异常, userId : {}, e : {}", user.getId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void orderCallBack(PlatformOrderDTO platformOrderDTO) {
|
|
|
+
|
|
|
+ Agent agent = agentService.getById(platformOrderDTO.getAgentId());
|
|
|
+ if (agent == null) {
|
|
|
+ log.error("订单回传不存在渠道信息, orderId : {}", platformOrderDTO.getOrderId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ User user = userService.getById(platformOrderDTO.getUserId());
|
|
|
+
|
|
|
+ GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
|
+ .eq(GameApplet::getGameId, user.getGameId()));
|
|
|
+ try {
|
|
|
+
|
|
|
+ if (Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_TENCENT)) {
|
|
|
+ TencentOrderDTO tencentOrderDTO = this.transform(platformOrderDTO, user, agent, gameApplet);
|
|
|
+ gameBackTencentRpc.backOrder(tencentOrderDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.equals(agent.getAccountType(), Agent.ACCOUNT_TYPE_BYTE)) {
|
|
|
+
|
|
|
+ Game game = gameService.getById(platformOrderDTO.getGameId());
|
|
|
+ if (Objects.equals(game.getCategory(), GameCategoryEnum.CATEGORY_WX_APPLET.getCategory())) {
|
|
|
+ OrderReportRpcDTO orderReportRpcDTO = this.transform(platformOrderDTO, user.getOpenId(), agent, gameApplet);
|
|
|
+ wechatMiniGameDataReportRpc.orderReport(orderReportRpcDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("订单回传异常, orderId : {}, e : {}", platformOrderDTO.getOrderId(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private TencentUserDTO transform(User user, Agent agent, GameApplet gameApplet) {
|
|
|
+ return TencentUserDTO.builder()
|
|
|
+ .gameId(user.getGameId())
|
|
|
+ .adAccountId(agent.getAccountId())
|
|
|
+ .registerTime(user.getCreateTime())
|
|
|
+ .channel(agent.getAgentKey())
|
|
|
+ .wechatOpenid(user.getOpenId())
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
+ private UserActiveReportRpcDTO transform(User user, Agent agent, GameApplet gameApplet, Map<String, String> urlParamMap) {
|
|
|
+ AccountReportRpcDTO accountReportRpcDTO = AccountReportRpcDTO.builder()
|
|
|
+ .accountId(agent.getAccountId())
|
|
|
+ .reportToken(agent.getReportToken())
|
|
|
+ .reportUrl(agent.getReportUrl())
|
|
|
+ .build();
|
|
|
+ return UserActiveReportRpcDTO.builder()
|
|
|
+ .gameId(user.getGameId())
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .wechatOpenId(user.getOpenId())
|
|
|
+ .accountReport(accountReportRpcDTO)
|
|
|
+ .agentKey(agent.getAgentKey())
|
|
|
+ .activeTime(user.getCreateTime())
|
|
|
+ .clueToken(urlParamMap.get("clue_token"))
|
|
|
+ .projectId(urlParamMap.get("project_id") == null ? null : Long.valueOf(urlParamMap.get("project_id")))
|
|
|
+ .promotionId(urlParamMap.get("promotion_id") == null ? null : Long.valueOf(urlParamMap.get("promotion_id")))
|
|
|
+ .advertiserId(urlParamMap.get("advertiser_id") == null ? null : Long.valueOf(urlParamMap.get("advertiser_id")))
|
|
|
+ .reqId(urlParamMap.get("req_id"))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ private TencentOrderDTO transform(PlatformOrderDTO platformOrderDTO, User user, Agent agent, GameApplet gameApplet) {
|
|
|
+ return TencentOrderDTO.builder()
|
|
|
+ .backPolicyId(agent.getBackPolicyId())
|
|
|
+ .gameId(platformOrderDTO.getGameId())
|
|
|
+ .adAccountId(agent.getAccountId())
|
|
|
+ .registerTime(user.getCreateTime())
|
|
|
+ .rechargeMoney(platformOrderDTO.getAmount().longValue() * 100)
|
|
|
+ .rechargeTime(platformOrderDTO.getCreateTime())
|
|
|
+ .orderId(platformOrderDTO.getOrderId())
|
|
|
+ .channel(agent.getAgentKey())
|
|
|
+ .wechatOpenid(user.getOpenId())
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .orderStatus(platformOrderDTO.getStatus())
|
|
|
+ .payTime(platformOrderDTO.getPayTime())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
|
|
|
+ private OrderReportRpcDTO transform(PlatformOrderDTO platformOrderDTO, String openId, Agent agent, GameApplet gameApplet) {
|
|
|
+ AccountReportRpcDTO accountReportRpcDTO = AccountReportRpcDTO.builder()
|
|
|
+ .accountId(agent.getAccountId())
|
|
|
+ .reportToken(agent.getReportToken())
|
|
|
+ .reportUrl(agent.getReportUrl())
|
|
|
+ .build();
|
|
|
+ return OrderReportRpcDTO.builder()
|
|
|
+ .gameId(platformOrderDTO.getGameId())
|
|
|
+ .accountReport(accountReportRpcDTO)
|
|
|
+ .wechatAppId(gameApplet == null ? null : gameApplet.getAppId())
|
|
|
+ .wechatOpenId(openId)
|
|
|
+ .orderId(platformOrderDTO.getOrderId())
|
|
|
+ .agentKey(agent.getAgentKey())
|
|
|
+ .backPolicyId(agent.getBackPolicyId())
|
|
|
+ .rechargeMoney(platformOrderDTO.getAmount().longValue() * 100)
|
|
|
+ .orderStatus(platformOrderDTO.getStatus())
|
|
|
+ .createTime(platformOrderDTO.getCreateTime())
|
|
|
+ .payTime(platformOrderDTO.getPayTime())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
}
|