+ GetEffectiveActStoreSkuInfo
This commit is contained in:
@@ -210,3 +210,55 @@ func QueryActs(db *DaoDB, actID int, offset, pageSize int, keyword string, statu
|
||||
}
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func GetEffectiveActStoreSkuInfo(db *DaoDB, actID int, vendorIDs, storeIDs, skuIDs []int, fromTime, toTime time.Time) (actStoreSkuList []*model.ActStoreSku2, err error) {
|
||||
if utils.IsTimeZero(fromTime) {
|
||||
return nil, fmt.Errorf("GeActStoreSkuInfo必须指定fromTime")
|
||||
}
|
||||
if utils.IsTimeZero(toTime) {
|
||||
toTime = fromTime
|
||||
}
|
||||
sql := `
|
||||
SELECT t2.*
|
||||
FROM`
|
||||
sqlParams := []interface{}{}
|
||||
if len(vendorIDs) > 0 {
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, vendorIDs, fromTime, toTime)
|
||||
actSQL := ""
|
||||
if actID > 0 {
|
||||
actSQL = " AND t11.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
sql += fmt.Sprintf(`
|
||||
(
|
||||
SELECT t11.id, t11.begin_at, t11.end_at, t11.status
|
||||
FROM act t11
|
||||
JOIN act_map t12 ON t12.act_id = t11.id AND t12.deleted_at = ? AND t12.vendor_id IN (`+GenQuestionMarks(len(vendorIDs))+`)
|
||||
WHERE t11.begin_at <= ? AND t11.end_at >= ? %s
|
||||
GROUP BY 1,2,3
|
||||
) t1`, actSQL)
|
||||
} else {
|
||||
sql += `
|
||||
act t1`
|
||||
}
|
||||
sql += `
|
||||
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
WHERE t1.status = ? AND t1.begin_at <= ? AND t1.end_at >= ?`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, model.ActStatusCreated, fromTime, toTime)
|
||||
if actID > 0 {
|
||||
sql = " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, actID)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND t2.store_id IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t2.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
err = GetRows(db, &actStoreSkuList, sql, sqlParams...)
|
||||
return actStoreSkuList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user