浏览代码

子账号列表接口 禁用接口

liudongzhi 2 月之前
父节点
当前提交
9715a8e243

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

@@ -25,6 +25,9 @@ public class SubAccountListVo {
     @ApiModelProperty(value = "主账号联系电话")
     private String mainAccountPhone;
 
+    @ApiModelProperty(value = "子账号中间表ID")
+    private Integer subAccountId;
+
     @ApiModelProperty(value = "子账号用户ID")
     private Integer userId;
 

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

@@ -39,6 +39,7 @@
             su_main.phone AS mainAccountPhone,
             sur.id AS userId,
             sur.phone AS phone,
+            spur.id AS subAccountId,
             spur.account_name AS accountName,
             spur.store_id AS storeId,
             spr.role_id AS roleId,

+ 25 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/StorePlatformUserRoleController.java

@@ -265,5 +265,30 @@ public class StorePlatformUserRoleController {
         return R.data(subAccountPage);
     }
 
+    @ApiOperation("禁用子账号")
+    @ApiOperationSupport(order = 12)
+    @PlatformOperationLog(
+            module = "账号操作记录",
+            type = "禁用子账号",
+            content = "禁用子账号(关联记录ID=#{#id})"
+    )
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "子账号关联记录的主键ID", dataType = "Long", paramType = "query", required = true)
+    })
+    @PostMapping("/disableSubAccount")
+    public R<String> disableSubAccount(@RequestParam("id") Long id) {
+        log.info("StorePlatformUserRoleController.disableSubAccount?id={}", id);
+        
+        if (id == null) {
+            return R.fail("子账号关联记录ID不能为空");
+        }
+        
+        boolean result = storePlatformUserRoleService.disableSubAccount(id);
+        if (result) {
+            return R.success("禁用子账号成功");
+        }
+        return R.fail("禁用子账号失败");
+    }
+
 }
 

+ 9 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/StorePlatformUserRoleService.java

@@ -137,5 +137,14 @@ public interface StorePlatformUserRoleService extends IService<StorePlatformUser
      * @return 子账号分页列表
      */
     IPage<SubAccountListVo> queryAllSubAccounts(Integer pageNum, Integer pageSize, String accountId, String phone, Integer status);
+
+    /**
+     * 禁用子账号
+     * 将 store_platform_user_role 表中指定记录的 status 从 0 改为 1
+     *
+     * @param id 子账号关联记录的主键ID
+     * @return 是否成功
+     */
+    boolean disableSubAccount(Long id);
 }
 

+ 42 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StorePlatformUserRoleServiceImpl.java

@@ -798,5 +798,47 @@ public class StorePlatformUserRoleServiceImpl extends ServiceImpl<StorePlatformU
             return emptyPage;
         }
     }
+
+    @Override
+    public boolean disableSubAccount(Long id) {
+        if (id == null) {
+            log.error("子账号关联记录ID不能为空");
+            return false;
+        }
+
+        try {
+            // 1. 先查询记录是否存在
+            StorePlatformUserRole userRole = storePlatformUserRoleMapper.selectById(id);
+            if (userRole == null) {
+                log.error("子账号关联记录不存在: id={}", id);
+                return false;
+            }
+
+            // 2. 检查当前状态
+            if (userRole.getStatus() != null && userRole.getStatus() == 1) {
+                log.warn("子账号已经是禁用状态: id={}", id);
+                return true; // 已经是禁用状态,返回成功
+            }
+
+            // 3. 更新状态为禁用(1)
+            LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
+            updateWrapper.eq(StorePlatformUserRole::getId, id)
+                    .eq(StorePlatformUserRole::getDeleteFlag, 0) // 只更新未删除的记录
+                    .set(StorePlatformUserRole::getStatus, 1); // 1代表禁用
+
+            int updateResult = storePlatformUserRoleMapper.update(null, updateWrapper);
+            if (updateResult > 0) {
+                log.info("成功禁用子账号: id={}, userId={}, storeId={}, roleId={}", 
+                        id, userRole.getUserId(), userRole.getStoreId(), userRole.getRoleId());
+                return true;
+            } else {
+                log.error("禁用子账号失败: id={}", id);
+                return false;
+            }
+        } catch (Exception e) {
+            log.error("禁用子账号异常: id={}", id, e);
+            return false;
+        }
+    }
 }