Kaynağa Gözat

Merge remote-tracking branch 'origin/package' into package

shishaosong 1 yıl önce
ebeveyn
işleme
c1a2f0d531

+ 44 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/pojo/enums/ShellControlEnum.java

@@ -0,0 +1,44 @@
+package com.zanxiang.game.module.base.pojo.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-06
+ * @description : 壳包控制类型枚举
+ */
+@Getter
+@AllArgsConstructor
+public enum ShellControlEnum {
+
+    /**
+     * 关闭
+     */
+    SHELL_CONTROL_CLOSE(0, "关闭"),
+
+    /**
+     * 开启
+     */
+    SHELL_CONTROL_OPEN(1, "开启"),
+
+    /**
+     * 新用户开启, 老用户关闭
+     */
+    SHELL_CONTROL_NEW_USER_OPEN(2, "新用户开启, 老用户关闭"),
+
+    /**
+     * 角色等级控制开启
+     */
+    SHELL_CONTROL_LOW_LEVEL_OPEN(3, "角色等级控制开启");
+
+    /**
+     * 壳包控制类型
+     */
+    private Integer shellControl;
+
+    /**
+     * 描述
+     */
+    private String name;
+}

+ 87 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameAppletShell.java

@@ -0,0 +1,87 @@
+package com.zanxiang.game.module.mybatis.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.*;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-06
+ * @description : 小游戏壳包控制
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@ToString
+@Builder
+@TableName("t_game_applet_shell")
+public class GameAppletShell implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 游戏id
+     */
+    private Long gameId;
+
+    /**
+     * 是否在申诉
+     */
+    private Boolean isAppeal;
+
+    /**
+     * 线上版本号
+     */
+    private String proVersion;
+
+    /**
+     * 提审版本号
+     */
+    @TableField(updateStrategy = FieldStrategy.IGNORED)
+    private String arraignVersion;
+
+    /**
+     * 壳包控制类型, 0:关闭, 1:开启, 2:新用户开启, 老用户关闭, 3:角色等级控制开启
+     */
+    private Integer proControlType;
+
+    /**
+     * 壳包控制等级, 类型为3时, 必填
+     */
+    @TableField(updateStrategy = FieldStrategy.IGNORED)
+    private Long proControlLevel;
+
+    /**
+     * 壳跳出按钮开关
+     */
+    private Boolean isSkipSwitch;
+
+    /**
+     * 状态 0正常 1 不可用
+     */
+    private Integer status;
+
+    /**
+     * 0正常,1 删除
+     */
+    private Integer isDelete;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 更新时间
+     */
+    private LocalDateTime updateTime;
+
+}

+ 0 - 5
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameExt.java

@@ -69,11 +69,6 @@ public class GameExt implements Serializable {
      */
      */
     private Boolean adCallBackSwitch;
     private Boolean adCallBackSwitch;
 
 
-    /**
-     * 小游戏壳包控制开关
-     */
-    private Boolean appletShellSwitch;
-
     /**
     /**
      * 客服手机
      * 客服手机
      */
      */

+ 12 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/mapper/GameAppletShellMapper.java

@@ -0,0 +1,12 @@
+package com.zanxiang.game.module.mybatis.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.zanxiang.game.module.mybatis.entity.GameAppletShell;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-06
+ * @description : 壳包控制
+ */
+public interface GameAppletShellMapper extends BaseMapper<GameAppletShell> {
+}

+ 8 - 7
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/InitController.java

@@ -4,16 +4,14 @@ import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.pojo.param.UserData;
 import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
 import com.zanxiang.game.module.sdk.pojo.vo.GameInitVO;
 import com.zanxiang.game.module.sdk.service.IGameAppletService;
 import com.zanxiang.game.module.sdk.service.IGameAppletService;
+import com.zanxiang.game.module.sdk.service.IGameAppletShellService;
 import com.zanxiang.module.util.pojo.ResultVO;
 import com.zanxiang.module.util.pojo.ResultVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
 import io.swagger.annotations.ApiResponses;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 
 /**
 /**
  * @author : lingfeng
  * @author : lingfeng
@@ -28,6 +26,9 @@ public class InitController {
     @Autowired
     @Autowired
     private IGameAppletService gameAppletService;
     private IGameAppletService gameAppletService;
 
 
+    @Autowired
+    private IGameAppletShellService gameAppletShellService;
+
     @UnSignCheck
     @UnSignCheck
     @ApiOperation(value = "(H5和微信小游戏)SDK参数初始化")
     @ApiOperation(value = "(H5和微信小游戏)SDK参数初始化")
     @PostMapping("/applet")
     @PostMapping("/applet")
@@ -38,9 +39,9 @@ public class InitController {
 
 
     @UnSignCheck
     @UnSignCheck
     @ApiOperation(value = "微信小游戏壳包控制开关")
     @ApiOperation(value = "微信小游戏壳包控制开关")
-    @PostMapping("/shell/switch")
+    @GetMapping("/shell/switch")
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
-    public ResultVO<Boolean> appletShellSwitch(@RequestParam String appId) {
-        return ResultVO.ok(gameAppletService.appletShellSwitch(appId));
+    public ResultVO<Integer> getShellSwitch(@RequestParam String appId, @RequestParam String version) {
+        return ResultVO.ok(gameAppletShellService.getShellSwitch(appId, version));
     }
     }
 }
 }

+ 40 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/enums/ShellSwitchEnum.java

@@ -0,0 +1,40 @@
+package com.zanxiang.game.module.sdk.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-06
+ * @description : 壳包控制枚举
+ */
+@Getter
+@AllArgsConstructor
+public enum ShellSwitchEnum {
+
+    /**
+     * 开启壳包
+     */
+    SHELL_SWITCH_OPEN(1, "开启壳包"),
+
+    /**
+     * 关闭壳包
+     */
+    SHELL_SWITCH_CLOSE(2, "关闭壳包"),
+
+    /**
+     * 申诉状态
+     */
+    SHELL_SWITCH_APPEAL(3, "申诉中");
+
+    /**
+     * 壳包控制
+     */
+    private Integer shellSwitch;
+
+    /**
+     * 描述
+     */
+    private String name;
+
+}

+ 6 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/vo/UserLoginVO.java

@@ -82,4 +82,10 @@ public class UserLoginVO {
      */
      */
     @ApiModelProperty(notes = "是否需要强制实名, true : 是, false : 否")
     @ApiModelProperty(notes = "是否需要强制实名, true : 是, false : 否")
     private Boolean checkSwitch;
     private Boolean checkSwitch;
+
+    /**
+     * 小游戏壳包控制开关
+     */
+    @ApiModelProperty(notes = "小游戏壳包控制开关")
+    private Integer appletShellSwitch;
 }
 }

+ 0 - 8
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletService.java

@@ -62,12 +62,4 @@ public interface IGameAppletService extends IService<GameApplet> {
      * @return {@link GameInitVO}
      * @return {@link GameInitVO}
      */
      */
     GameInitVO h5AndAppletInit(UserData userData);
     GameInitVO h5AndAppletInit(UserData userData);
-
-    /**
-     * 小游戏壳包控制开关
-     *
-     * @param appId 应用程序id
-     * @return boolean
-     */
-    boolean appletShellSwitch(String appId);
 }
 }

+ 31 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameAppletShellService.java

@@ -0,0 +1,31 @@
+package com.zanxiang.game.module.sdk.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.zanxiang.game.module.mybatis.entity.GameAppletShell;
+import com.zanxiang.game.module.mybatis.entity.User;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-06
+ * @description : 壳包控制
+ */
+public interface IGameAppletShellService extends IService<GameAppletShell> {
+
+    /**
+     * 获取壳开关
+     *
+     * @param appId   应用程序id
+     * @param version 版本
+     * @return {@link Integer}
+     */
+    Integer getShellSwitch(String appId, String version);
+
+    /**
+     * 获取用户壳开关
+     *
+     * @param user     用户
+     * @param register 注册
+     * @return {@link Integer}
+     */
+    Integer getUserShellSwitch(User user, boolean register);
+}

+ 0 - 9
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletServiceImpl.java

@@ -208,13 +208,4 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
                 .h5LoginLogo(game.getH5LoginLogo())
                 .h5LoginLogo(game.getH5LoginLogo())
                 .build();
                 .build();
     }
     }
-
-    @Override
-    public boolean appletShellSwitch(String appId) {
-        GameExt gameExt = gameExtService.getByGameAppId(appId);
-        if (gameExt == null || gameExt.getAppletShellSwitch() == null) {
-            return false;
-        }
-        return gameExt.getAppletShellSwitch();
-    }
 }
 }

+ 112 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameAppletShellServiceImpl.java

