Explorar el Código

feat(merchant): add delete alipay account functionality

- Added new endpoint /deleteAlipayAccount to remove Alipay account
- Implemented service method to clear alipayAccount field in StoreUser table
- Added parameter validation and user existence check
- Used LambdaUpdateWrapper to explicitly set Alipay account to null
- Included comprehensive logging for the deletion process
- Updated API order and documentation tags accordingly
wxd hace 3 semanas
padre
commit
e4dc9220ab

+ 22 - 1
alien-store-platform/src/main/java/shop/alien/storeplatform/controller/MerchantUserController.java

@@ -10,6 +10,7 @@ import shop.alien.entity.store.vo.StoreUserVo;
 import shop.alien.storeplatform.dto.AddAlipayAccountDTO;
 import shop.alien.storeplatform.dto.SetPayPasswordDTO;
 import shop.alien.storeplatform.service.MerchantUserService;
+import shop.alien.storeplatform.util.LoginUserUtil;
 
 import java.util.Map;
 
@@ -128,8 +129,28 @@ public class MerchantUserController {
         }
     }
 
-    @ApiOperation("重置商户到刚注册状态")
+    @ApiOperation("删除支付宝账号")
     @ApiOperationSupport(order = 6)
+    @PostMapping("/deleteAlipayAccount")
+    public R<Boolean> deleteAlipayAccount() {
+        log.info("MerchantUserController.deleteAlipayAccount - 删除支付宝账号");
+        try {
+            // 从token中获取当前登录用户的ID
+            Integer userId = LoginUserUtil.getCurrentUserId();
+            
+            boolean success = merchantUserService.deleteAlipayAccount(userId);
+            if (success) {
+                return R.success("删除成功");
+            }
+            return R.fail("删除失败");
+        } catch (Exception e) {
+            log.error("MerchantUserController.deleteAlipayAccount ERROR: {}", e.getMessage(), e);
+            return R.fail("删除失败:" + e.getMessage());
+        }
+    }
+
+    @ApiOperation("重置商户到刚注册状态")
+    @ApiOperationSupport(order = 7)
     @PostMapping("/resetToInitialStatus")
     public R<Boolean> resetToInitialStatus() {
         log.info("MerchantUserController.resetToInitialStatus - 重置商户状态");

+ 8 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/MerchantUserService.java

@@ -57,6 +57,14 @@ public interface MerchantUserService {
     Integer addAlipayAccount(Integer userId, String alipayAccount);
 
     /**
+     * 删除支付宝账号
+     *
+     * @param userId 用户ID
+     * @return 是否删除成功
+     */
+    boolean deleteAlipayAccount(Integer userId);
+
+    /**
      * 重置商户到刚注册状态
      * (一键退回:删除店铺申请、解绑店铺、清理相关数据)
      *

+ 39 - 0
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/MerchantUserServiceImpl.java

@@ -282,6 +282,45 @@ public class MerchantUserServiceImpl implements MerchantUserService {
     }
 
     /**
+     * 删除支付宝账号
+     * 将 StoreUser 表中的 alipayAccount 字段置空
+     *
+     * @param userId 用户ID
+     * @return 是否删除成功
+     */
+    @Override
+    public boolean deleteAlipayAccount(Integer userId) {
+        log.info("MerchantUserServiceImpl.deleteAlipayAccount - 开始删除支付宝账号: userId={}", userId);
+
+        // 1. 参数验证
+        if (userId == null) {
+            log.warn("MerchantUserServiceImpl.deleteAlipayAccount - 用户ID为空");
+            throw new RuntimeException("用户ID不能为空");
+        }
+
+        // 2. 查询用户是否存在
+        StoreUser storeUser = storeUserMapper.selectById(userId);
+        if (storeUser == null) {
+            log.warn("MerchantUserServiceImpl.deleteAlipayAccount - 用户不存在: userId={}", userId);
+            throw new RuntimeException("用户不存在");
+        }
+
+        // 4. 使用 LambdaUpdateWrapper 显式将支付宝账号设置为 null
+        LambdaUpdateWrapper<StoreUser> updateWrapper = new LambdaUpdateWrapper<>();
+        updateWrapper.eq(StoreUser::getId, userId)
+                .set(StoreUser::getAlipayAccount, null);  // 显式设置为 null
+
+        // 5. 执行更新
+        int updateResult = storeUserMapper.update(null, updateWrapper);
+        boolean success = updateResult > 0;
+
+        log.info("MerchantUserServiceImpl.deleteAlipayAccount - 删除完成: userId={}, success={}", 
+                userId, success);
+
+        return success;
+    }
+
+    /**
      * 重置商户到刚注册状态
      * 一键退回:删除店铺申请、解绑店铺、清理相关数据
      *