1、修改查询优惠券列表接口,状态为3时查询3/4的数据;

2、新机预售券支付完成发放优惠券时同步更新发货和收货时间;
3、购买主机预售券不用填写地址;
4、增加限制:一个ID只能购买一张预售券;
5、商城订单退货增加判断,主机预售券退货不判断时间,只判断优惠券是否未使用;
6、增加新机优惠券对应错误码;
This commit is contained in:
chenlin 2025-01-22 17:21:33 +08:00
parent f3611088d5
commit 911f580bf6
5 changed files with 78 additions and 20 deletions

View File

@ -568,8 +568,12 @@ func MemberRenewalUserCouponList(c *gin.Context) {
qs := model.NewUserCouponQuerySet(model.DB).UidEq(uc.Uid)
if req.State != 0 {
if req.State == 3 {
qs = qs.StateIn(3, 4)
} else {
qs = qs.StateEq(req.State)
}
}
if req.ActivityId != 0 {
qs = qs.ActivityIdEq(req.ActivityId)
}

View File

@ -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)

View File

@ -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.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,6 +685,7 @@ func MallOrderRefund(c *gin.Context) {
RespJson(c, status.OrderDelivered, nil)
return
}
if goodsOrder.DeliverStoreId != 0 { // 线上购买预售券时没有发货门店
store, err := model.GetStore(goodsOrder.DeliverStoreId)
if err != nil {
log.Error().Msgf("get store err:%#v", err)
@ -648,6 +693,7 @@ func MallOrderRefund(c *gin.Context) {
return
}
goodsOrder.DeliverStore = store
}
err = model.NewGoodsOrderQuerySet(model.DB).OrderIdEq(req.GoodsOrderId).GetUpdater().
SetRefundReason(req.RefundReason).SetState(model.GoodsOrderStateOnRefund).Update()
if err != nil {

View File

@ -116,6 +116,10 @@ const (
NotShopperCodeStoreUser = 500533 // 您不是推广门店用户,请扫店员推广码后再使用优惠券
NotAvailableCode = 500534 // 兑换码错误
NoSpecValue = 500535 // 优惠券未指定规格
OutOffCouponLimit = 500536 // 超出限制一个ID只能购买一张预售券
NewMachineCouponUsed = 500537 // 新机预售券已使用
NewMachineCouponOutOfTime = 500538 // 新机预售券已过期
NewMachineCouponDisabled = 500539 // 新机预售券已失效
ToastErr = 600 // 报错
)
@ -283,6 +287,10 @@ var statusMsg = map[int]string{
NotShopperCodeStoreUser: "您不是推广门店用户,请扫店员推广码后再使用优惠券",
NotAvailableCode: "兑换码错误",
NoSpecValue: "优惠券未指定规格",
OutOffCouponLimit: "超出限制一个ID只能购买一张预售券",
NewMachineCouponUsed: "新机预售券已使用",
NewMachineCouponOutOfTime: "新机预售券已过期",
NewMachineCouponDisabled: "新机预售券已失效",
}
func StatusDesc(code int) string {

View File

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