diff --git a/business/model/order.go b/business/model/order.go index 6c6c70d40..be40c0b66 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -466,8 +466,8 @@ func (v *UserCoupons) TableIndex() [][]string { type StoreCoupons struct { ModelIDCULD - CouponID int `orm:"column(coupon_id)" json:"couponID"` //优惠券ID - StoreID string `orm:"column(store_id)" json:"storeID"` //storeID + CouponID int `orm:"column(coupon_id)" json:"couponID"` //优惠券ID + StoreID int `orm:"column(store_id)" json:"storeID"` //storeID } func (v *StoreCoupons) TableIndex() [][]string { diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index feabf611c..160f888d7 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -2172,6 +2172,13 @@ func AddCoupons(ctx *jxcontext.Context, coupons *model.Coupons, count int, store coupons.CouponStatus = model.CouponStatusRe } } + if coupons.IsAll == model.NO { + if len(storeIDs) == 0 { + return fmt.Errorf("不是全国生效则必须选择生效门店!") + } + } else { + storeIDs = []int{} //全国不需要选门店 + } if coupons.UpperLimit == 0 || coupons.Cut == 0 { return fmt.Errorf("请输入正确的满减!") } else { @@ -2187,7 +2194,19 @@ func AddCoupons(ctx *jxcontext.Context, coupons *model.Coupons, count int, store } for i := 1; i < count; i++ { dao.WrapAddIDCULDEntity(coupons, ctx.GetUserName()) - dao.CreateEntity(db, coupons) + if err = dao.CreateEntity(db, coupons); err == nil { + //门店优惠券表 + if coupons.IsAll == 0 { + for _, v := range storeIDs { + storeCoupons := &model.StoreCoupons{ + CouponID: int(coupons.ID), + StoreID: v, + } + dao.WrapAddIDCULEntity(storeCoupons, ctx.GetUserName()) + dao.CreateEntity(db, v) + } + } + } } return err }