校验 剩余数量

This commit is contained in:
wangw 2025-09-18 15:06:05 +08:00
parent 6756f35db6
commit 84f0cb0a9b
2 changed files with 10 additions and 10 deletions

View File

@ -38,7 +38,7 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
*
* @param giftDTO sourceFlowId 全必填 如果有 也填
* @param number 发放数量
* @param isLimit 是否校验限领活动与管理员添加 不计限领
* @param isLimit 是否校验限领/扣除剩余数量活动与管理员添加 不计限领
*/
void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit);

View File

@ -139,18 +139,22 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
AssertUtil.isNull(coupon.getShopId(), "优惠券店铺不存在");
AssertUtil.isNotEqual(coupon.getShopId(), giftDTO.getShopId(), "优惠券店铺与发放店铺不一致");
AssertUtil.isNotEqual(coupon.getStatus(), 1, "优惠券已失效");
if (isLimit) {
if (coupon.getGiveNum() >= 0 && coupon.getLeftNum() < number) {
throw new CzgException("优惠券库存不足");
}
if (isLimit) {
//查询已领取张数
long count = this.queryChain()
.eq(MkShopCouponRecord::getShopUserId, shopUser.getId())
.eq(MkShopCouponRecord::getCouponId, giftDTO.getCouponId()).count();
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);
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
LocalDateTime end = null;
@ -187,10 +191,6 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
record.setUseEndTime(end);
save(record);
}
coupon.setGiftNum(coupon.getGiftNum() + number);
if (coupon.getGiveNum() != -10086) {
coupon.setLeftNum(coupon.getLeftNum() - number);
}
couponService.update(coupon, true);
}