@@ -0,0 +1,112 @@
+package com.zanxiang.game.module.sdk.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zanxiang.game.module.base.pojo.enums.ShellControlEnum;
+import com.zanxiang.game.module.mybatis.entity.GameAppletShell;
+import com.zanxiang.game.module.mybatis.entity.GameExt;
+import com.zanxiang.game.module.mybatis.entity.GameUserRole;
+import com.zanxiang.game.module.mybatis.entity.User;
+import com.zanxiang.game.module.mybatis.mapper.GameAppletShellMapper;
+import com.zanxiang.game.module.sdk.enums.ShellSwitchEnum;
+import com.zanxiang.game.module.sdk.service.IGameAppletShellService;
+import com.zanxiang.game.module.sdk.service.IGameExtService;
+import com.zanxiang.game.module.sdk.service.IGameUserRoleService;
+import com.zanxiang.module.util.JsonUtil;
+import com.zanxiang.module.util.exception.BaseException;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author : lingfeng
+ * @time : 2023-07-06
+ * @description : 壳包控制
+ */
+@Slf4j
+@Service
+public class GameAppletShellServiceImpl extends ServiceImpl<GameAppletShellMapper, GameAppletShell> implements IGameAppletShellService {
+
+    @Autowired
+    private IGameExtService gameExtService;
+
+    @Autowired
+    private IGameUserRoleService gameUserRoleService;
+
+    @Override
+    public Integer getShellSwitch(String appId, String version) {
+        GameExt gameExt = gameExtService.getByGameAppId(appId);
+        if (gameExt == null) {
+            throw new BaseException("参数错误, 游戏信息不存在");
+        }
+        GameAppletShell gameAppletShell = super.getOne(new LambdaQueryWrapper<GameAppletShell>()
+                .eq(GameAppletShell::getGameId, gameExt.getGameId()));
+        if (gameAppletShell == null) {
+            throw new BaseException("参数错误, 游戏设置信息不存在");
+        }
+        //版本为提审版本
+        if (Objects.equals(gameAppletShell.getArraignVersion(), version)) {
+            return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+        }
+        //线上版本
+        if (Objects.equals(gameAppletShell.getProVersion(), version)) {
+            //申诉中, 返回申诉状态
+            if (Objects.equals(gameAppletShell.getIsAppeal(), Boolean.TRUE)) {
+                return ShellSwitchEnum.SHELL_SWITCH_APPEAL.getShellSwitch();
+            }
+            //返回关闭
+            return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+        }
+        log.error("版本信息不存在, appId : {}, version : {}", appId, version);
+        throw new BaseException("参数错误, 版本信息不存在");
+    }
+
+    @Override
+    public Integer getUserShellSwitch(User user, boolean register) {
+        GameAppletShell gameAppletShell = super.getOne(new LambdaQueryWrapper<GameAppletShell>()
+                .eq(GameAppletShell::getGameId, user.getGameId()));
+        //未设置, 统一返回关闭
+        if (gameAppletShell == null) {
+            return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+        }
+        //控制类型
+        Integer proControlType = gameAppletShell.getProControlType();
+        //关闭
+        if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_CLOSE.getShellControl())) {
+            return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+        }
+        //开启
+        if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_OPEN.getShellControl())) {
+            return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+        }
+        //新用户开启
+        if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_NEW_USER_OPEN.getShellControl())) {
+            return register ? ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch() : ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+        }
+        //等级控制开启
+        if (Objects.equals(proControlType, ShellControlEnum.SHELL_CONTROL_LOW_LEVEL_OPEN.getShellControl())) {
+            //查询用户角色等级
+            List<GameUserRole> gameUserRoleList = gameUserRoleService.list(new LambdaQueryWrapper<GameUserRole>()
+                    .eq(GameUserRole::getUserId, user.getId())
+                    .eq(GameUserRole::getGameId, user.getGameId()));
+            //不存在角色的新用户, 开启
+            if (CollectionUtils.isEmpty(gameUserRoleList)) {
+                return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+            }
+            //获取用户等级最好的角色
+            GameUserRole gameUserRole = gameUserRoleList.stream().max(Comparator.comparing(GameUserRole::getRoleLevel)).orElse(null);
+            //角色不存在, 或者等级小于等于控制等级
+            if (gameUserRole == null || gameUserRole.getRoleLevel() <= gameAppletShell.getProControlLevel()) {
+                return ShellSwitchEnum.SHELL_SWITCH_OPEN.getShellSwitch();
+            }
+            return ShellSwitchEnum.SHELL_SWITCH_CLOSE.getShellSwitch();
+        }
+        log.error("版本信息不存在, userId : {}, gameAppletShell : {}", user.getId(), JsonUtil.toString(gameAppletShell));
+        throw new BaseException("参数错误, 游戏参数设置错误");
+    }
+}

+ 9 - 2
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java

@@ -84,6 +84,9 @@ public class LoginServiceImpl implements IRegisterLoginService {
     @Autowired
     @Autowired
     private IAgentService agentService;
     private IAgentService agentService;
 
 
+    @Autowired
+    private IGameAppletShellService gameAppletShellService;
+
     @Override
     @Override
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
     public ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData) {
     public ResultVO<UserLoginVO> loginWxCode(LoginVxCodeParam param, UserData userData) {
@@ -119,12 +122,16 @@ public class LoginServiceImpl implements IRegisterLoginService {
             //渠道更新和回传判断
             //渠道更新和回传判断
             agentService.userAgentUpdate(user, userData.getChannel());
             agentService.userAgentUpdate(user, userData.getChannel());
             //返回登录信息
             //返回登录信息
-            return ResultVO.ok(this.createUserLoginVO(user, userData));
+            UserLoginVO userLoginVO = this.createUserLoginVO(user, userData);
+            userLoginVO.setAppletShellSwitch(gameAppletShellService.getUserShellSwitch(user, Boolean.FALSE));
+            return ResultVO.ok(userLoginVO);
         }
         }
         //用户注册
         //用户注册
         user = userCreateSave(userData, openId, null, null, openId, sessionKey, param.getShareUserId());
         user = userCreateSave(userData, openId, null, null, openId, sessionKey, param.getShareUserId());
         //返回登录信息
         //返回登录信息
-        return ResultVO.ok(this.createUserLoginVO(user, userData));
+        UserLoginVO userLoginVO = this.createUserLoginVO(user, userData);
+        userLoginVO.setAppletShellSwitch(gameAppletShellService.getUserShellSwitch(user, Boolean.TRUE));
+        return ResultVO.ok(userLoginVO);
     }
     }
 
 
     @Override
     @Override