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"` //