校验 剩余数量
This commit is contained in:
parent
6756f35db6
commit
84f0cb0a9b
|
|
@ -38,7 +38,7 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
|
||||||
*
|
*
|
||||||
* @param giftDTO 除 sourceFlowId 外 全必填 如果有 也填
|
* @param giftDTO 除 sourceFlowId 外 全必填 如果有 也填
|
||||||
* @param number 发放数量
|
* @param number 发放数量
|
||||||
* @param isLimit 是否校验限领,活动与管理员添加 不计限领
|
* @param isLimit 是否校验限领/扣除剩余数量,活动与管理员添加 不计限领
|
||||||
*/
|
*/
|
||||||
void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit);
|
void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,18 +139,22 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||||
AssertUtil.isNull(coupon.getShopId(), "优惠券店铺不存在");
|
AssertUtil.isNull(coupon.getShopId(), "优惠券店铺不存在");
|
||||||
AssertUtil.isNotEqual(coupon.getShopId(), giftDTO.getShopId(), "优惠券店铺与发放店铺不一致");
|
AssertUtil.isNotEqual(coupon.getShopId(), giftDTO.getShopId(), "优惠券店铺与发放店铺不一致");
|
||||||
AssertUtil.isNotEqual(coupon.getStatus(), 1, "优惠券已失效");
|
AssertUtil.isNotEqual(coupon.getStatus(), 1, "优惠券已失效");
|
||||||
|
if (isLimit) {
|
||||||
if (coupon.getGiveNum() >= 0 && coupon.getLeftNum() < number) {
|
if (coupon.getGiveNum() >= 0 && coupon.getLeftNum() < number) {
|
||||||
throw new CzgException("优惠券库存不足");
|
throw new CzgException("优惠券库存不足");
|
||||||
}
|
}
|
||||||
if (isLimit) {
|
|
||||||
//查询已领取张数
|
//查询已领取张数
|
||||||
long count = this.queryChain()
|
long count = this.queryChain()
|
||||||
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
|
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
|
||||||
.eq(MkShopCouponRecord::getCouponId, giftDTO.getCouponId()).count();
|
.eq(MkShopCouponRecord::getCouponId, giftDTO.getCouponId()).count();
|
||||||
if (coupon.getGetLimit() >= 0 && count >= coupon.getGetLimit()) {
|
if (coupon.getGetLimit() >= 0 && count >= coupon.getGetLimit()) {
|
||||||
throw new CzgException("已达到领取限制,不可领取7");
|
throw new CzgException("已达到领取限制,不可领取");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
coupon.setGiftNum(coupon.getGiftNum() + number);
|
||||||
|
if (coupon.getGiveNum() != -10086 && isLimit) {
|
||||||
|
coupon.setLeftNum(coupon.getLeftNum() - number);
|
||||||
|
}
|
||||||
String couponJson = JSONObject.toJSONString(coupon);
|
String couponJson = JSONObject.toJSONString(coupon);
|
||||||
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||||
LocalDateTime end = null;
|
LocalDateTime end = null;
|
||||||
|
|
@ -187,10 +191,6 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||||
record.setUseEndTime(end);
|
record.setUseEndTime(end);
|
||||||
save(record);
|
save(record);
|
||||||
}
|
}
|
||||||
coupon.setGiftNum(coupon.getGiftNum() + number);
|
|
||||||
if (coupon.getGiveNum() != -10086) {
|
|
||||||
coupon.setLeftNum(coupon.getLeftNum() - number);
|
|
||||||
}
|
|
||||||
couponService.update(coupon, true);
|
couponService.update(coupon, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue