Search in sources :

Example 1 with MemberCoupon

use of com.whoiszxl.entity.MemberCoupon in project shopzz by whoiszxl.

the class CouponServiceImpl method receive.

@Override
public void receive(Long couponId) {
    // 1. 校验优惠券是否存在,是否有效
    Coupon coupon = super.getOne(Wrappers.<Coupon>lambdaQuery().eq(Coupon::getId, couponId).eq(Coupon::getStatus, CouponStatusEnum.AVAIL.getCode()));
    AssertUtils.isTrue(coupon != null, "优惠券不存在");
    // 2. 判断是否在有效期内
    LocalDateTime now = LocalDateTime.now();
    if (now.isBefore(coupon.getStartTime()) || now.isAfter(coupon.getEndTime())) {
        // 将优惠券更新为过期状态
        coupon.setStatus(CouponStatusEnum.EXPIRED.getCode());
        super.updateById(coupon);
        return;
    }
    // 3. 判断是否领取过
    Long memberId = AuthUtils.getMemberId();
    MemberCoupon memberCoupon = memberCouponService.getOne(Wrappers.<MemberCoupon>lambdaQuery().eq(MemberCoupon::getCouponId, couponId).eq(MemberCoupon::getMemberId, memberId));
    AssertUtils.isTrue(memberCoupon == null, "不能重复领取");
    // 4. 领取成功
    MemberCoupon saveParams = new MemberCoupon();
    saveParams.setCouponId(couponId);
    saveParams.setMemberId(memberId);
    saveParams.setGetTime(now);
    memberCouponService.save(saveParams);
}
Also used : LocalDateTime(java.time.LocalDateTime) Coupon(com.whoiszxl.entity.Coupon) MemberCoupon(com.whoiszxl.entity.MemberCoupon) MemberCoupon(com.whoiszxl.entity.MemberCoupon)

Example 2 with MemberCoupon

use of com.whoiszxl.entity.MemberCoupon in project shopzz by whoiszxl.

the class PromotionFeignClientImpl method checkCouponIsUsed.

@Override
public ResponseResult<Boolean> checkCouponIsUsed(Long couponId) {
    Long memberId = AuthUtils.getMemberId();
    MemberCoupon memberCoupon = memberCouponService.getOne(Wrappers.<MemberCoupon>lambdaQuery().eq(MemberCoupon::getCouponId, couponId).eq(MemberCoupon::getMemberId, memberId));
    if (memberCoupon == null) {
        return ResponseResult.buildSuccess();
    }
    return ResponseResult.buildError();
}
Also used : MemberCoupon(com.whoiszxl.entity.MemberCoupon)

Aggregations

MemberCoupon (com.whoiszxl.entity.MemberCoupon)2 Coupon (com.whoiszxl.entity.Coupon)1 LocalDateTime (java.time.LocalDateTime)1