Browse Source

fix(shop): 修复未登录用户可领取优惠券的bug- 在领取优惠券接口中增加了登录验证逻辑

- 确保只有已登录用户才能领取优惠券
main
科技小王子 3 days ago
parent
commit
a38256f9ca
  1. 4
      src/main/java/com/gxwebsoft/shop/controller/ShopUserCouponController.java

4
src/main/java/com/gxwebsoft/shop/controller/ShopUserCouponController.java

@ -117,7 +117,9 @@ public class ShopUserCouponController extends BaseController {
@Operation(summary = "领取优惠券")
@PostMapping("/take")
public ApiResult<?> take(@RequestBody ShopUserCoupon userCoupon) {
ShopCoupon coupon = couponService.getByIdRel(userCoupon.getCouponId());
final User loginUser = getLoginUser();
if (loginUser == null) return fail("请先登录");
ShopCoupon coupon = couponService.getByIdRel(userCoupon.getCouponId());
if (coupon.getTotalCount() != -1 && coupon.getReceiveNum() >= coupon.getTotalCount()) return fail("已经被领完了");
List<ShopUserCoupon> userCouponList = shopUserCouponService.list(
new LambdaQueryWrapper<ShopUserCoupon>()

Loading…
Cancel
Save