新增 检测优惠卷是否全部发放完毕
This commit is contained in:
parent
7af51c49ce
commit
b6d99cda23
@ -80,3 +80,12 @@ func (r *CouponDao) Dec(tx *gorm.DB, couponId int64, field string, numeral int)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditCouponById 修改
|
||||
func (r *CouponDao) EditCouponById(tx *gorm.DB, couponId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Coupon{}).Where("coupon_id = ?", couponId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -180,6 +180,17 @@ func (r *CouponService) ReceiveCoupon(req requestsV1.ReceiveCoupon) (g *dtoV1.Re
|
||||
return nil, errors.New("发放失败")
|
||||
}
|
||||
|
||||
// 检测优惠卷是否全部发放完毕
|
||||
if (req.Quantity - remainingQuantity) == 0 {
|
||||
maps := make(map[string]interface{})
|
||||
maps["coupon_status"] = 3
|
||||
err := couponDao.EditCouponById(tx, coupon.CouponId, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return nil, errors.New("发放失败")
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < req.Quantity; i++ {
|
||||
// 添加用户优惠卷表
|
||||
UserCouponModel := &model.UserCoupon{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user