瀏覽代碼

fix : 小游戏玩家导量到H5游戏

bilingfeng 1 年之前
父節點
當前提交
a2aa691652

+ 8 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/controller/UserController.java

@@ -136,4 +136,12 @@ public class UserController {
     public ResultVO<UserWeChatVO> getUserWeChat(@RequestParam Long userId) {
         return ResultVO.ok(userService.getUserWeChat(userId));
     }
+
+    @ApiOperation(value = "小游戏玩家导量到H5游戏")
+    @GetMapping(value = "/applet/to/h5")
+    @PreAuthorize(permissionKey = "manage:user:appletToH5")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
+    public ResultVO<Boolean> appletToH5(@RequestParam Long userId, @RequestParam String mobile) {
+        return ResultVO.ok(userService.appletToH5(userId, mobile));
+    }
 }

+ 5 - 10
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/GameDTO.java

@@ -32,16 +32,6 @@ public class GameDTO {
      */
     private Long category;
 
-    /**
-     * H5游戏跳转地址
-     */
-    private String h5GameUrl;
-
-    /**
-     * H5游戏登录logo图片
-     */
-    private String h5LoginLogo;
-
     /**
      * 游戏是否投放
      */
@@ -72,6 +62,11 @@ public class GameDTO {
      */
     private Long h5GameId;
 
+    /**
+     * H5游戏相关配置
+     */
+    private String h5GameConfig;
+
     /**
      * 导量游戏id
      */

+ 24 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/vo/UserListVO.java

@@ -194,4 +194,28 @@ public class UserListVO {
     @ApiModelProperty(notes = "注册充值时间差")
     private Long regPayTimeDiff;
 
+    /**
+     * 关联游戏id
+     */
+    @ApiModelProperty(notes = "关联游戏id")
+    private Long relationGameId;
+
+    /**
+     * 关联游戏名称
+     */
+    @ApiModelProperty(notes = "关联游戏名称")
+    private String relationGameName;
+
+    /**
+     * 关联用户id
+     */
+    @ApiModelProperty(notes = "关联用户id")
+    private Long relationUserId;
+
+    /**
+     * 关联建立时间
+     */
+    @ApiModelProperty(notes = "关联建立时间")
+    private LocalDateTime relationCreateTime;
+
 }

+ 2 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameUserRoleService.java

@@ -1,6 +1,7 @@
 package com.zanxiang.game.module.manage.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.module.manage.pojo.dto.GameUserRoleDTO;
 import com.zanxiang.game.module.manage.pojo.params.GameUserRoleListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameUserRoleListVO;
@@ -14,7 +15,7 @@ import java.util.List;
  * @time : 2022-07-01
  * @description : 玩家角色
  */
-public interface IGameUserRoleService {
+public interface IGameUserRoleService extends IService<GameUserRole> {
 
     /**
      * 获取用户最近的游戏角色

+ 3 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameUserService.java

@@ -1,16 +1,18 @@
 package com.zanxiang.game.module.manage.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.zanxiang.game.module.manage.pojo.params.GameUserListParam;
 import com.zanxiang.game.module.manage.pojo.vo.GameUserListVO;
 import com.zanxiang.game.module.manage.pojo.vo.GameUserVO;
+import com.zanxiang.game.module.mybatis.entity.GameUser;
 
 /**
  * @author : lingfeng
  * @time : 2022-07-04
  * @description : 玩家游戏
  */
-public interface IGameUserService {
+public interface IGameUserService extends IService<GameUser> {
 
     /**
      * 查询玩家游戏列表

+ 9 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IUserService.java

@@ -21,6 +21,15 @@ import java.util.Map;
  */
 public interface IUserService extends IService<User> {
 
+    /**
+     * 小游戏导量到H5
+     *
+     * @param userId 用户id
+     * @param mobile 移动
+     * @return {@link Boolean}
+     */
+    Boolean appletToH5(Long userId, String mobile);
+
     /**
      * 获取用户微信
      *

+ 74 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/UserServiceImpl.java

@@ -24,6 +24,7 @@ import com.zanxiang.game.module.manage.pojo.vo.UserVO;
 import com.zanxiang.game.module.manage.pojo.vo.UserWeChatVO;
 import com.zanxiang.game.module.manage.service.*;
 import com.zanxiang.game.module.mybatis.entity.Agent;
+import com.zanxiang.game.module.mybatis.entity.GameUser;
 import com.zanxiang.game.module.mybatis.entity.GameUserRole;
 import com.zanxiang.game.module.mybatis.entity.User;
 import com.zanxiang.game.module.mybatis.mapper.UserMapper;
@@ -75,6 +76,79 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
     @DubboReference(providedBy = CorpServer.SERVER_DUBBO_NAME)
     private ICorpExternalUserServiceRpc corpExternalUserServiceRpc;
 
+    @Autowired
+    private IGameUserService gameUserService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean appletToH5(Long userId, String mobile) {
+        //用户信息
+        User user = super.getById(userId);
+        if (user == null) {
+            throw new BaseException("参数错误, 用户信息不存在");
+        }
+        //查询H5游戏
+        GameDTO h5GameDTO = gameService.getById(gameService.getById(user.getGameId()).getH5GameId());
+        if (h5GameDTO == null) {
+            throw new BaseException("参数错误, 关联H5游戏信息不存在");
+        }
+        //复制用户信息
+        User h5User = BeanUtil.copy(user, User.class);
+        h5User.setId(null);
+        h5User.setGameId(h5GameDTO.getId());
+        h5User.setMobile(mobile);
+        h5User.setRelationUserId(user.getId());
+        h5User.setRelationCreateTime(LocalDateTime.now());
+        super.save(h5User);
+        //复制玩家信息
+        GameUser gameUser = gameUserService.getOne(new LambdaQueryWrapper<GameUser>()
+                .eq(GameUser::getUserId, user.getId())
+                .eq(GameUser::getGameId, user.getGameId()));
+        if (gameUser == null) {
+            throw new BaseException("参数错误, 玩家游戏信息不存在");
+        }
+        GameUser h5GameUser = GameUser.builder()
+                .userId(h5User.getId())
+                .gameId(h5User.getGameId())
+                .nickname(gameUser.getNickname())
+                .regTime(gameUser.getRegTime())
+                .createTime(gameUser.getCreateTime())
+                .updateTime(gameUser.getUpdateTime())
+                .build();
+        gameUserService.save(h5GameUser);
+        //复制角色
+        List<GameUserRole> gameUserRoleList = gameUserRoleService.list(new LambdaQueryWrapper<GameUserRole>()
+                .eq(GameUserRole::getUserId, user.getId())
+                .eq(GameUserRole::getGameId, user.getGameId()));
+        if (CollectionUtils.isNotEmpty(gameUserRoleList)) {
+            throw new BaseException("参数错误, 用户不存在角色信息");
+        }
+        List<GameUserRole> h5GameUserRoleList = gameUserRoleList.stream().map(gameUserRole -> GameUserRole.builder()
+                .userId(h5User.getId())
+                .gameUserId(h5GameUser.getId())
+                .gameId(h5User.getGameId())
+                .serverId(gameUserRole.getServerId())
+                .serverName(gameUserRole.getServerName())
+                .roleId(gameUserRole.getRoleId())
+                .roleName(gameUserRole.getRoleName())
+                .roleLevel(gameUserRole.getRoleLevel())
+                .roleVipLevel(gameUserRole.getRoleVipLevel())
+                .rolePower(gameUserRole.getRolePower())
+                .os(gameUserRole.getOs())
+                .regTime(gameUserRole.getCreateTime())
+                .createTime(gameUserRole.getCreateTime())
+                .updateTime(gameUserRole.getUpdateTime())
+                .lastLoginTime(gameUserRole.getLastLoginTime())
+                .build()
+        ).collect(Collectors.toList());
+        gameUserRoleService.saveBatch(h5GameUserRoleList);
+        //用户更新
+        return super.update(new LambdaUpdateWrapper<User>()
+                .set(User::getRelationUserId, h5User)
+                .set(User::getRelationCreateTime, LocalDateTime.now())
+                .eq(User::getId, userId));
+    }
+
     @Override
     public UserWeChatVO getUserWeChat(Long userId) {
         User user = super.getById(userId);

+ 10 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/User.java

@@ -171,6 +171,16 @@ public class User implements Serializable {
      */
     private Long shareUserId;
 
+    /**
+     * 关联用户id
+     */
+    private Long relationUserId;
+
+    /**
+     * 关联建立时间
+     */
+    private LocalDateTime relationCreateTime;
+
     /**
      * 获取用户显示手机号
      *