From ca32ddc0624ae88ef210f0449ec411101acaa0a5 Mon Sep 17 00:00:00 2001 From: wyn <1074145239@qq.com> Date: Fri, 7 Aug 2026 13:26:30 +0800 Subject: [PATCH] =?UTF-8?q?book/user/info/=E6=8E=A5=E5=8F=A3=E6=94=B9?= =?UTF-8?q?=E9=80=A0-=E5=AE=89=E5=85=A8=E7=9B=91=E7=AE=A1=E5=B1=80=20?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=AE=A1=E7=90=86-=E5=A5=97=E4=B9=A6?= =?UTF-8?q?=E6=89=BE=E5=8D=95=E5=93=81=E5=AF=B9=E5=BA=94=E7=9A=84=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/controller/MyUserController.java | 28 +++++++++++++++---- .../impl/InventoryManagementServiceImpl.java | 24 ++++++++-------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/peanut/modules/book/controller/MyUserController.java b/src/main/java/com/peanut/modules/book/controller/MyUserController.java index be5058c..db0fd8d 100644 --- a/src/main/java/com/peanut/modules/book/controller/MyUserController.java +++ b/src/main/java/com/peanut/modules/book/controller/MyUserController.java @@ -20,6 +20,8 @@ import com.peanut.modules.common.entity.*; import com.peanut.modules.common.service.UserContributionService; import com.peanut.modules.common.service.UserInviteRegisterService; import com.peanut.modules.common.service.UserVipService; +import com.peanut.modules.sys.entity.SysUserTokenEntity; +import com.peanut.modules.sys.service.ShiroService; import com.peanut.modules.sys.service.SysUserTokenService; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; @@ -51,6 +53,8 @@ public class MyUserController { @Autowired private SysUserTokenService sysUserTokenService; @Autowired + private ShiroService shiroService; + @Autowired private TransactionDetailsService transactionDetailsService; @Autowired private UserInviteRegisterService inviteRegisterService; @@ -126,15 +130,27 @@ public class MyUserController { /** * 信息 + * 通过 token 获取当前用户:管理员可按 id 查询任意用户;其他角色仅可查询自身信息 + * 说明:/book/user/** 为 anon,需手动解析 token,不能依赖 Shiro principal */ @RequestMapping("/info/{id}") // @RequiresPermissions("book:user:info") - public R info(@PathVariable("id") String id){ - MyUserEntity user = userService.getById(id); -// List list = couponHistoryService.getBaseMapper().selectList(new QueryWrapper().eq("member_id", id) -// .eq("use_status", 0)); -// user.setConponsCount(list.size()); - + public R info(@PathVariable("id") String id, HttpServletRequest request){ + String token = request.getHeader("token"); + if (StringUtils.isEmpty(token)) { + return R.error("无权限访问"); + } + SysUserTokenEntity tokenEntity = shiroService.queryByToken(token); + if (tokenEntity == null || tokenEntity.getExpireTime() == null + || tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()) { + return R.error("无权限访问"); + } + Long tokenUserId = tokenEntity.getUserId(); + // 与 OAuth2Realm 一致:userId < 10000 为后台管理员,可查任意用户;否则仅可查自身 + if (tokenUserId >= 10000 && !String.valueOf(tokenUserId).equals(id)) { + return R.error("无权限访问"); + } + MyUserEntity user = userService.getById(id); return R.ok().put("user", user); } diff --git a/src/main/java/com/peanut/modules/master/service/impl/InventoryManagementServiceImpl.java b/src/main/java/com/peanut/modules/master/service/impl/InventoryManagementServiceImpl.java index 3700866..fe6ff83 100644 --- a/src/main/java/com/peanut/modules/master/service/impl/InventoryManagementServiceImpl.java +++ b/src/main/java/com/peanut/modules/master/service/impl/InventoryManagementServiceImpl.java @@ -317,7 +317,6 @@ public class InventoryManagementServiceImpl extends ServiceImpl() .eq(ShopProductBookEntity::getProductId, candidateId) ); - if (bookCount != null && bookCount == 1) { - componentProductId = candidateId; - break; + if (bookCount == null || bookCount != 1) { + continue; + } + ShopProduct product = shopProductDao.selectById(candidateId); + if (product == null || (product.getDelFlag() != null && product.getDelFlag() != 0)) { + continue; + } + // 只要纯书/预售书,排除书课组合(07)等 + String goodsType = product.getGoodsType(); + if ("02".equals(goodsType) || "03".equals(goodsType)) { + return product; } } - if (componentProductId == null) { - return null; - } - ShopProduct product = shopProductDao.selectById(componentProductId); - if (product == null || (product.getDelFlag() != null && product.getDelFlag() != 0)) { - return null; - } - return product; + return null; } private void validateSetBookComponentStock(List bookIds, Integer merchantId, int quantity, Integer setProductId) {