aa
This commit is contained in:
@@ -42,6 +42,9 @@ const (
|
|||||||
CouponStatusOverdue = -1 //已过期
|
CouponStatusOverdue = -1 //已过期
|
||||||
CouponStatusNormal = 0 //正常
|
CouponStatusNormal = 0 //正常
|
||||||
CouponStatusDeleted = -4 //被删了
|
CouponStatusDeleted = -4 //被删了
|
||||||
|
|
||||||
|
CouponTypeDiscount = 1 //优惠券类型,总额满减
|
||||||
|
CouponTypeDelivery = 2 //运费优惠
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -143,6 +146,7 @@ type GoodsOrder struct {
|
|||||||
EarningType int `json:"earningType"` //订单结算方式,2为扣点,1为报价
|
EarningType int `json:"earningType"` //订单结算方式,2为扣点,1为报价
|
||||||
OrderType int `json:"orderType"` //订单类型,0为普通订单,1为物料订单,2为进货订单
|
OrderType int `json:"orderType"` //订单类型,0为普通订单,1为物料订单,2为进货订单
|
||||||
OrderPayPercentage int `json:"orderPayPercentage"`
|
OrderPayPercentage int `json:"orderPayPercentage"`
|
||||||
|
CouponIDs string `orm:"column(coupon_ids)" json:"couponIDs"` //优惠券IDs(京西商城)
|
||||||
|
|
||||||
// 以下只是用于传递数据
|
// 以下只是用于传递数据
|
||||||
OriginalData string `orm:"-" json:"-"`
|
OriginalData string `orm:"-" json:"-"`
|
||||||
|
|||||||
@@ -611,7 +611,6 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
|||||||
if distance := jxutils.Point2StoreDistance(deliveryAddress.Lng, deliveryAddress.Lat, storeDetail.Lng, storeDetail.Lat, storeDetail.DeliveryRangeType, storeDetail.DeliveryRange); distance == 0 {
|
if distance := jxutils.Point2StoreDistance(deliveryAddress.Lng, deliveryAddress.Lat, storeDetail.Lng, storeDetail.Lat, storeDetail.DeliveryRangeType, storeDetail.DeliveryRange); distance == 0 {
|
||||||
return nil, nil, fmt.Errorf("当前送货地址不在门店%s的配送范围", storeDetail.Name)
|
return nil, nil, fmt.Errorf("当前送货地址不在门店%s的配送范围", storeDetail.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//结算类型
|
//结算类型
|
||||||
if storeDetail.PayPercentage < 50 {
|
if storeDetail.PayPercentage < 50 {
|
||||||
jxOrder.EarningType = model.EarningTypePoints
|
jxOrder.EarningType = model.EarningTypePoints
|
||||||
@@ -922,7 +921,6 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
if jxOrder.OrderType == model.OrderTypeNormal {
|
if jxOrder.OrderType == model.OrderTypeNormal {
|
||||||
outJxOrder.TotalPrice = outJxOrder.OrderPrice + outJxOrder.FreightPrice
|
outJxOrder.TotalPrice = outJxOrder.OrderPrice + outJxOrder.FreightPrice
|
||||||
// 判断用户是否是会员
|
|
||||||
var (
|
var (
|
||||||
tuserID string
|
tuserID string
|
||||||
dicountCards []*model.DiscountCard
|
dicountCards []*model.DiscountCard
|
||||||
@@ -932,6 +930,46 @@ func generateOrder(ctx *jxcontext.Context, jxOrder *JxOrderInfo, addressID int64
|
|||||||
} else {
|
} else {
|
||||||
tuserID = userID
|
tuserID = userID
|
||||||
}
|
}
|
||||||
|
// 1.先扣除优惠券
|
||||||
|
if len(couponIDs) > 0 {
|
||||||
|
if userCoupons, err := dao.GetUserCoupons(db, couponIDs, []string{tuserID}, nil, model.CouponStatusNormal); err == nil {
|
||||||
|
if len(userCoupons) != len(couponIDs) {
|
||||||
|
return nil, nil, fmt.Errorf("选择的优惠券状态不正常,请刷新后重试!")
|
||||||
|
}
|
||||||
|
for _, v := range userCoupons {
|
||||||
|
coupon := &model.Coupons{}
|
||||||
|
coupon.ID = int64(v.CouponID)
|
||||||
|
if err = dao.GetEntity(db, coupon); err == nil && coupon.Name != "" {
|
||||||
|
checkPrice := func(price int64) (rPrice int64, err error) {
|
||||||
|
priceInt := int(price)
|
||||||
|
if priceInt < coupon.UpperLimit {
|
||||||
|
return 0, fmt.Errorf("抱歉,该订单价格未达到此优惠券[%v]满减额度!", coupon.Name)
|
||||||
|
}
|
||||||
|
if priceInt <= coupon.Cut {
|
||||||
|
rPrice = 0
|
||||||
|
} else {
|
||||||
|
rPrice = int64(priceInt - coupon.Cut)
|
||||||
|
}
|
||||||
|
return rPrice, err
|
||||||
|
}
|
||||||
|
switch coupon.CouponType {
|
||||||
|
case model.CouponTypeDiscount:
|
||||||
|
outJxOrder.OrderPrice, err = checkPrice(outJxOrder.OrderPrice)
|
||||||
|
case model.CouponTypeDelivery:
|
||||||
|
outJxOrder.FreightPrice, err = checkPrice(outJxOrder.FreightPrice)
|
||||||
|
default:
|
||||||
|
return nil, nil, fmt.Errorf("暂不支持的优惠券类型![%v]", coupon.CouponType)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2.判断用户是否是会员
|
||||||
userMembers, _ := dao.GetUserMember(db, tuserID, "", model.MemberTypeDiscountCard, model.YES)
|
userMembers, _ := dao.GetUserMember(db, tuserID, "", model.MemberTypeDiscountCard, model.YES)
|
||||||
if len(userMembers) > 0 {
|
if len(userMembers) > 0 {
|
||||||
if configList, err := dao.QueryConfigs(db, "会员折扣卡", model.ConfigTypeDiscountCard, ""); err == nil {
|
if configList, err := dao.QueryConfigs(db, "会员折扣卡", model.ConfigTypeDiscountCard, ""); err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user