From 64e772a47ccfa58dbd22d0adcc31b16f94fd2562 Mon Sep 17 00:00:00 2001 From: Jack <46790855@qq.com> Date: Fri, 27 Jun 2025 16:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/common/utils/UserInfoService.java | 10 +++-- .../admin/ShopPageBaseController.java | 40 +++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/mall-common/src/main/java/com/suisung/mall/common/utils/UserInfoService.java b/mall-common/src/main/java/com/suisung/mall/common/utils/UserInfoService.java index bb60a778..95e78cc9 100644 --- a/mall-common/src/main/java/com/suisung/mall/common/utils/UserInfoService.java +++ b/mall-common/src/main/java/com/suisung/mall/common/utils/UserInfoService.java @@ -47,13 +47,17 @@ public class UserInfoService { userStr = null; } + UserDto userDto; if (StrUtil.isNotBlank(userStr)) { // 将 JSON 字符串转换为 UserDto 对象 - return JSONUtil.toBean(userStr, UserDto.class); + userDto = JSONUtil.toBean(userStr, UserDto.class); + } else { + // 如果 userStr 为空,尝试通过 token 获取用户信息 + userDto = getUserByToken(); } - // 如果 userStr 为空,尝试通过 token 获取用户信息 - return getUserByToken(); + log.info("用户信息:{}", userDto); + return userDto; } public Integer getUserId() { diff --git a/mall-shop/src/main/java/com/suisung/mall/shop/page/controller/admin/ShopPageBaseController.java b/mall-shop/src/main/java/com/suisung/mall/shop/page/controller/admin/ShopPageBaseController.java index 7bccf062..b6583d17 100644 --- a/mall-shop/src/main/java/com/suisung/mall/shop/page/controller/admin/ShopPageBaseController.java +++ b/mall-shop/src/main/java/com/suisung/mall/shop/page/controller/admin/ShopPageBaseController.java @@ -150,15 +150,39 @@ public class ShopPageBaseController extends BaseControllerImpl { @ApiOperation(value = "页面表-通过page_id删除", notes = "页面表-通过page_id删除") @RequestMapping(value = "/remove", method = RequestMethod.POST) public CommonResult remove(@RequestParam(name = "page_id") Long page_id) { - UserDto user = getCurrentUser(); - if (user == null || !user.isPlatform()) { - throw new ApiException(ResultCode.FORBIDDEN); - } + try { + UserDto user = getCurrentUser(); - if (shopPageBaseService.remove(page_id)) { - return CommonResult.success(); - } else { - return CommonResult.failed(); + // 用户未登录,禁止操作 + if (user == null) { + throw new ApiException(ResultCode.FORBIDDEN); + } + + // 非平台管理员,只能删除自己店铺的页面 + if (!user.isPlatform()) { + String storeId = user.getStore_id(); + ShopPageBase shopPageBase = shopPageBaseService.getById(page_id); +// log.info("storeId:{}", storeId); +// log.info("shopPageBase:{}", shopPageBase); + + // 页面不存在 或 当前用户无店铺信息 或 页面归属与当前店铺不符,则禁止删除 + if (shopPageBase == null || StrUtil.isBlank(storeId) || !storeId.equals(shopPageBase.getStore_id().toString())) { + throw new ApiException(ResultCode.FORBIDDEN); + } + } + + // 执行删除操作 + boolean isRemoved = shopPageBaseService.remove(page_id); + return isRemoved ? CommonResult.success() : CommonResult.failed(); + + } catch (ApiException e) { + // 已知业务异常,直接抛出 + log.warn("删除页面失败,参数:{}", page_id, e); + throw e; + } catch (Exception e) { + // 未知系统异常,记录日志并返回友好提示 + log.error("删除页面发生系统异常,page_id: {}", page_id, e); + throw new ApiException(ResultCode.FAILED); } }