新增 检测优惠卷是否全部发放完毕

This commit is contained in:
wucongxing8150 2024-06-05 18:56:27 +08:00
parent ef5bd88106
commit 575c93bb73

View File

@ -519,7 +519,7 @@ func (r *CouponService) GrantSystemCoupon(couponId, adminUserId int64, req reque
} }
// 检测优惠卷可发放数量 // 检测优惠卷可发放数量
if req.TotalQuantity >= remainingQuantity { if req.TotalQuantity > remainingQuantity {
return false, errors.New("优惠卷数量不足,无法发放") return false, errors.New("优惠卷数量不足,无法发放")
} }
@ -588,6 +588,25 @@ func (r *CouponService) GrantSystemCoupon(couponId, adminUserId int64, req reque
} }
}() }()
// 增加优惠卷发放数量
err = couponDao.Inc(tx, couponId, "coupon_take_count", req.SingleQuantity)
if err != nil {
tx.Rollback()
return false, errors.New("发放失败")
}
// 检测优惠卷是否全部发放完毕
if (req.TotalQuantity - remainingQuantity) == 0 {
maps := make(map[string]interface{})
maps["coupon_status"] = 3
err := couponDao.EditCouponById(tx, coupon.CouponId, maps)
if err != nil {
tx.Rollback()
return false, errors.New("发放失败")
}
}
// 发放优惠卷
for i := 0; i < req.SingleQuantity; i++ { for i := 0; i < req.SingleQuantity; i++ {
// 添加用户优惠卷表 // 添加用户优惠卷表
UserCouponModel := &model.UserCoupon{ UserCouponModel := &model.UserCoupon{
@ -614,13 +633,6 @@ func (r *CouponService) GrantSystemCoupon(couponId, adminUserId int64, req reque
return false, errors.New("发放失败") return false, errors.New("发放失败")
} }
// 增加优惠卷发放数量
err = couponDao.Inc(tx, couponId, "coupon_take_count", 1)
if err != nil {
tx.Rollback()
return false, errors.New("发放失败")
}
// 添加弹窗表 // 添加弹窗表
if coupon.IsPopup == 1 { if coupon.IsPopup == 1 {
popupModel := &model.Popup{ popupModel := &model.Popup{