Compare commits
2 Commits
04090fba93
...
911f580bf6
Author | SHA1 | Date | |
---|---|---|---|
911f580bf6 | |||
f3611088d5 |
|
@ -568,7 +568,11 @@ func MemberRenewalUserCouponList(c *gin.Context) {
|
||||||
|
|
||||||
qs := model.NewUserCouponQuerySet(model.DB).UidEq(uc.Uid)
|
qs := model.NewUserCouponQuerySet(model.DB).UidEq(uc.Uid)
|
||||||
if req.State != 0 {
|
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 {
|
if req.ActivityId != 0 {
|
||||||
qs = qs.ActivityIdEq(req.ActivityId)
|
qs = qs.ActivityIdEq(req.ActivityId)
|
||||||
|
|
|
@ -976,7 +976,7 @@ func PushWXPayNotice(c *gin.Context) {
|
||||||
|
|
||||||
if strings.Contains(goods.Name, "预售") { // 主机预售券,需要发放优惠券;默认为已收货
|
if strings.Contains(goods.Name, "预售") { // 主机预售券,需要发放优惠券;默认为已收货
|
||||||
model.NewGoodsOrderQuerySet(model.DB).IDEq(goodsOrder.ID).GetUpdater().
|
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
|
var couponInfo model.Coupon
|
||||||
err = model.NewCouponQuerySet(model.DB).ActivityIdEq(model.NewMachineActivityId).One(&couponInfo)
|
err = model.NewCouponQuerySet(model.DB).ActivityIdEq(model.NewMachineActivityId).One(&couponInfo)
|
||||||
|
@ -986,6 +986,13 @@ func PushWXPayNotice(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var couponValue uint32
|
||||||
|
if couponInfo.Value != 0 { // 如果预售券金额为0,则发放时抵扣金额=支付金额;否则=预售券金额
|
||||||
|
couponValue = couponInfo.Value
|
||||||
|
} else {
|
||||||
|
couponValue = uint32(notifyInfo.TotalFee)
|
||||||
|
}
|
||||||
|
|
||||||
couponCode, err := utils.GenerateRandomNumber19()
|
couponCode, err := utils.GenerateRandomNumber19()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("GenerateRandomNumber19err:", err)
|
logger.Error("GenerateRandomNumber19err:", err)
|
||||||
|
@ -996,7 +1003,7 @@ func PushWXPayNotice(c *gin.Context) {
|
||||||
CouponType: couponInfo.CouponType,
|
CouponType: couponInfo.CouponType,
|
||||||
ActivityType: couponInfo.ActivityType,
|
ActivityType: couponInfo.ActivityType,
|
||||||
ActivityId: couponInfo.ActivityId,
|
ActivityId: couponInfo.ActivityId,
|
||||||
Value: uint32(notifyInfo.TotalFee),
|
Value: couponValue,
|
||||||
State: 1,
|
State: 1,
|
||||||
ActiveStart: time.Now(),
|
ActiveStart: time.Now(),
|
||||||
ActiveEnd: time.Now().AddDate(0, 0, 180),
|
ActiveEnd: time.Now().AddDate(0, 0, 180),
|
||||||
|
@ -2489,7 +2496,7 @@ func HmPushWXPayNotice(c *gin.Context) {
|
||||||
|
|
||||||
if strings.Contains(goods.Name, "预售") { // 主机预售券,需要发放优惠券;默认为已收货
|
if strings.Contains(goods.Name, "预售") { // 主机预售券,需要发放优惠券;默认为已收货
|
||||||
model.NewGoodsOrderQuerySet(model.DB).IDEq(goodsOrder.ID).GetUpdater().
|
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
|
var couponInfo model.Coupon
|
||||||
err = model.NewCouponQuerySet(model.DB).ActivityIdEq(model.NewMachineActivityId).One(&couponInfo)
|
err = model.NewCouponQuerySet(model.DB).ActivityIdEq(model.NewMachineActivityId).One(&couponInfo)
|
||||||
|
@ -2499,6 +2506,13 @@ func HmPushWXPayNotice(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var couponValue uint32
|
||||||
|
if couponInfo.Value != 0 { // 如果预售券金额为0,则发放时抵扣金额=支付金额;否则=预售券金额
|
||||||
|
couponValue = couponInfo.Value
|
||||||
|
} else {
|
||||||
|
couponValue = uint32(fundRecord.Amount)
|
||||||
|
}
|
||||||
|
|
||||||
couponCode, err := utils.GenerateRandomNumber19()
|
couponCode, err := utils.GenerateRandomNumber19()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("GenerateRandomNumber19err:", err)
|
logger.Error("GenerateRandomNumber19err:", err)
|
||||||
|
@ -2509,7 +2523,7 @@ func HmPushWXPayNotice(c *gin.Context) {
|
||||||
CouponType: couponInfo.CouponType,
|
CouponType: couponInfo.CouponType,
|
||||||
ActivityType: couponInfo.ActivityType,
|
ActivityType: couponInfo.ActivityType,
|
||||||
ActivityId: couponInfo.ActivityId,
|
ActivityId: couponInfo.ActivityId,
|
||||||
Value: uint32(fundRecord.Amount),
|
Value: couponValue,
|
||||||
State: 1,
|
State: 1,
|
||||||
ActiveStart: time.Now(),
|
ActiveStart: time.Now(),
|
||||||
ActiveEnd: time.Now().AddDate(0, 0, 180),
|
ActiveEnd: time.Now().AddDate(0, 0, 180),
|
||||||
|
|
|
@ -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()
|
count, _ := model.NewUserAddressQuerySet(model.DB).UidEq(uc.Uid).IDEq(req.AddressId).Count()
|
||||||
if count != 1 {
|
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 userCoupon model.UserCoupon
|
||||||
var coupon model.Coupon
|
var coupon model.Coupon
|
||||||
|
@ -628,12 +643,41 @@ func MallOrderRefund(c *gin.Context) {
|
||||||
RespJson(c, status.InternalServerError, nil)
|
RespJson(c, status.InternalServerError, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if goodsOrder.CreatedAt.AddDate(0, 0, 15).Before(utils.Now()) ||
|
if goodsOrder.Amount == 0 && goodsOrder.DeliverStoreId == 0 { // 新机预售券
|
||||||
(!goodsOrder.ReceivedTime.IsZero() && goodsOrder.ReceivedTime.AddDate(0, 0, 7).Before(utils.Now())) {
|
// 查询新机预售券状态,只有未使用才能退
|
||||||
log.Error().Msg("goods order refund exceed the time limit")
|
var newMachineCoupon model.UserCoupon
|
||||||
RespJson(c, status.InternalServerError, nil)
|
err = model.NewUserCouponQuerySet(model.DB).UidEq(goodsOrder.Uid).ActivityIdEq(model.NewMachineActivityId).
|
||||||
return
|
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 &&
|
if goodsOrder.State != model.GoodsOrderStateDelivered &&
|
||||||
goodsOrder.State != model.GoodsOrderStateReceived &&
|
goodsOrder.State != model.GoodsOrderStateReceived &&
|
||||||
goodsOrder.State != model.GoodsOrderStateRefundedCancel {
|
goodsOrder.State != model.GoodsOrderStateRefundedCancel {
|
||||||
|
@ -641,13 +685,15 @@ func MallOrderRefund(c *gin.Context) {
|
||||||
RespJson(c, status.OrderDelivered, nil)
|
RespJson(c, status.OrderDelivered, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
store, err := model.GetStore(goodsOrder.DeliverStoreId)
|
if goodsOrder.DeliverStoreId != 0 { // 线上购买预售券时没有发货门店
|
||||||
if err != nil {
|
store, err := model.GetStore(goodsOrder.DeliverStoreId)
|
||||||
log.Error().Msgf("get store err:%#v", err)
|
if err != nil {
|
||||||
RespJson(c, status.InternalServerError, nil)
|
log.Error().Msgf("get store err:%#v", err)
|
||||||
return
|
RespJson(c, status.InternalServerError, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
goodsOrder.DeliverStore = store
|
||||||
}
|
}
|
||||||
goodsOrder.DeliverStore = store
|
|
||||||
err = model.NewGoodsOrderQuerySet(model.DB).OrderIdEq(req.GoodsOrderId).GetUpdater().
|
err = model.NewGoodsOrderQuerySet(model.DB).OrderIdEq(req.GoodsOrderId).GetUpdater().
|
||||||
SetRefundReason(req.RefundReason).SetState(model.GoodsOrderStateOnRefund).Update()
|
SetRefundReason(req.RefundReason).SetState(model.GoodsOrderStateOnRefund).Update()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -116,6 +116,10 @@ const (
|
||||||
NotShopperCodeStoreUser = 500533 // 您不是推广门店用户,请扫店员推广码后再使用优惠券
|
NotShopperCodeStoreUser = 500533 // 您不是推广门店用户,请扫店员推广码后再使用优惠券
|
||||||
NotAvailableCode = 500534 // 兑换码错误
|
NotAvailableCode = 500534 // 兑换码错误
|
||||||
NoSpecValue = 500535 // 优惠券未指定规格
|
NoSpecValue = 500535 // 优惠券未指定规格
|
||||||
|
OutOffCouponLimit = 500536 // 超出限制:一个ID只能购买一张预售券
|
||||||
|
NewMachineCouponUsed = 500537 // 新机预售券已使用
|
||||||
|
NewMachineCouponOutOfTime = 500538 // 新机预售券已过期
|
||||||
|
NewMachineCouponDisabled = 500539 // 新机预售券已失效
|
||||||
|
|
||||||
ToastErr = 600 // 报错
|
ToastErr = 600 // 报错
|
||||||
)
|
)
|
||||||
|
@ -279,10 +283,14 @@ var statusMsg = map[int]string{
|
||||||
|
|
||||||
ThePhoneHasBeenRegistered: "该手机号已经注册账号",
|
ThePhoneHasBeenRegistered: "该手机号已经注册账号",
|
||||||
|
|
||||||
NotNewUser: "您不是新用户,请领取续费优惠券",
|
NotNewUser: "您不是新用户,请领取续费优惠券",
|
||||||
NotShopperCodeStoreUser: "您不是推广门店用户,请扫店员推广码后再使用优惠券",
|
NotShopperCodeStoreUser: "您不是推广门店用户,请扫店员推广码后再使用优惠券",
|
||||||
NotAvailableCode: "兑换码错误",
|
NotAvailableCode: "兑换码错误",
|
||||||
NoSpecValue: "优惠券未指定规格",
|
NoSpecValue: "优惠券未指定规格",
|
||||||
|
OutOffCouponLimit: "超出限制:一个ID只能购买一张预售券",
|
||||||
|
NewMachineCouponUsed: "新机预售券已使用",
|
||||||
|
NewMachineCouponOutOfTime: "新机预售券已过期",
|
||||||
|
NewMachineCouponDisabled: "新机预售券已失效",
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatusDesc(code int) string {
|
func StatusDesc(code int) string {
|
||||||
|
|
|
@ -34,6 +34,7 @@ type Coupon struct {
|
||||||
MemberLevel uint32 `json:"member_level"` // 会员等级 1-用户 2-会员
|
MemberLevel uint32 `json:"member_level"` // 会员等级 1-用户 2-会员
|
||||||
CategoryNumber string `json:"category_number"` // 可以使用该优惠券的商品分类,如果为空则表示没限制
|
CategoryNumber string `json:"category_number"` // 可以使用该优惠券的商品分类,如果为空则表示没限制
|
||||||
CommodityNumber string `json:"commodity_number"` // 可以使用该优惠券的商品编号,如果为空则表示没限制
|
CommodityNumber string `json:"commodity_number"` // 可以使用该优惠券的商品编号,如果为空则表示没限制
|
||||||
|
Limit uint32 `json:"limit"` // 优惠券叠加限制 0-不限制;1-仅限原价购买时使用
|
||||||
IsDraw bool `json:"is_draw" gorm:"-"` //
|
IsDraw bool `json:"is_draw" gorm:"-"` //
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ type UserCoupon struct {
|
||||||
ActivityType uint32 `json:"activity_type"` // 活动类型 1-会员续费 2-关注公众号 3-运费包
|
ActivityType uint32 `json:"activity_type"` // 活动类型 1-会员续费 2-关注公众号 3-运费包
|
||||||
ActivityId uint32 `json:"activity_id" gorm:"index"` //
|
ActivityId uint32 `json:"activity_id" gorm:"index"` //
|
||||||
Value uint32 `json:"value"` //
|
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"` // 有效期开始
|
ActiveStart time.Time `json:"active_start"` // 有效期开始
|
||||||
ActiveEnd time.Time `json:"active_end"` // 有效期结束 零值永不结束
|
ActiveEnd time.Time `json:"active_end"` // 有效期结束 零值永不结束
|
||||||
UseTime time.Time `json:"use_time"` //
|
UseTime time.Time `json:"use_time"` //
|
||||||
|
@ -59,7 +60,8 @@ type UserCoupon struct {
|
||||||
CategoryNumber string `json:"category_number"` // 可以使用该优惠券的商品分类,如果为空则表示没限制
|
CategoryNumber string `json:"category_number"` // 可以使用该优惠券的商品分类,如果为空则表示没限制
|
||||||
CommodityNumber string `json:"commodity_number"` // 可以使用该优惠券的商品编号,如果为空则表示没限制
|
CommodityNumber string `json:"commodity_number"` // 可以使用该优惠券的商品编号,如果为空则表示没限制
|
||||||
Code string `json:"code"` // 优惠券券码
|
Code string `json:"code"` // 优惠券券码
|
||||||
StoreId uint32 `json:"store_id" gorm:"-"` // 邀请码对应门店id
|
Limit uint32 `json:"limit"` // 优惠券叠加限制 0-不限制;1-仅限原价购买时使用
|
||||||
|
StoreId uint32 `json:"store_id" gorm:"-"` // 邀请码对应门店id
|
||||||
Availability uint32 `json:"availability" gorm:"-"` // 1-不可用 2-可用
|
Availability uint32 `json:"availability" gorm:"-"` // 1-不可用 2-可用
|
||||||
Coupon *Coupon `json:"coupon" gorm:"-"`
|
Coupon *Coupon `json:"coupon" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user