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)
|
||||
}
|
||||
|
||||
@@ -291,15 +291,16 @@ func (c *JxOrderController) TestDefend() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param couponType query int false "优惠券类型,1为商品总额满减,2为运费优惠"
|
||||
// @Param couponStatuss query string false "优惠券状态,0为正常可使用,-1为已过期, -2为还没开始"
|
||||
// @Param storeIDs query string false "门店IDs"
|
||||
// @Param keyword query string false "关键字"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetCoupons [get]
|
||||
func (c *JxOrderController) GetCoupons() {
|
||||
c.callGetCoupons(func(params *tJxorderGetCouponsParams) (retVal interface{}, errCode string, err error) {
|
||||
var statuss []int
|
||||
if err = jxutils.Strings2Objs(params.CouponStatuss, &statuss); err == nil {
|
||||
retVal, err = localjx.GetCoupons(params.Ctx, params.CouponType, statuss, params.Keyword)
|
||||
var statuss, storeIDs []int
|
||||
if err = jxutils.Strings2Objs(params.CouponStatuss, &statuss, params.StoreIDs, &storeIDs); err == nil {
|
||||
retVal, err = localjx.GetCoupons(params.Ctx, params.CouponType, statuss, storeIDs, params.Keyword)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
@@ -309,15 +310,19 @@ func (c *JxOrderController) GetCoupons() {
|
||||
// @Description 添加优惠券
|
||||
// @Param token header string true "认证token"
|
||||
// @Param payload formData string true "优惠券类型 payload"
|
||||
// @Param count formData int true "优惠券数量,默认1"
|
||||
// @Param storeIDs formData string false "门店IDs"
|
||||
// @Param count formData int false "优惠券数量,默认1"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /AddCoupons [post]
|
||||
func (c *JxOrderController) AddCoupons() {
|
||||
c.callAddCoupons(func(params *tJxorderAddCouponsParams) (retVal interface{}, errCode string, err error) {
|
||||
coupons := &model.Coupons{}
|
||||
var storeIDs []int
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), coupons); err == nil {
|
||||
err = localjx.AddCoupons(params.Ctx, coupons, params.Count)
|
||||
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
|
||||
err = localjx.AddCoupons(params.Ctx, coupons, params.Count, storeIDs)
|
||||
}
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
|
||||
@@ -84,10 +84,12 @@ func Init() {
|
||||
orm.RegisterModel(&model.UserMember{})
|
||||
orm.RegisterModel(&model.OrderPay{}, &model.OrderPayRefund{})
|
||||
orm.RegisterModel(&model.UserOrderSms{})
|
||||
orm.RegisterModel(&model.FakeJdThingMap{})
|
||||
|
||||
//优惠券
|
||||
orm.RegisterModel(&model.Coupons{})
|
||||
orm.RegisterModel(&model.UserCoupons{})
|
||||
|
||||
orm.RegisterModel(&model.FakeJdThingMap{})
|
||||
orm.RegisterModel(&model.StoreCoupons{})
|
||||
|
||||
//权限
|
||||
orm.RegisterModel(&model.Role{})
|
||||
|
||||
Reference in New Issue
Block a user