From b6d99cda23869f262f32e673ae0940b68ac9cfb7 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 17 Jun 2024 11:26:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=8D=B7=E6=98=AF=E5=90=A6=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E5=8F=91=E6=94=BE=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dao/coupon.go | 9 +++++++++ api/service/v1/Coupon.go | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/api/dao/coupon.go b/api/dao/coupon.go index 9c6d4fe..53899e1 100644 --- a/api/dao/coupon.go +++ b/api/dao/coupon.go @@ -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 +} diff --git a/api/service/v1/Coupon.go b/api/service/v1/Coupon.go index 7ed62c3..c36473a 100644 --- a/api/service/v1/Coupon.go +++ b/api/service/v1/Coupon.go @@ -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{