Quellcode durchsuchen

中台bug修复 返回值类型更新 分页查询 根据主账号id去找子账号id 主账号id和子账号id相同

wuchen vor 2 Monaten
Ursprung
Commit
16132587e7

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreUserVo.java

@@ -38,6 +38,9 @@ public class StoreUserVo extends StoreUser {
     @ApiModelProperty(value = "账号是否启用")
     private boolean switchStatus;
 
+    @ApiModelProperty(value = "状态展示文案:启用/禁用,供前端直接展示")
+    private String statusName;
+
     @ApiModelProperty(value = "验证码")
     private String verificationCode;
 

+ 1 - 0
alien-entity/src/main/java/shop/alien/mapper/StoreUserMapper.java

@@ -45,4 +45,5 @@ public interface StoreUserMapper extends BaseMapper<StoreUser> {
      * @return 子账号的 store_user.id 列表
      */
     List<Integer> selectSubAccountUserIdsByMainAccountIdWithRole(@Param("mainAccountId") Integer mainAccountId);
+
 }

+ 1 - 0
alien-entity/src/main/resources/mapper/StoreUserMapper.xml

@@ -26,4 +26,5 @@
           AND u.account_type = 2
           AND u.delete_flag = 0
     </select>
+
 </mapper>

+ 2 - 9
alien-store/src/main/java/shop/alien/store/controller/StoreUserController.java

@@ -288,15 +288,8 @@ public class StoreUserController {
      */
     @ApiOperation("web端切换商家端用户状态(主账号有子账号时禁止禁用;返回更新后状态供前端及时展示)")
     @ApiOperationSupport(order = 7)
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "subAccountId", value = "子账号用户ID(store_user.id),子账号启用/禁用时必传", dataType = "int", paramType = "body"),
-            @ApiImplicitParam(name = "id", value = "主账号时为主账号ID;子账号时可传主账号id(与 parentAccountId 一致)", dataType = "int", paramType = "body"),
-            @ApiImplicitParam(name = "parentAccountId", value = "主账号ID(子账号启用/禁用时必传,与分页列表一致)", dataType = "int", paramType = "body"),
-            @ApiImplicitParam(name = "accountType", value = "账号类型:1-主账号,2-子账号", dataType = "int", paramType = "body"),
-            @ApiImplicitParam(name = "status", value = "当前状态:0-启用,1-禁用(用于切换,点击禁用传0,点击启用传1)", dataType = "int", paramType = "body")
-    })
-    @PutMapping("/switchingStates")
-    public R<StoreUserVo> switchingStates(@RequestBody StoreUserVo storeUser) {
+    @PostMapping("/switchingStates")
+    public R<StoreUserVo> switchingStates(@RequestBody StoreUser storeUser) {
         log.info("StoreUserController.switchingStates?storeUser={}", storeUser);
         try {
             return storeUserService.switchingStates(storeUser);

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/StoreUserService.java

@@ -124,7 +124,7 @@ public interface StoreUserService extends IService<StoreUser> {
      *
      * @return boolean
      */
-    R<StoreUserVo> switchingStates(StoreUserVo storeUser);
+    R<StoreUserVo> switchingStates(StoreUser storeUser);
 
 
     /**

+ 117 - 182
alien-store/src/main/java/shop/alien/store/service/impl/StoreUserServiceImpl.java

@@ -545,6 +545,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
                 int rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
                 storeUserVo.setStatus(rowStatus);
                 storeUserVo.setSwitchStatus(rowStatus == 0);
+                storeUserVo.setStatusName(rowStatus == -1 ? "注销中" : rowStatus == 2 ? "已注销" : (rowStatus == 1 ? "禁用" : "启用"));
                 storeUserVo.setPhone(subAccount.getPhone());
                 if (mainAccount != null) {
                     storeUserVo.setParentAccountPhone(mainAccount.getPhone());
@@ -565,8 +566,6 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
                 .like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
                 .eq(status != null, StoreUser::getStatus, status)
                 .eq(StoreUser::getAccountType, 1)
-                .and(w -> w.isNull(StoreUser::getLogoutFlag).or().eq(StoreUser::getLogoutFlag, 0))
-                .and(w -> w.isNull(StoreUser::getStatus).or().in(StoreUser::getStatus, 0, 1))
                 .orderByDesc(StoreUser::getCreatedTime);
 
         IPage<StoreUser> storeUsers = storeUserMapper.selectPage(page, storeUserLambdaQueryWrapper);
@@ -578,7 +577,11 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
             BeanUtils.copyProperties(storeUser, vo);
             vo.setPassword(null);
             vo.setPayPassword(null);
-            vo.setSwitchStatus(storeUser.getStatus() != null && storeUser.getStatus() == 0);
+            // 主账号分页:返回最新 status(0 启用 / 1 禁用),前端展示启用/禁用
+            Integer latestStatus = storeUser.getStatus() != null ? storeUser.getStatus() : 0;
+            vo.setStatus(latestStatus);
+            vo.setSwitchStatus(latestStatus == 0);
+            vo.setStatusName(latestStatus == 1 ? "禁用" : "启用");
             int childCount = countSubAccountUserIdsByStoreId(storeUser.getStoreId(), storeUser.getId());
             vo.setChildAccountCount(childCount);
             List<Integer> childUserIds = getSubAccountUserIdsByStoreId(storeUser.getStoreId(), storeUser.getId());
@@ -593,6 +596,25 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
     }
 
     /**
+     * 通过主账号 id 用 MyBatis-Plus selectCount 查子账号数量(中间表 store_platform_user_role + store_user)。
+     * 能查出数量大于 0 则代表有子账号,禁止删除或禁用主账号。
+     *
+     * @param mainAccountId 主账号 id(store_user.id)
+     * @return true 表示有子账号,禁止删除/禁用;false 表示无子账号,可操作
+     */
+    private boolean hasSubAccountsByMainAccountId(Integer mainAccountId) {
+        if (mainAccountId == null) {
+            return false;
+        }
+        // 2. 在中间表 store_platform_user_role 中 selectCount:user_id in 子账号id 且 delete_flag=0
+        LambdaQueryWrapper<StorePlatformUserRole> roleWrapper = new LambdaQueryWrapper<>();
+        roleWrapper.eq(StorePlatformUserRole::getUserId,mainAccountId)
+                .eq(StorePlatformUserRole::getDeleteFlag, 0);
+        Long count = Long.valueOf(storePlatformUserRoleMapper.selectCount(roleWrapper));
+        return count != null && count > 0;
+    }
+
+    /**
      * 按 store_platform_user_role 统计该店铺下子账号数量(排除主账号自身,按 distinct user_id 计)
      */
     private int countSubAccountUserIdsByStoreId(Integer storeId, Integer excludeUserId) {
@@ -601,6 +623,20 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
     }
 
     /**
+     * 统计某个子账号用户在中间表中的有效关联数量(跨店铺、未删除)。
+     * 用于删除 / 启用禁用员工账号时判断:若同一 userId 关联多个店铺,则禁止直接删除 / 禁用全局账号。
+     */
+    private long countActiveSubAccountRelations(Integer userId) {
+        if (userId == null) {
+            return 0L;
+        }
+        LambdaQueryWrapper<StorePlatformUserRole> countWrapper = new LambdaQueryWrapper<>();
+        countWrapper.eq(StorePlatformUserRole::getUserId, userId)
+                .eq(StorePlatformUserRole::getDeleteFlag, 0);
+        return storePlatformUserRoleMapper.selectCount(countWrapper);
+    }
+
+    /**
      * 按 store_platform_user_role 查询该店铺下子账号 userId 列表(排除主账号自身)
      */
     private List<Integer> getSubAccountUserIdsByStoreId(Integer storeId, Integer excludeUserId) {
@@ -612,6 +648,15 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
         return list == null ? Collections.emptyList() : list.stream().map(StorePlatformUserRole::getUserId).distinct().collect(Collectors.toList());
     }
 
+    private List<Integer> getSubAccountUserIds(Integer excludeUserId) {
+        if (excludeUserId == null) return Collections.emptyList();
+        LambdaQueryWrapper<StorePlatformUserRole> w = new LambdaQueryWrapper<>();
+        w.eq(StorePlatformUserRole::getDeleteFlag, 0);
+        if (excludeUserId != null) w.ne(StorePlatformUserRole::getUserId, excludeUserId);
+        List<StorePlatformUserRole> list = storePlatformUserRoleMapper.selectList(w);
+        return list == null ? Collections.emptyList() : list.stream().map(StorePlatformUserRole::getUserId).distinct().collect(Collectors.toList());
+    }
+
     @Override
     public R<StoreUserVo> editStoreUser(StoreUser storeUser) {
         storeUserMapper.updateById(storeUser);
@@ -631,111 +676,74 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
 
 
     /**
-     * 启用/禁用(参考 deleteStoreAccountInfo 数据格式)。
-     * 要求1:子账号禁用时,若该账号既是主账号也是子账号,只禁用子账号角色,不禁用主账号;分页查询时页面展示最新状态(以 store_platform_user_role.status 为准)。
-     * 要求2:子账号可以禁用。
-     * 要求3:主账号底下有关联子账号时不能禁用。
-     * 状态:0 启用/正常,1 禁用;接口返回 newStatus 便于前端及分页展示最新状态。
+     * 启用/禁用(入参必传 id)。默认状态 0=启用,1=禁用。
+     * 禁用:主账号底下有关联子账号时需先删除子账号后才能禁用,否则用 UPDATE 把 status 从 0 改为 1,并删 token。
+     * 启用:用 UPDATE 把 status 从 1 改为 0。
+     * 若入参未传 status/accountType,则按 id 查库补全。
      */
     @Override
-    public R<StoreUserVo> switchingStates(StoreUserVo storeUserParam) {
+    public R<StoreUserVo> switchingStates(StoreUser storeUserParam) {
         if (storeUserParam == null) {
             throw new RuntimeException("参数不能为空");
         }
-        // 当前状态 0=启用 1=禁用;点击禁用则 newStatus=1,点击启用则 newStatus=0
-        int currentStatus = storeUserParam.getStatus() != null ? storeUserParam.getStatus() : 0;
-        int newStatus = (currentStatus == 0) ? 1 : 0;
-        boolean isMainAccount = storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 1;
-
-        // ---------- 子账号:要求2 子账号可以禁用 ----------
-        if (storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 2) {
-            Integer subAccountId = storeUserParam.getSubAccountId();
-            if (subAccountId == null) {
-                throw new RuntimeException("子账号 id 不能为空");
-            }
-            StoreUser storeUser = storeUserMapper.selectById(subAccountId);
-            if (storeUser == null) {
+        if (storeUserParam.getId() == null) {
+            throw new RuntimeException("请传入用户id");
+        }
+        // 入参未传 status / accountType / storeId 时,按 id 查库补全,避免缺字段导致子账号数量判断不准确
+        if (storeUserParam.getStatus() == null
+                || storeUserParam.getAccountType() == null
+                || storeUserParam.getStoreId() == null) {
+            StoreUser dbUser = storeUserMapper.selectById(storeUserParam.getId());
+            if (dbUser == null) {
                 throw new RuntimeException("用户不存在");
             }
-            Integer mainAccountId = storeUserParam.getParentAccountId() != null ? storeUserParam.getParentAccountId() : storeUser.getSubAccountId();
-            Integer storeId = null;
-            if (mainAccountId != null) {
-                StoreUser mainAccount = storeUserMapper.selectById(mainAccountId);
-                if (mainAccount != null) storeId = mainAccount.getStoreId();
+            if (storeUserParam.getStatus() == null) {
+                storeUserParam.setStatus(dbUser.getStatus());
             }
-
-            // 要求1:若该账号既是主账号也是子账号,只禁用子账号角色,不禁用主账号(同一手机号存在主账号则只更新 role)
-            boolean isBothMainAndSub = false;
-            if (storeUser.getPhone() != null && !storeUser.getPhone().isEmpty()) {
-                long mainSamePhone = storeUserMapper.selectCount(
-                        new LambdaQueryWrapper<StoreUser>()
-                                .eq(StoreUser::getPhone, storeUser.getPhone())
-                                .eq(StoreUser::getAccountType, 1)
-                                .eq(StoreUser::getDeleteFlag, 0));
-                isBothMainAndSub = mainSamePhone > 0;
-            }
-
-            LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
-            if (storeId != null) {
-                roleUpdateWrapper.eq(StorePlatformUserRole::getStoreId, storeId);
+            if (storeUserParam.getAccountType() == null) {
+                storeUserParam.setAccountType(dbUser.getAccountType());
             }
-            roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
-                    .eq(StorePlatformUserRole::getDeleteFlag, 0)
-                    .set(StorePlatformUserRole::getStatus, newStatus);
-            storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
-
-            if (isBothMainAndSub) {
-                // 既是主账号也是子账号:只改了 role,不更新 store_user,主账号保持启用;分页列表以 role.status 展示为最新状态
-                StoreUserVo vo = new StoreUserVo();
-                vo.setId(mainAccountId != null ? mainAccountId : storeUser.getId());
-                vo.setSubAccountId(storeUser.getId());
-                vo.setParentAccountId(mainAccountId);
-                vo.setStatus(newStatus);
-                vo.setSwitchStatus(newStatus == 0);
-                return R.data(vo);
-            }
-
-            baseRedisService.delete("store_" + storeUser.getPhone());
-            LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
-            userUpdateWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, newStatus);
-            storeUserMapper.update(null, userUpdateWrapper);
-            long enabledRoleCount = storePlatformUserRoleMapper.selectCount(
-                    new LambdaQueryWrapper<StorePlatformUserRole>()
-                            .eq(StorePlatformUserRole::getUserId, storeUser.getId())
-                            .eq(StorePlatformUserRole::getDeleteFlag, 0)
-                            .eq(StorePlatformUserRole::getStatus, 0));
-            if (enabledRoleCount == 0) {
-                baseRedisService.delete("store_" + storeUser.getPhone());
-                userUpdateWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, newStatus);
-                storeUserMapper.update(null, userUpdateWrapper);
+            if (storeUserParam.getStoreId() == null) {
+                storeUserParam.setStoreId(dbUser.getStoreId());
             }
-            StoreUserVo vo = new StoreUserVo();
-            vo.setId(mainAccountId != null ? mainAccountId : storeUser.getId());
-            vo.setSubAccountId(storeUser.getId());
-            vo.setParentAccountId(mainAccountId);
-            vo.setStatus(newStatus);
-            vo.setSwitchStatus(newStatus == 0);
-            return R.data(vo);
         }
+        // 当前状态默认 0(启用);点击禁用则 0->1,点击启用则 1->0
+        int currentStatus = storeUserParam.getStatus() != null ? storeUserParam.getStatus() : 0;
+        int newStatus = (currentStatus == 0) ? 1 : 0;
+        boolean isMainAccount = storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 1;
 
-        // ---------- 主账号:要求3 底下有关联子账号不能禁用 ----------
-        if (newStatus == 1 && isMainAccount) {
-            List<Integer> subAccountIds = storeUserMapper.selectSubAccountUserIdsByMainAccountIdWithRole(storeUserParam.getId());
-            if (subAccountIds != null && !subAccountIds.isEmpty()) {
-                throw new RuntimeException("请先删除主账号下的子账号后再禁用");
-            }
-        }
 
-        // 主账号启用/禁用:更新 store_user.status,禁用时删 token;返回 newStatus 便于分页展示最新状态
-        LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
-        userUpdateWrapper.eq(StoreUser::getId, storeUserParam.getId()).set(StoreUser::getStatus, newStatus);
-        storeUserMapper.update(null, userUpdateWrapper);
         if (newStatus == 1) {
+            StoreUser storeUser = storeUserMapper.selectById(storeUserParam.getId());
+
+            // 2)子账号:只要在中间表存在关联记录(userId 对得上),就禁止禁用,需先在子账号管理中解除
+            if (isMainAccount) {
+                long relationCount = countActiveSubAccountRelations(storeUserParam.getId());
+                if (relationCount > 0||storeUser.getStoreId()!=null) {
+                    log.error("该子账号在子账号列表中仍有关联记录,禁止直接禁用全局账号 userId={}", storeUserParam.getId());
+                    return R.fail("当前子账号在子账号管理中仍有关联记录,请先解除子账号后再禁用");
+                }
+            }
+            // UPDATE store_user SET status = 1 WHERE id = ?
+            LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
+            userUpdateWrapper.eq(StoreUser::getId, storeUserParam.getId()).set(StoreUser::getStatus, 1);
+            storeUserMapper.update(null, userUpdateWrapper);
+            // 禁用时删除 token
             StoreUser u = storeUserMapper.selectById(storeUserParam.getId());
             if (u != null && u.getPhone() != null) {
-                baseRedisService.delete("store_" + u.getPhone());
+                try {
+                    baseRedisService.delete("store_" + u.getPhone());
+                } catch (Exception e) {
+                    log.warn("switchingStates 删除 token 异常: {}", e.getMessage());
+                }
             }
+        } else {
+            // 启用:UPDATE store_user SET status = 0 WHERE id = ?
+            LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
+            userUpdateWrapper.eq(StoreUser::getId, storeUserParam.getId()).set(StoreUser::getStatus, 0);
+            storeUserMapper.update(null, userUpdateWrapper);
         }
+
         StoreUserVo vo = new StoreUserVo();
         vo.setId(storeUserParam.getId());
         vo.setStatus(newStatus);
@@ -1123,28 +1131,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
             log.warn("deleteStoreAccountInfo 参数不能为空");
             return "删除失败";
         }
-        // 1. 解析用户:子账号 id(userId) 优先用 subAccountId,其次 id;或通过 phone 查
-        Integer userId = null;
-        StoreUser storeUser = null;
-        if (storeUserVo.getSubAccountId() != null || storeUserVo.getId() != null) {
-            Integer idParam = storeUserVo.getSubAccountId() != null ? storeUserVo.getSubAccountId() : storeUserVo.getId();
-            storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
-                    .eq(StoreUser::getId, idParam).eq(StoreUser::getDeleteFlag, 0));
-            if (storeUser != null) {
-                userId = storeUser.getId();
-                log.info("deleteStoreAccountInfo 通过子账号 id 查到用户: userId={}, phone={}", userId, storeUser.getPhone());
-            }
-        }
-        if (storeUser == null && storeUserVo.getPhone() != null) {
-            storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
-                    .eq(StoreUser::getPhone, storeUserVo.getPhone()).eq(StoreUser::getDeleteFlag, 0));
-            if (storeUser != null) userId = storeUser.getId();
-        }
-        if (userId == null || storeUser == null) {
-            log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传 userId(subAccountId/id)或 phone");
-            return "删除失败";
-        }
-
+       StoreUser storeUser = storeUserMapper.selectById(storeUserVo.getId());
         // 2. 主账号删除校验:有关联店铺禁止删除,有关联子账号禁止删除
         if (storeUserVo.getAccountType() != null && storeUserVo.getAccountType() == 1) {
             Integer mainIdForCheck = storeUserVo.getId();
@@ -1157,83 +1144,31 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
                 log.error("该主账号下存在关联店铺,禁止删除");
                 return "当前账号下存在店铺 禁止删除";
             }
-            List<Integer> subAccountIds = storeUserMapper.selectSubAccountUserIdsByMainAccountIdWithRole(mainIdForCheck);
-            if (subAccountIds != null && !subAccountIds.isEmpty()) {
-                log.error("该主账号下存在关联子账号,禁止删除");
-                return "当前账号下存在子账号禁止删除";
-            }
-            return null;
-        }
-
-        // 3. 子账号删除:入参等价于 userId、主账号 id(mainAccountId)、主账号店铺 storeId;先查子账号 id 列表再判断
-        Integer mainAccountId = storeUser.getSubAccountId() != null ? storeUser.getSubAccountId() : storeUserVo.getParentAccountId();
-        if (mainAccountId == null) {
-            log.warn("deleteStoreAccountInfo 无法确定主账号,请传 parentAccountId 或保证子账号 sub_account_id 有值");
-            return "删除失败";
-        }
 
-        // 3.1 查询主账号下的子账号 id 列表,根据子账号 id 判断数量及是否包含当前 userId
-        List<Integer> subAccountIds = storeUserMapper.selectSubAccountUserIdsByMainAccountIdWithRole(mainAccountId);
-        if (subAccountIds == null) subAccountIds = Collections.emptyList();
-        int subAccountCount = subAccountIds.size();
-        log.info("deleteStoreAccountInfo 主账号下子账号数量: userId={}, mainAccountId={}, storeId={}, subAccountCount={}", userId, mainAccountId, subAccountCount);
-        if (!subAccountIds.contains(userId)) {
-            log.warn("deleteStoreAccountInfo 当前用户不在主账号子账号列表中: userId={}, mainAccountId={}", userId, mainAccountId);
-            return "删除失败";
-        }
+            // 主账号:存在子账号则禁止删除(按主账号id + 中间表统计)
+            if (hasSubAccountsByMainAccountId(mainIdForCheck)) {
+                log.error("该主账号下存在关联子账号,不能删除");
+                return "请先删除主账号下的子账号后再删除";
+            }
 
-        // 3.2 逻辑删除 store_platform_user_role(按 userId + storeId,delete_flag=1)
-        LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
-        roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, userId)
-                .eq(StorePlatformUserRole::getDeleteFlag, 0)
-                .set(StorePlatformUserRole::getDeleteFlag, 1);
-        int roleUpdateResult = storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
-        if (roleUpdateResult <= 0) {
-            log.error("deleteStoreAccountInfo 逻辑删除 store_platform_user_role 失败: userId={}", userId);
-            return "删除失败";
+            // 主账号无店铺、无子账号,可执行逻辑删除(此处仅校验通过,实际删除逻辑在子账号分支或需补充)
+            return null;
         }
 
-        // 3.3 根据子账号 id 查询用户信息及联系方式,删除 Redis token(key: store_手机号),参照 removeRole
-        StoreUser subUser = storeUserMapper.selectById(userId);
-        if (subUser != null && subUser.getPhone() != null) {
-            String tokenKey = "store_" + subUser.getPhone();
-            try {
-                String existingToken = baseRedisService.getString(tokenKey);
-                if (existingToken != null) {
-                    baseRedisService.delete(tokenKey);
-                    log.info("deleteStoreAccountInfo 清除用户 token 成功: userId={}, phone={}, tokenKey={}", userId, subUser.getPhone(), tokenKey);
-                } else {
-                    log.warn("deleteStoreAccountInfo 用户 token 不存在或已过期: userId={}, phone={}", userId, subUser.getPhone());
-                }
-            } catch (Exception e) {
-                log.warn("deleteStoreAccountInfo 清除 token 异常: userId={}, tokenKey={}", userId, tokenKey, e);
+        // 子账号删除:只要该 userId 在中间表存在关联记录(userId 对得上),就禁止直接删除全局账号
+        if (storeUser != null && storeUser.getAccountType() != null && storeUser.getAccountType() == 2) {
+            long relationCount = countActiveSubAccountRelations(storeUser.getId());
+            if (relationCount > 0) {
+                log.error("该子账号在子账号列表中仍有关联记录,禁止直接删除全局账号 userId={}", storeUser.getId());
+                return "当前子账号在子账号管理中仍有关联记录,请先解除子账号后再删除";
             }
         }
 
-        // 3.4 若该主账号下仅 1 个子账号,则进一步判断是否为主账号,再决定是否同时逻辑删除 store_user(参照 removeRole)
-        if (subAccountCount == 1) {
-            if (subUser != null) {
-                if (subUser.getStoreId() != null && subUser.getStoreId() > 0) {
-                    log.info("deleteStoreAccountInfo 用户是主账号,不删除 store_user 记录: userId={}, storeId={}", userId, subUser.getStoreId());
-                } else {
-                    LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
-                    userUpdateWrapper.eq(StoreUser::getId, userId)
-                            .eq(StoreUser::getDeleteFlag, 0)
-                            .set(StoreUser::getDeleteFlag, 1);
-                    int userUpdateResult = storeUserMapper.update(null, userUpdateWrapper);
-                    if (userUpdateResult > 0) {
-                        log.info("deleteStoreAccountInfo 用户只有一个子账号且不是主账号,已同时逻辑删除 store_user 记录: userId={}", userId);
-                    } else {
-                        log.warn("deleteStoreAccountInfo 逻辑删除 store_user 记录失败或记录不存在: userId={}", userId);
-                    }
-                }
-            } else {
-                log.warn("deleteStoreAccountInfo 未找到用户信息: userId={}", userId);
-            }
-        } else {
-            log.info("deleteStoreAccountInfo 用户有多个子账号(count={}),仅删除 store_platform_user_role 记录,不删除 store_user 记录: userId={}", subAccountCount, userId);
-        }
-        return null;
+        LambdaUpdateWrapper<StoreUser> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(StoreUser::getId, storeUserVo.getId());
+        updateWrapper.set(StoreUser::getDeleteFlag, 1);
+
+        return "删除成功";
     }
 
     @Override