|
@@ -133,7 +133,7 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
@Override
|
|
@Override
|
|
public Long claimCoupon(@NonNull Long couponId) {
|
|
public Long claimCoupon(@NonNull Long couponId) {
|
|
Coupon coupon = ResourceUtils.required(couponService.getById(couponId), "优惠券不存在");
|
|
Coupon coupon = ResourceUtils.required(couponService.getById(couponId), "优惠券不存在");
|
|
- if (CouponClaimType.FREE.equals(coupon.getClaimType())) {
|
|
|
|
|
|
+ if (!CouponClaimType.FREE.equals(coupon.getClaimType())) {
|
|
throw new ResourceUnavailableException("当前优惠券不允许免费领取");
|
|
throw new ResourceUnavailableException("当前优惠券不允许免费领取");
|
|
}
|
|
}
|
|
Long userId = SessionContextHolder.getId();
|
|
Long userId = SessionContextHolder.getId();
|
|
@@ -141,7 +141,8 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
this.checkCouponLimit(coupon, userId);
|
|
this.checkCouponLimit(coupon, userId);
|
|
// 保存优惠券领取记录
|
|
// 保存优惠券领取记录
|
|
UserCoupon userCoupon = UserCoupon.builder().userId(userId).couponId(couponId)
|
|
UserCoupon userCoupon = UserCoupon.builder().userId(userId).couponId(couponId)
|
|
- .type(coupon.getType()).used(false).build();
|
|
|
|
|
|
+ .type(coupon.getType()).used(0).build();
|
|
|
|
+ userCoupon.setStatus(UserCouponStatus.UNUSED);
|
|
this.save(userCoupon);
|
|
this.save(userCoupon);
|
|
// 修改优惠券的领取数量
|
|
// 修改优惠券的领取数量
|
|
couponService.updateCouponReceivedNum(couponId, 1);
|
|
couponService.updateCouponReceivedNum(couponId, 1);
|
|
@@ -185,9 +186,9 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
Integer haveCoupons = this.lambdaQuery()
|
|
Integer haveCoupons = this.lambdaQuery()
|
|
.eq(UserCoupon::getUserId, userId)
|
|
.eq(UserCoupon::getUserId, userId)
|
|
.eq(UserCoupon::getCouponId, coupon.getId()).count();
|
|
.eq(UserCoupon::getCouponId, coupon.getId()).count();
|
|
- if (!PromotionStatus.START.equals(coupon.getPromotionStatus())) {
|
|
|
|
- throw new ResourceUnavailableException("当前优惠券已经被领取完了,下次要早点来哦");
|
|
|
|
- }
|
|
|
|
|
|
+// if (!PromotionStatus.START.equals(coupon.getPromotionStatus())) {
|
|
|
|
+// throw new ResourceUnavailableException("当前优惠券已经被领取完了,下次要早点来哦");
|
|
|
|
+// }
|
|
if (coupon.getPublishNum() != 0 && coupon.getReceivedNum() >= coupon.getPublishNum()) {
|
|
if (coupon.getPublishNum() != 0 && coupon.getReceivedNum() >= coupon.getPublishNum()) {
|
|
throw new ResourceUnavailableException("优惠券剩余领取数量不足");
|
|
throw new ResourceUnavailableException("优惠券剩余领取数量不足");
|
|
}
|
|
}
|
|
@@ -239,7 +240,7 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
|
|
List<UserCouponDTO> userCouponList = UserCouponCopier.INSTANCE.copying(baseMapper.selectList(lwq));
|
|
List<UserCouponDTO> userCouponList = UserCouponCopier.INSTANCE.copying(baseMapper.selectList(lwq));
|
|
if (userCouponList != null && userCouponList.size()>0){
|
|
if (userCouponList != null && userCouponList.size()>0){
|
|
userCouponList.forEach(item ->{
|
|
userCouponList.forEach(item ->{
|
|
- item.setCouponDTO(CouponCopier.INSTANCE.copying(this.couponService.getById(item.getId())));
|
|
|
|
|
|
+ item.setCouponDTO(CouponCopier.INSTANCE.copying(this.couponService.getById(item.getCouponId())));
|
|
if (CouponType.REDUCE.equals(item.getCouponDTO().getType())){
|
|
if (CouponType.REDUCE.equals(item.getCouponDTO().getType())){
|
|
int comparison = amount.compareTo(new BigDecimal(item.getCouponDTO().getConsumeThreshold()));
|
|
int comparison = amount.compareTo(new BigDecimal(item.getCouponDTO().getConsumeThreshold()));
|
|
if (comparison == 0) {
|
|
if (comparison == 0) {
|