From 911f580bf63a17a95c1c2abd2123c33f89a9268c Mon Sep 17 00:00:00 2001 From: chenlin Date: Wed, 22 Jan 2025 17:21:33 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E7=8A=B6=E6=80=81=E4=B8=BA3=E6=97=B6=E6=9F=A5?= =?UTF-8?q?=E8=AF=A23/4=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=9B=202=E3=80=81?= =?UTF-8?q?=E6=96=B0=E6=9C=BA=E9=A2=84=E5=94=AE=E5=88=B8=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8F=91=E6=94=BE=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E6=97=B6=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=E5=8F=91=E8=B4=A7?= =?UTF-8?q?=E5=92=8C=E6=94=B6=E8=B4=A7=E6=97=B6=E9=97=B4=EF=BC=9B=203?= =?UTF-8?q?=E3=80=81=E8=B4=AD=E4=B9=B0=E4=B8=BB=E6=9C=BA=E9=A2=84=E5=94=AE?= =?UTF-8?q?=E5=88=B8=E4=B8=8D=E7=94=A8=E5=A1=AB=E5=86=99=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=EF=BC=9B=204=E3=80=81=E5=A2=9E=E5=8A=A0=E9=99=90=E5=88=B6?= =?UTF-8?q?=EF=BC=9A=E4=B8=80=E4=B8=AAID=E5=8F=AA=E8=83=BD=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=E4=B8=80=E5=BC=A0=E9=A2=84=E5=94=AE=E5=88=B8=EF=BC=9B?= =?UTF-8?q?=205=E3=80=81=E5=95=86=E5=9F=8E=E8=AE=A2=E5=8D=95=E9=80=80?= =?UTF-8?q?=E8=B4=A7=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=EF=BC=8C=E4=B8=BB?= =?UTF-8?q?=E6=9C=BA=E9=A2=84=E5=94=AE=E5=88=B8=E9=80=80=E8=B4=A7=E4=B8=8D?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=97=B6=E9=97=B4=EF=BC=8C=E5=8F=AA=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E4=BC=98=E6=83=A0=E5=88=B8=E6=98=AF=E5=90=A6=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=EF=BC=9B=206=E3=80=81=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E6=9C=BA=E4=BC=98=E6=83=A0=E5=88=B8=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/activity.go | 6 +++- controller/game_card.go | 4 +-- controller/mall.go | 70 ++++++++++++++++++++++++++++++++++------- lib/status/status.go | 16 +++++++--- model/coupon.go | 2 +- 5 files changed, 78 insertions(+), 20 deletions(-) diff --git a/controller/activity.go b/controller/activity.go index b88ddc0..1fbd26a 100644 --- a/controller/activity.go +++ b/controller/activity.go @@ -568,7 +568,11 @@ func MemberRenewalUserCouponList(c *gin.Context) { qs := model.NewUserCouponQuerySet(model.DB).UidEq(uc.Uid) if req.State != 0 { - qs = qs.StateEq(req.State) + if req.State == 3 { + qs = qs.StateIn(3, 4) + } else { + qs = qs.StateEq(req.State) + } } if req.ActivityId != 0 { qs = qs.ActivityIdEq(req.ActivityId) diff --git a/controller/game_card.go b/controller/game_card.go index ddb2e8b..9a43e19 100644 --- a/controller/game_card.go +++ b/controller/game_card.go @@ -976,7 +976,7 @@ func PushWXPayNotice(c *gin.Context) { if strings.Contains(goods.Name, "预售") { // 主机预售券,需要发放优惠券;默认为已收货 model.NewGoodsOrderQuerySet(model.DB).IDEq(goodsOrder.ID).GetUpdater(). - SetState(model.GoodsOrderStateReceived).Update() + SetState(model.GoodsOrderStateReceived).SetDeliverTime(time.Now()).SetReceivedTime(time.Now()).Update() var couponInfo model.Coupon err = model.NewCouponQuerySet(model.DB).ActivityIdEq(model.NewMachineActivityId).One(&couponInfo) @@ -2496,7 +2496,7 @@ func HmPushWXPayNotice(c *gin.Context) { if strings.Contains(goods.Name, "预售") { // 主机预售券,需要发放优惠券;默认为已收货 model.NewGoodsOrderQuerySet(model.DB).IDEq(goodsOrder.ID).GetUpdater(). - SetState(model.GoodsOrderStateReceived).Update() + SetState(model.GoodsOrderStateReceived).SetDeliverTime(time.Now()).SetReceivedTime(time.Now()).Update() var couponInfo model.Coupon err = model.NewCouponQuerySet(model.DB).ActivityIdEq(model.NewMachineActivityId).One(&couponInfo) diff --git a/controller/mall.go b/controller/mall.go index 37b3fae..3ea7153 100644 --- a/controller/mall.go +++ b/controller/mall.go @@ -211,7 +211,7 @@ func MallOrderCreate(c *gin.Context) { } // 如果不是发放优惠券,需要判断用户地址 - if !strings.Contains(goods.Name, "优惠券") { + if !(strings.Contains(goods.Name, "优惠券") || strings.Contains(goods.Name, "预售")) { // 检测收货地址是否正确 count, _ := model.NewUserAddressQuerySet(model.DB).UidEq(uc.Uid).IDEq(req.AddressId).Count() if count != 1 { @@ -221,6 +221,21 @@ func MallOrderCreate(c *gin.Context) { } } + // 判断是否已经购买或使用过新机预售券 + if strings.Contains(goods.Name, "预售") { + var newMachineCoupon model.UserCoupon + err = model.NewUserCouponQuerySet(model.DB).UidEq(user.Uid).ActivityIdEq(model.NewMachineActivityId). + One(&newMachineCoupon) + if err != nil { + log.Error().Msgf("query newMachineCoupon err:%#v, code is:", err, req.CouponCode) + } + + if newMachineCoupon.ID != 0 { + RespJson(c, status.OutOffCouponLimit, "一个ID只能购买一张预售券") + return + } + } + // 查找用户优惠券,判断是否可用 var userCoupon model.UserCoupon var coupon model.Coupon @@ -628,12 +643,41 @@ func MallOrderRefund(c *gin.Context) { RespJson(c, status.InternalServerError, nil) return } - if goodsOrder.CreatedAt.AddDate(0, 0, 15).Before(utils.Now()) || - (!goodsOrder.ReceivedTime.IsZero() && goodsOrder.ReceivedTime.AddDate(0, 0, 7).Before(utils.Now())) { - log.Error().Msg("goods order refund exceed the time limit") - RespJson(c, status.InternalServerError, nil) - return + if goodsOrder.Amount == 0 && goodsOrder.DeliverStoreId == 0 { // 新机预售券 + // 查询新机预售券状态,只有未使用才能退 + var newMachineCoupon model.UserCoupon + err = model.NewUserCouponQuerySet(model.DB).UidEq(goodsOrder.Uid).ActivityIdEq(model.NewMachineActivityId). + One(&newMachineCoupon) + if err != nil { + logger.Error(err) + RespJson(c, status.BadRequest, nil) + return + } + + switch newMachineCoupon.State { + case 2: + RespJson(c, status.NewMachineCouponUsed, nil) + return + case 3: + RespJson(c, status.NewMachineCouponOutOfTime, nil) + return + case 4: + RespJson(c, status.NewMachineCouponDisabled, nil) + return + default: + RespJson(c, status.BadRequest, nil) + return + } + + } else { + if goodsOrder.CreatedAt.AddDate(0, 0, 15).Before(utils.Now()) || + (!goodsOrder.ReceivedTime.IsZero() && goodsOrder.ReceivedTime.AddDate(0, 0, 7).Before(utils.Now())) { + log.Error().Msg("goods order refund exceed the time limit") + RespJson(c, status.InternalServerError, nil) + return + } } + if goodsOrder.State != model.GoodsOrderStateDelivered && goodsOrder.State != model.GoodsOrderStateReceived && goodsOrder.State != model.GoodsOrderStateRefundedCancel { @@ -641,13 +685,15 @@ func MallOrderRefund(c *gin.Context) { RespJson(c, status.OrderDelivered, nil) return } - store, err := model.GetStore(goodsOrder.DeliverStoreId) - if err != nil { - log.Error().Msgf("get store err:%#v", err) - RespJson(c, status.InternalServerError, nil) - return + if goodsOrder.DeliverStoreId != 0 { // 线上购买预售券时没有发货门店 + store, err := model.GetStore(goodsOrder.DeliverStoreId) + if err != nil { + log.Error().Msgf("get store err:%#v", err) + RespJson(c, status.InternalServerError, nil) + return + } + goodsOrder.DeliverStore = store } - goodsOrder.DeliverStore = store err = model.NewGoodsOrderQuerySet(model.DB).OrderIdEq(req.GoodsOrderId).GetUpdater(). SetRefundReason(req.RefundReason).SetState(model.GoodsOrderStateOnRefund).Update() if err != nil { diff --git a/lib/status/status.go b/lib/status/status.go index 1181d63..cc9fb49 100644 --- a/lib/status/status.go +++ b/lib/status/status.go @@ -116,6 +116,10 @@ const ( NotShopperCodeStoreUser = 500533 // 您不是推广门店用户,请扫店员推广码后再使用优惠券 NotAvailableCode = 500534 // 兑换码错误 NoSpecValue = 500535 // 优惠券未指定规格 + OutOffCouponLimit = 500536 // 超出限制:一个ID只能购买一张预售券 + NewMachineCouponUsed = 500537 // 新机预售券已使用 + NewMachineCouponOutOfTime = 500538 // 新机预售券已过期 + NewMachineCouponDisabled = 500539 // 新机预售券已失效 ToastErr = 600 // 报错 ) @@ -279,10 +283,14 @@ var statusMsg = map[int]string{ ThePhoneHasBeenRegistered: "该手机号已经注册账号", - NotNewUser: "您不是新用户,请领取续费优惠券", - NotShopperCodeStoreUser: "您不是推广门店用户,请扫店员推广码后再使用优惠券", - NotAvailableCode: "兑换码错误", - NoSpecValue: "优惠券未指定规格", + NotNewUser: "您不是新用户,请领取续费优惠券", + NotShopperCodeStoreUser: "您不是推广门店用户,请扫店员推广码后再使用优惠券", + NotAvailableCode: "兑换码错误", + NoSpecValue: "优惠券未指定规格", + OutOffCouponLimit: "超出限制:一个ID只能购买一张预售券", + NewMachineCouponUsed: "新机预售券已使用", + NewMachineCouponOutOfTime: "新机预售券已过期", + NewMachineCouponDisabled: "新机预售券已失效", } func StatusDesc(code int) string { diff --git a/model/coupon.go b/model/coupon.go index b638e44..df9a045 100644 --- a/model/coupon.go +++ b/model/coupon.go @@ -49,7 +49,7 @@ type UserCoupon struct { ActivityType uint32 `json:"activity_type"` // 活动类型 1-会员续费 2-关注公众号 3-运费包 ActivityId uint32 `json:"activity_id" gorm:"index"` // Value uint32 `json:"value"` // - State uint32 `json:"state"` // 1-未使用 2-已使用 3-已过期 + State uint32 `json:"state"` // 1-未使用 2-已使用 3-已过期 4-已失效 ActiveStart time.Time `json:"active_start"` // 有效期开始 ActiveEnd time.Time `json:"active_end"` // 有效期结束 零值永不结束 UseTime time.Time `json:"use_time"` //