| | |
| | | @Autowired |
| | | private AppUserClient appUserClient; |
| | | |
| | | /** |
| | | * 查询注册赠送优惠券 判断当前优惠券限领数量 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/coupon/queryCouponByUser/{userId}") |
| | | public List<Integer> queryCouponByUser(@PathVariable("userId") Integer userId){ |
| | | List<Coupon> list = couponService.list(new QueryWrapper<Coupon>().eq("distributionMethod", 2) |
| | | .le("startTime", new Date()).ge("endTime", new Date()).eq("auditStatus", 2) |
| | | .eq("state", 1)); |
| | | |
| | | for (Coupon coupon : list) { |
| | | // 发放数量 |
| | | Integer quantityIssued = coupon.getQuantityIssued(); |
| | | // 限领数量 |
| | | Integer pickUpQuantity = coupon.getPickUpQuantity(); |
| | | // 优惠券已领取数量 |
| | | int couponId = ucService.count(new QueryWrapper<UserCoupon>().eq("couponId", coupon.getId())); |
| | | // 用户已领取该优惠券数量 |
| | | int count = ucService.count(new QueryWrapper<UserCoupon>().eq("couponId", coupon.getId() |
| | | ).eq("userId", userId)); |
| | | if (couponId>=quantityIssued){ |
| | | continue; |
| | | } |
| | | if (count>=pickUpQuantity){ |
| | | continue; |
| | | } |
| | | // 条件满足 将优惠券送给用户 |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setCouponId(coupon.getId()); |
| | | userCoupon.setUserId(userId); |
| | | userCoupon.setStatus(1); |
| | | userCoupon.setInsertTime(new Date()); |
| | | ucService.save(userCoupon); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/api/coupon/queryCouponList") |