aa
This commit is contained in:
@@ -1482,31 +1482,57 @@ func GetPriceDefendOrder(db *DaoDB, vendorOrderID string, storeIDs, skuIDs, issu
|
||||
return priceDefendOrders, err
|
||||
}
|
||||
|
||||
func GetCoupons(db *DaoDB, couponType int, couponStatuss, storeIDs []int, keyword string) (coupons []*model.Coupons, err error) {
|
||||
func GetCoupons(db *DaoDB, couponType int, couponStatuss, storeIDs []int, userID, mobile, keyword string) (coupons []*model.Coupons, err error) {
|
||||
sqlParams := []interface{}{}
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM coupons
|
||||
WHERE 1 = 1 AND is_all = ?
|
||||
SELECT DISTINCT a.*
|
||||
FROM coupons a
|
||||
`
|
||||
if userID != "" || mobile != "" {
|
||||
sql += " JOIN user_coupons b ON a.id = b.coupon_id"
|
||||
if userID != "" {
|
||||
sql += " AND b.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if mobile != "" {
|
||||
sql += " AND b.mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE a.is_all = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, 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)
|
||||
}
|
||||
sql +=
|
||||
`UNION
|
||||
sql += `
|
||||
UNION
|
||||
SELECT DISTINCT a.*
|
||||
FROM coupons a
|
||||
LEFT JOIN store_coupons b ON a.id = b.coupon_id AND b.deleted_at = ?
|
||||
`
|
||||
if userID != "" || mobile != "" {
|
||||
sql += " JOIN user_coupons c ON a.id = c.coupon_id"
|
||||
if userID != "" {
|
||||
sql += " AND c.user_id = ?"
|
||||
sqlParams = append(sqlParams, userID)
|
||||
}
|
||||
if mobile != "" {
|
||||
sql += " AND c.mobile = ?"
|
||||
sqlParams = append(sqlParams, mobile)
|
||||
}
|
||||
}
|
||||
sql += `
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
@@ -1545,5 +1571,33 @@ func GetStoreCoupons(db *DaoDB, couponIDs, storeIDs []int) (storeCoupons []*mode
|
||||
sql += " AND store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
err = GetRows(db, &storeCoupons, sql, sqlParams)
|
||||
return storeCoupons, err
|
||||
}
|
||||
|
||||
func GetUserCoupons(db *DaoDB, couponIDs []int, userIDs, mobiles []string, userStatus int) (userCoupons []*model.UserCoupons, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM user_coupons
|
||||
WHERE 1 = 1
|
||||
`
|
||||
sqlParams := []interface{}{}
|
||||
if len(couponIDs) > 0 {
|
||||
sql += " AND coupon_id IN (" + GenQuestionMarks(len(couponIDs)) + ")"
|
||||
sqlParams = append(sqlParams, couponIDs)
|
||||
}
|
||||
if len(userIDs) > 0 {
|
||||
sql += " AND user_id IN (" + GenQuestionMarks(len(userIDs)) + ")"
|
||||
sqlParams = append(sqlParams, userIDs)
|
||||
}
|
||||
if len(mobiles) > 0 {
|
||||
sql += " AND mobile IN (" + GenQuestionMarks(len(mobiles)) + ")"
|
||||
sqlParams = append(sqlParams, mobiles)
|
||||
}
|
||||
if userStatus != 0 {
|
||||
sql += " AND user_coupon_status = ?"
|
||||
sqlParams = append(sqlParams, userStatus)
|
||||
}
|
||||
err = GetRows(db, &userCoupons, sql, sqlParams)
|
||||
return userCoupons, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user