aa
This commit is contained in:
@@ -1482,25 +1482,31 @@ func GetPriceDefendOrder(db *DaoDB, vendorOrderID string, storeIDs, skuIDs, issu
|
||||
return priceDefendOrders, err
|
||||
}
|
||||
|
||||
func GetCoupons(db *DaoDB, couponType int, couponStatuss []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
func GetCoupons(db *DaoDB, couponType int, couponStatuss, storeIDs []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM coupons
|
||||
WHERE deleted_at = ?
|
||||
SELECT DISTINCT a.*
|
||||
FROM coupons a
|
||||
LEFT JOIN store_coupons b ON a.id = b.coupon_id
|
||||
WHERE a.deleted_at = ?
|
||||
OR a.is_all = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, model.YES}
|
||||
if couponType != 0 {
|
||||
sql += " AND coupon_type = ?"
|
||||
sql += " AND a.coupon_type = ?"
|
||||
sqlParams = append(sqlParams, couponType)
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += " AND (name LIKE ? OR desc LIKE ?)"
|
||||
sql += " AND (a.name LIKE ? OR a.desc LIKE ?)"
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%")
|
||||
}
|
||||
if len(couponStatuss) > 0 {
|
||||
sql += " AND coupon_status IN (" + GenQuestionMarks(len(couponStatuss)) + ")"
|
||||
sql += " AND a.coupon_status IN (" + GenQuestionMarks(len(couponStatuss)) + ")"
|
||||
sqlParams = append(sqlParams, couponStatuss)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND b.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
err = GetRows(db, &coupons, sql, sqlParams)
|
||||
return coupons, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderDeliveryTypePlatform = "platform" // 平台负责配送
|
||||
@@ -429,15 +431,15 @@ func (v *PriceDefendOrder) TableIndex() [][]string {
|
||||
type Coupons struct {
|
||||
ModelIDCUL
|
||||
|
||||
CouponType int `json:"couponType"` //优惠券类型 ,1为总额满减, 2为运费优惠,
|
||||
Name string `json:"name"` //优惠券名字
|
||||
Desc string `json:"desc"` //优惠券详情描述
|
||||
BeginAt time.Time `json:"beginAt"` //开始时间
|
||||
EndAt time.Time `json:"endAt"` //到期时间
|
||||
UpperLimit int `json:"upperLimit"` //满多少
|
||||
Cut int `json:"cut"` //减多少
|
||||
StoreLimit string `orm:"type(text)" json:"storeLimit"` //门店限制:如100118,102919
|
||||
CouponStatus int `json:"couponStatus"` //优惠券状态,0为正常可使用,-1为已过期, -2为还没开始
|
||||
CouponType int `json:"couponType"` //优惠券类型 ,1为总额满减, 2为运费优惠,
|
||||
Name string `json:"name"` //优惠券名字
|
||||
Desc string `json:"desc"` //优惠券详情描述
|
||||
BeginAt time.Time `json:"beginAt"` //开始时间
|
||||
EndAt time.Time `json:"endAt"` //到期时间
|
||||
UpperLimit int `json:"upperLimit"` //满多少
|
||||
Cut int `json:"cut"` //减多少
|
||||
CouponStatus int `json:"couponStatus"` //优惠券状态,0为正常可使用,-1为已过期, -2为还没开始
|
||||
IsAll int `json:"isAll"` //是否全国有效,1是
|
||||
}
|
||||
|
||||
func (v *Coupons) TableIndex() [][]string {
|
||||
@@ -461,6 +463,19 @@ 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
|
||||
}
|
||||
|
||||
func (v *StoreCoupons) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"CouponID", "StoreID"},
|
||||
}
|
||||
}
|
||||
|
||||
// 判断是否是购买平台自有物流
|
||||
// 对于京东,饿百来说,就是其自有的物流,对于微商城来说,是达达
|
||||
func IsWaybillPlatformOwn(bill *Waybill) bool {
|
||||
|
||||
@@ -2149,11 +2149,11 @@ func GetMyPriceDefendOrders(ctx *jxcontext.Context, fromTime, toTime string) (pr
|
||||
return priceDefendOrders, err
|
||||
}
|
||||
|
||||
func GetCoupons(ctx *jxcontext.Context, couponType int, couponStatuss []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
func GetCoupons(ctx *jxcontext.Context, couponType int, couponStatuss, storeIDs []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
coupons, err = dao.GetCoupons(db, couponType, couponStatuss, keyword)
|
||||
coupons, err = dao.GetCoupons(db, couponType, couponStatuss, storeIDs, keyword)
|
||||
return coupons, err
|
||||
}
|
||||
|
||||
@@ -2182,7 +2182,10 @@ func AddCoupons(ctx *jxcontext.Context, coupons *model.Coupons, count int) (err
|
||||
if coupons.CouponType == 0 {
|
||||
return fmt.Errorf("请选择一个优惠券类型!")
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
if count == 0 {
|
||||
count += 1
|
||||
}
|
||||
for i := 1; i < count; i++ {
|
||||
dao.WrapAddIDCULDEntity(coupons, ctx.GetUserName())
|
||||
dao.CreateEntity(db, coupons)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user