You've already forked FrameTour-BE
fix(pricing): 修复优惠券库存检查逻辑
- 修正totalQuantity为NULL或0时不限制总量的判断逻辑 - 优化claimedQuantity为空时的默认值处理 - 仅在totalQuantity大于0时更新已领取数量 - 完善MD文档中字段语义描述和配置示例 - 更新SQL表字段说明及典型配置组合示例
This commit is contained in:
@@ -231,8 +231,10 @@ public class CouponServiceImpl implements ICouponService {
|
||||
}
|
||||
|
||||
// 5. 检查库存(如果有总量限制)
|
||||
if (coupon.getTotalQuantity() != null && coupon.getClaimedQuantity() != null) {
|
||||
if (coupon.getClaimedQuantity() >= coupon.getTotalQuantity()) {
|
||||
// totalQuantity为NULL或0表示不限制总量
|
||||
if (coupon.getTotalQuantity() != null && coupon.getTotalQuantity() > 0) {
|
||||
int currentClaimed = (coupon.getClaimedQuantity() == null ? 0 : coupon.getClaimedQuantity());
|
||||
if (currentClaimed >= coupon.getTotalQuantity()) {
|
||||
return CouponClaimResult.failure(CouponClaimResult.ERROR_COUPON_OUT_OF_STOCK, "优惠券已领完");
|
||||
}
|
||||
}
|
||||
@@ -276,7 +278,8 @@ public class CouponServiceImpl implements ICouponService {
|
||||
}
|
||||
|
||||
// 10. 更新优惠券已领取数量(区分于已使用数量)
|
||||
if (coupon.getTotalQuantity() != null) {
|
||||
// 仅在有总量限制时才更新claimedQuantity(totalQuantity为正整数)
|
||||
if (coupon.getTotalQuantity() != null && coupon.getTotalQuantity() > 0) {
|
||||
int updatedClaimedQuantity = (coupon.getClaimedQuantity() == null ? 0 : coupon.getClaimedQuantity()) + 1;
|
||||
coupon.setClaimedQuantity(updatedClaimedQuantity);
|
||||
couponConfigMapper.updateById(coupon);
|
||||
|
||||
Reference in New Issue
Block a user