Преглед на файлове

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

wuchen преди 2 месеца
родител
ревизия
456b407b18

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

@@ -428,9 +428,9 @@ public class StoreUserController {
             @ApiImplicitParam(name = "phone", value = "子账号联系电话(可选,与 subAccountId 二选一)", dataType = "String", paramType = "body")
     })
     @PostMapping("/deleteStoreAccountInfo")
-    public R<String> deleteStoreAccountInfo(@RequestBody StoreUserVo storeUserVo) {
-        log.info("StoreUserController.deleteStoreAccountInfo?phone={}, id={}", storeUserVo.getPhone(), storeUserVo.getSubAccountId());
-        String errMsg = storeUserService.deleteStoreAccountInfo(storeUserVo);
+    public R<String> deleteStoreAccountInfo(@RequestBody StoreUser storeUser) {
+        log.info("StoreUserController.deleteStoreAccountInfo? id={}", storeUser.getId());
+        String errMsg = storeUserService.deleteStoreAccountInfo(storeUser);
         if (errMsg == null || errMsg.isEmpty()) {
             return R.success("删除成功");
         }

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

@@ -176,7 +176,7 @@ public interface StoreUserService extends IService<StoreUser> {
      * 手动删除商家账号及店铺 进行校验
      * @return 成功返回 null;失败返回具体原因:当前账号下存在店铺 禁止删除 / 当前账号下存在子账号禁止删除 / 删除失败
      */
-    String deleteStoreAccountInfo(StoreUserVo storeUserVo);
+    String deleteStoreAccountInfo(StoreUser storeUser);
 
     /**
      * 获取主键集合

+ 16 - 21
alien-store/src/main/java/shop/alien/store/service/impl/StoreUserServiceImpl.java

@@ -717,13 +717,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
             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);
@@ -1126,33 +1120,31 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
      * 子账号:参照 removeRole 逻辑,按 userId/storeId 逻辑删除 store_platform_user_role;若该主账号下仅 1 个子账号且非主账号则同时逻辑删除 store_user 并清 token。
      */
     @Override
-    public String deleteStoreAccountInfo(StoreUserVo storeUserVo) {
-        if (storeUserVo == null) {
+    public String deleteStoreAccountInfo(StoreUser storeUser) {
+        if (storeUser == null) {
             log.warn("deleteStoreAccountInfo 参数不能为空");
             return "删除失败";
         }
-       StoreUser storeUser = storeUserMapper.selectById(storeUserVo.getId());
+       StoreUser user = storeUserMapper.selectById(storeUser.getId());
         // 2. 主账号删除校验:有关联店铺禁止删除,有关联子账号禁止删除
-        if (storeUserVo.getAccountType() != null && storeUserVo.getAccountType() == 1) {
-            Integer mainIdForCheck = storeUserVo.getId();
-            if (mainIdForCheck == null) {
+        if (storeUser.getAccountType() != null && storeUser.getAccountType() == 1) {
+            if (user == null) {
                 log.warn("deleteStoreAccountInfo 删除主账号时 id 不能为空");
                 return "删除失败";
             }
-            StoreUser mainUser = storeUserMapper.selectById(mainIdForCheck);
-            if (mainUser != null && mainUser.getStoreId() != null && mainUser.getStoreId() > 0) {
+
+            if (user != null && user.getStoreId() != null && user.getStoreId() > 0) {
                 log.error("该主账号下存在关联店铺,禁止删除");
                 return "当前账号下存在店铺 禁止删除";
             }
 
             // 主账号:存在子账号则禁止删除(按主账号id + 中间表统计)
-            if (hasSubAccountsByMainAccountId(mainIdForCheck)) {
+
+            if (hasSubAccountsByMainAccountId(user.getId())) {
                 log.error("该主账号下存在关联子账号,不能删除");
                 return "请先删除主账号下的子账号后再删除";
             }
 
-            // 主账号无店铺、无子账号,可执行逻辑删除(此处仅校验通过,实际删除逻辑在子账号分支或需补充)
-            return null;
         }
 
         // 子账号删除:只要该 userId 在中间表存在关联记录(userId 对得上),就禁止直接删除全局账号
@@ -1165,10 +1157,13 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
         }
 
         LambdaUpdateWrapper<StoreUser> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.eq(StoreUser::getId, storeUserVo.getId());
+        updateWrapper.eq(StoreUser::getId, storeUser.getId());
         updateWrapper.set(StoreUser::getDeleteFlag, 1);
-
-        return "删除成功";
+        int update = storeUserMapper.update(null, updateWrapper);
+        if (update > 0) {
+            return "删除成功";
+        }
+        return "删除失败";
     }
 
     @Override