From 6ace927de5c28b0d3f688b654aaa2807ce8b7473 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Wed, 10 Apr 2024 22:59:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=96=B0=E5=A2=9E):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=8A=B6=E6=80=81,=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E9=80=89=E4=B8=AD,=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ssyx/client/ActivityFeignClient.java | 13 ++++ .../cart/controller/CartApiController.java | 24 +++++++ .../ssyx/cart/service/CartInfoService.java | 28 +++++++- .../service/impl/CartInfoServiceImpl.java | 64 +++++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) diff --git a/service-client/service-activity-client/src/main/java/com/atguigu/ssyx/client/ActivityFeignClient.java b/service-client/service-activity-client/src/main/java/com/atguigu/ssyx/client/ActivityFeignClient.java index 8ac4ca6..934e9f1 100644 --- a/service-client/service-activity-client/src/main/java/com/atguigu/ssyx/client/ActivityFeignClient.java +++ b/service-client/service-activity-client/src/main/java/com/atguigu/ssyx/client/ActivityFeignClient.java @@ -1,5 +1,6 @@ package com.atguigu.ssyx.client; +import com.atguigu.ssyx.model.activity.CouponInfo; import com.atguigu.ssyx.model.order.CartInfo; import com.atguigu.ssyx.vo.order.OrderConfirmVo; import org.springframework.cloud.openfeign.FeignClient; @@ -24,4 +25,16 @@ public interface ActivityFeignClient { // 获取购物车满足条件的促销与优惠券信息 @PostMapping("inner/findCartActivityAndCoupon/{userId}") OrderConfirmVo findCartActivityAndCoupon(@RequestBody List cartInfoList, @PathVariable Long userId); + + // 获取优惠券范围对应的购物车列表 + @PostMapping(value = "/api/activity/inner/findRangeSkuIdList/{couponId}") + CouponInfo findRangeSkuIdList(@RequestBody List cartInfoList, @PathVariable("couponId") Long couponId); + + // 根据活动id获取活动skuId列表 + @GetMapping(value = "/api/activity/inner/findSkuIdList/{activityId}") + List findSkuIdList(@PathVariable("activityId") Long activityId); + + // 更新优惠券支付时间 + @GetMapping(value = "/api/activity/inner/updateCouponInfoUsedTime/{couponId}/{userId}") + Boolean updateCouponInfoUsedTime(@PathVariable("couponId") Long couponId, @PathVariable("userId") Long userId); } diff --git a/service/service-cart/src/main/java/com/atguigu/ssyx/cart/controller/CartApiController.java b/service/service-cart/src/main/java/com/atguigu/ssyx/cart/controller/CartApiController.java index 61bfc3a..df5277d 100644 --- a/service/service-cart/src/main/java/com/atguigu/ssyx/cart/controller/CartApiController.java +++ b/service/service-cart/src/main/java/com/atguigu/ssyx/cart/controller/CartApiController.java @@ -70,5 +70,29 @@ public class CartApiController { OrderConfirmVo orderTradeVo = activityFeignClient.findCartActivityAndCoupon(cartInfoList, userId); return Result.success(orderTradeVo); } + + @ApiOperation(value = "更新选中状态") + @GetMapping("checkCart/{skuId}/{isChecked}") + public Result checkCart(@PathVariable Long skuId, @PathVariable Integer isChecked) { + Long userId = BaseContext.getUserId(); + cartInfoService.checkCart(userId, isChecked, skuId); + return Result.success(); + } + + @ApiOperation(value = "更新全部选中") + @GetMapping("checkAllCart/{isChecked}") + public Result checkAllCart(@PathVariable Integer isChecked) { + Long userId = BaseContext.getUserId(); + cartInfoService.checkAllCart(userId, isChecked); + return Result.success(); + } + + @ApiOperation(value = "批量选择购物车") + @PostMapping("batchCheckCart/{isChecked}") + public Result batchCheckCart(@RequestBody List skuIdList, @PathVariable Integer isChecked) { + Long userId = BaseContext.getUserId(); + cartInfoService.batchCheckCart(skuIdList, userId, isChecked); + return Result.success(); + } } diff --git a/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/CartInfoService.java b/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/CartInfoService.java index 54201a8..969895c 100644 --- a/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/CartInfoService.java +++ b/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/CartInfoService.java @@ -34,7 +34,7 @@ public interface CartInfoService { * * 批量删除购物车 * * @param userId 用户id - * @param skuIdList 商品的id + * @param skuIdList 商品的id列表 */ void batchDeleteCart(Long userId, List skuIdList); @@ -45,4 +45,30 @@ public interface CartInfoService { * @return 购物车信息列表 */ List getCartList(Long userId); + + /** + * * 更新选中状态 + * + * @param userId 用户id + * @param isChecked 是否选中 + * @param skuId 商品Id + */ + void checkCart(Long userId, Integer isChecked, Long skuId); + + /** + * * 更新全部选中 + * + * @param userId 用户id + * @param isChecked 是否选中 + */ + void checkAllCart(Long userId, Integer isChecked); + + /** + * * 批量选择购物车 + * + * @param skuIdList 商品的id列表 + * @param userId 用户id + * @param isChecked 是否选中 + */ + void batchCheckCart(List skuIdList, Long userId, Integer isChecked); } diff --git a/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/impl/CartInfoServiceImpl.java b/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/impl/CartInfoServiceImpl.java index 5d332b0..34fb9ee 100644 --- a/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/impl/CartInfoServiceImpl.java +++ b/service/service-cart/src/main/java/com/atguigu/ssyx/cart/service/impl/CartInfoServiceImpl.java @@ -159,4 +159,68 @@ public class CartInfoServiceImpl implements CartInfoService { // 返回结果 return cartInfoList; } + + /** + * * 更新选中状态 + * + * @param userId 用户id + * @param isChecked 是否选中 + * @param skuId 商品Id + */ + @Override + public void checkCart(Long userId, Integer isChecked, Long skuId) { + String cartKey = module.getCartKey(userId); + BoundHashOperations boundedHashOps = redisTemplate.boundHashOps(cartKey); + CartInfo cartInfo = boundedHashOps.get(skuId.toString()); + if (cartInfo != null) { + cartInfo.setIsChecked(isChecked); + boundedHashOps.put(skuId.toString(), cartInfo); + // 设置key过期时间 + module.setCartKeyExpire(cartKey); + } + } + + /** + * * 更新全部选中 + * + * @param userId 用户id + * @param isChecked 是否选中 + */ + @Override + public void checkAllCart(Long userId, Integer isChecked) { + String cartKey = module.getCartKey(userId); + BoundHashOperations boundHashOps = redisTemplate.boundHashOps(cartKey); + List cartInfoList = boundHashOps.values(); + + // 当列表不能为空时做处理 + if (cartInfoList != null) { + cartInfoList.forEach(cartInfo -> { + cartInfo.setIsChecked(isChecked); + boundHashOps.put(cartInfo.getSkuId().toString(), cartInfo); + }); + // 设置过期时间 + module.setCartKeyExpire(cartKey); + } + } + + /** + * * 批量选择购物车 + * + * @param skuIdList 商品的id列表 + * @param userId 用户id + * @param isChecked 是否选中 + */ + @Override + public void batchCheckCart(List skuIdList, Long userId, Integer isChecked) { + String cartKey = module.getCartKey(userId); + BoundHashOperations boundHashOps = redisTemplate.boundHashOps(cartKey); + + // 边路skuId将值更新 + skuIdList.forEach(skuId -> { + CartInfo cartInfo = boundHashOps.get(skuId.toString()); + if (cartInfo != null) { + cartInfo.setIsChecked(isChecked); + } + }); + } }