|  | @@ -1,5 +1,6 @@
 | 
	
		
			
				|  |  |  package com.zanxiang.game.module.sdk.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson2.JSONObject;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.github.sd4324530.jtuple.Tuple2;
 | 
	
	
		
			
				|  | @@ -7,7 +8,9 @@ import com.github.sd4324530.jtuple.Tuple3;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.base.ServerInfo;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.base.pojo.dto.TencentMiniGameOrderBackQueryRpcDTO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.base.pojo.dto.TtAppOrderBackQueryRpcDTO;
 | 
	
		
			
				|  |  | +import com.zanxiang.game.back.base.pojo.vo.GameBackPolicyRpcVO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.base.pojo.vo.OrderBackQueryRpcVO;
 | 
	
		
			
				|  |  | +import com.zanxiang.game.back.base.rpc.IGameBackPolicyRpc;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.base.rpc.ITencentMiniGameBackRpc;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.base.rpc.ITtAppBackRpc;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.base.pojo.enums.AccountTypeEnum;
 | 
	
	
		
			
				|  | @@ -48,6 +51,9 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |      @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
 | 
	
		
			
				|  |  |      private ITtAppBackRpc ttAppBackRpc;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
 | 
	
		
			
				|  |  | +    private IGameBackPolicyRpc gameBackPolicyRpc;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @DubboReference(providedBy = ServerInfo.SERVER_DUBBO_NAME)
 | 
	
		
			
				|  |  |      private ITencentMiniGameBackRpc tencentMiniGameBackRpc;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -63,6 +69,9 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IUserEventService userEventService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private IGameUserRoleService gameUserRoleService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IUserLoginLogService userLoginLogService;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -199,6 +208,8 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |          Long userId = user.getId();
 | 
	
		
			
				|  |  |          //游戏id
 | 
	
		
			
				|  |  |          Long gameId = agent.getGameId();
 | 
	
		
			
				|  |  | +        //角色id
 | 
	
		
			
				|  |  | +        String roleId = param.getRoleId();
 | 
	
		
			
				|  |  |          //回传类型
 | 
	
		
			
				|  |  |          CallBackTypeEnum callBackTypeEnum = param.getCallBackTypeEnum();
 | 
	
		
			
				|  |  |          //按不同类型判断
 | 
	
	
		
			
				|  | @@ -208,6 +219,10 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |              case CALL_BACK_REGISTER:
 | 
	
		
			
				|  |  |              case CALL_BACK_ACTIVATE:
 | 
	
		
			
				|  |  |              case CALL_BACK_CREATE_ROLE:
 | 
	
		
			
				|  |  | +                Tuple2<Boolean, String> distinctCheck = this.callBackDistinctCheck(callBackTypeEnum, gameId, userId, roleId);
 | 
	
		
			
				|  |  | +                resultMap.put("callBack", distinctCheck.first);
 | 
	
		
			
				|  |  | +                resultMap.put("backMsg", distinctCheck.second);
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  |              case CALL_BACK_UPDATE_LEVEL:
 | 
	
		
			
				|  |  |              case CALL_BACK_ADD_TO_WISHLIST:
 | 
	
		
			
				|  |  |              case CALL_BACK_ON_SHARE_TIME_LINE:
 | 
	
	
		
			
				|  | @@ -217,13 +232,13 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |                  resultMap.put("callBack", Boolean.TRUE);
 | 
	
		
			
				|  |  |                  break;
 | 
	
		
			
				|  |  |              case CALL_BACK_RE_ACTIVE:
 | 
	
		
			
				|  |  | -                Tuple3<Boolean, Long, String> tuple = this.callBackReActiveCheck(param.getRoleId(), userId, gameId);
 | 
	
		
			
				|  |  | +                Tuple3<Boolean, Long, String> tuple = this.callBackReActiveCheck(roleId, userId, gameId);
 | 
	
		
			
				|  |  |                  resultMap.put("callBack", tuple.first);
 | 
	
		
			
				|  |  |                  resultMap.put("backFlowDay", tuple.second);
 | 
	
		
			
				|  |  |                  resultMap.put("backMsg", tuple.third);
 | 
	
		
			
				|  |  |                  break;
 | 
	
		
			
				|  |  |              case CALL_BACK_TUTORIAL_FINISH:
 | 
	
		
			
				|  |  | -                Tuple2<Boolean, String> tuple2 = this.callBackTutorialFinishCheck(param.getRoleId(), userId, gameId);
 | 
	
		
			
				|  |  | +                Tuple2<Boolean, String> tuple2 = this.callBackTutorialFinishCheck(roleId, userId, gameId, agent);
 | 
	
		
			
				|  |  |                  resultMap.put("callBack", tuple2.first);
 | 
	
		
			
				|  |  |                  resultMap.put("backMsg", tuple2.second);
 | 
	
		
			
				|  |  |                  break;
 | 
	
	
		
			
				|  | @@ -238,6 +253,41 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private Tuple2<Boolean, String> callBackDistinctCheck(CallBackTypeEnum callBackTypeEnum, Long gameId, Long userId, String roleId) {
 | 
	
		
			
				|  |  | +        //注册回传去重判断
 | 
	
		
			
				|  |  | +        if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_REGISTER)
 | 
	
		
			
				|  |  | +                && super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
		
			
				|  |  | +                .eq(GameBackLogMediaSdk::getGameId, gameId)
 | 
	
		
			
				|  |  | +                .eq(GameBackLogMediaSdk::getUserId, userId)
 | 
	
		
			
				|  |  | +                .eq(GameBackLogMediaSdk::getCallBackParam, callBackTypeEnum.getValue())
 | 
	
		
			
				|  |  | +        ) > 0) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "当前用户注册已回传, 不重复执行");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //创角回传判断
 | 
	
		
			
				|  |  | +        if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_ACTIVATE)
 | 
	
		
			
				|  |  | +                || Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_CREATE_ROLE)) {
 | 
	
		
			
				|  |  | +            //创角是否已回传
 | 
	
		
			
				|  |  | +            if (super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getGameId, gameId)
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getUserId, userId)
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getRoleId, roleId)
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getCallBackParam, callBackTypeEnum.getValue())
 | 
	
		
			
				|  |  | +            ) > 0) {
 | 
	
		
			
				|  |  | +                return Tuple2.with(Boolean.FALSE, "当前角色创角已回传, 不重复执行");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //腾讯小游戏的创角回传, 可以判断前置注册回传时候已执行
 | 
	
		
			
				|  |  | +            if (Objects.equals(callBackTypeEnum, CallBackTypeEnum.CALL_BACK_CREATE_ROLE)
 | 
	
		
			
				|  |  | +                    && super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getGameId, gameId)
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getUserId, userId)
 | 
	
		
			
				|  |  | +                    .eq(GameBackLogMediaSdk::getCallBackParam, callBackTypeEnum.getValue())
 | 
	
		
			
				|  |  | +            ) <= 0) {
 | 
	
		
			
				|  |  | +                return Tuple2.with(Boolean.FALSE, "当前用户注册未回传, 无法执行创角回传");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return Tuple2.with(Boolean.TRUE, "执行回传");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private Tuple3<Boolean, Long, String> callBackReActiveCheck(String roleId, Long userId, Long gameId) {
 | 
	
		
			
				|  |  |          //判断玩家今日是否已经沉默唤起回传
 | 
	
		
			
				|  |  |          if (super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
	
		
			
				|  | @@ -265,14 +315,58 @@ public class GameBackLogMediaSdkServiceImpl extends ServiceImpl<GameBackLogMedia
 | 
	
		
			
				|  |  |          return Tuple3.with(betweenDay >= backFlowDay, backFlowDay, "沉默唤起判断依据登录日志id: " + userLoginLog.getId());
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private Tuple2<Boolean, String> callBackTutorialFinishCheck(String roleId, Long userId, Long gameId) {
 | 
	
		
			
				|  |  | -        long count = super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
		
			
				|  |  | +    private Tuple2<Boolean, String> callBackTutorialFinishCheck(String roleId, Long userId, Long gameId, Agent agent) {
 | 
	
		
			
				|  |  | +        //判断创角是否回传, 新手引导回传必须在创角回传之后执行
 | 
	
		
			
				|  |  | +        if (super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
		
			
				|  |  | +                .eq(GameBackLogMediaSdk::getGameId, gameId)
 | 
	
		
			
				|  |  | +                .eq(GameBackLogMediaSdk::getUserId, userId)
 | 
	
		
			
				|  |  | +                .eq(GameBackLogMediaSdk::getRoleId, roleId)
 | 
	
		
			
				|  |  | +                .and(qw -> qw.eq(GameBackLogMediaSdk::getCallBackParam, CallBackTypeEnum.CALL_BACK_CREATE_ROLE)
 | 
	
		
			
				|  |  | +                        .or().eq(GameBackLogMediaSdk::getCallBackParam, CallBackTypeEnum.CALL_BACK_ACTIVATE))
 | 
	
		
			
				|  |  | +        ) <= 0) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "创角回传未执行, 无法执行新手引导回传");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //判断角色是否已经执行过新手引导回传
 | 
	
		
			
				|  |  | +        if (super.count(new LambdaQueryWrapper<GameBackLogMediaSdk>()
 | 
	
		
			
				|  |  |                  .eq(GameBackLogMediaSdk::getGameId, gameId)
 | 
	
		
			
				|  |  |                  .eq(GameBackLogMediaSdk::getUserId, userId)
 | 
	
		
			
				|  |  |                  .eq(GameBackLogMediaSdk::getRoleId, roleId)
 | 
	
		
			
				|  |  |                  .eq(GameBackLogMediaSdk::getCallBackParam, CallBackTypeEnum.CALL_BACK_TUTORIAL_FINISH)
 | 
	
		
			
				|  |  | -        );
 | 
	
		
			
				|  |  | -        return Tuple2.with(count <= 0, count <= 0 ? "执行新手引导回传" : "角色已执行新手引导回传, 不重复执行, count : " + count);
 | 
	
		
			
				|  |  | +        ) > 0) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "角色已执行新手引导回传, 不重复执行");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //渠道关联的策略
 | 
	
		
			
				|  |  | +        Long backPolicyId = agent.getBackPolicyId();
 | 
	
		
			
				|  |  | +        //判断角色当前等级是否满足策略限制等级
 | 
	
		
			
				|  |  | +        if (backPolicyId == null) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "渠道未绑定策略, 无法执行新手引导回传, agentId : " + agent.getId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //查询策略信息
 | 
	
		
			
				|  |  | +        Map<Long, GameBackPolicyRpcVO> policyRpcVOMap = gameBackPolicyRpc.listByIds(
 | 
	
		
			
				|  |  | +                Collections.singletonList(backPolicyId)).getData();
 | 
	
		
			
				|  |  | +        GameBackPolicyRpcVO gameBackPolicyRpcVO = policyRpcVOMap.get(backPolicyId);
 | 
	
		
			
				|  |  | +        if (gameBackPolicyRpcVO == null || Strings.isBlank(gameBackPolicyRpcVO.getTutorialFinishJson())) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "渠道绑定的策略信息不存在, 或者未设置新手引导回传等级, 无法执行新手引导回传, agentId : " + agent.getId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        JSONObject tutorialFinish = JSONObject.parse(gameBackPolicyRpcVO.getTutorialFinishJson());
 | 
	
		
			
				|  |  | +        Long roleLevel = tutorialFinish.getLong("roleLevel");
 | 
	
		
			
				|  |  | +        if (roleLevel == null) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "新手引导回传等级roleLevel设置为空, 无法执行新手引导回传, agentId : " + agent.getId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //查询角色当前等级
 | 
	
		
			
				|  |  | +        GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
 | 
	
		
			
				|  |  | +                .eq(GameUserRole::getUserId, userId)
 | 
	
		
			
				|  |  | +                .eq(GameUserRole::getGameId, gameId)
 | 
	
		
			
				|  |  | +                .eq(GameUserRole::getRoleId, roleId));
 | 
	
		
			
				|  |  | +        if (gameUserRole == null || gameUserRole.getRoleLevel() == null) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "角色信息或者角色等级信息不存在, 无法执行新手引导回传, roleId : " + roleId);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //等级判断
 | 
	
		
			
				|  |  | +        if (gameUserRole.getRoleLevel() < roleLevel) {
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, "角色等级未达到策略等级限制要求, 不执行新手引导回传, agentId : " + agent.getId());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //返回执行新手引导回传
 | 
	
		
			
				|  |  | +        return Tuple2.with(Boolean.TRUE, "执行新手引导回传");
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private Tuple3<Boolean, List<Long>, String> callBackOrderCheck(String orderId, User user, Agent agent) {
 |