+store/sku/GetStoreCategories

This commit is contained in:
gazebo
2019-12-16 18:05:26 +08:00
parent 7296b5cca3
commit b0cd64a358
5 changed files with 72 additions and 1 deletions

View File

@@ -63,7 +63,7 @@ func GetCategories(db *DaoDB, parentID, level int, catIDs []int) (cats []*model.
params = append(params, parentID)
}
if len(catIDs) > 0 {
sql += " AND t1.id (" + GenQuestionMarks(len(catIDs)) + ")"
sql += " AND t1.id IN (" + GenQuestionMarks(len(catIDs)) + ")"
params = append(params, catIDs)
}
if level > 0 {

View File

@@ -1028,6 +1028,46 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCategor
return skuCategory, err
}
func GetStoreSkuCategories(db *DaoDB, storeID, parentID int) (catList []*model.SkuCategory, err error) {
sql := `
SELECT
t1.*
FROM sku_category t1
JOIN
(
SELECT DISTINCT t3.category_id
FROM store_sku_bind t1
JOIN sku t2 ON t2.id = t1.sku_id AND t2.deleted_at = ? AND t2.status = ?
JOIN sku_name t3 ON t3.id = t2.name_id AND t3.deleted_at = ? AND t3.status = ?
WHERE t1.deleted_at = ? AND t1.status = ? AND t1.store_id = ?
) t2 ON t2.category_id = t1.id
WHERE t1.deleted_at = ?`
sqlParams := []interface{}{
utils.DefaultTimeValue, model.SkuStatusNormal,
utils.DefaultTimeValue, model.SkuStatusNormal,
utils.DefaultTimeValue, model.SkuStatusNormal, storeID,
utils.DefaultTimeValue,
}
if parentID >= 0 {
sql += " AND t1.parent_id = ?"
sqlParams = append(sqlParams, parentID)
}
sql += " ORDER BY t1.level, t1.seq"
if err = GetRows(db, &catList, sql, sqlParams...); err == nil && len(catList) > 0 {
parentIDMap := make(map[int]int)
for _, v := range catList {
parentIDMap[v.ParentID] = 1
}
paretnCats, err2 := GetCategories(db, -1, 0, jxutils.IntMap2List(parentIDMap))
if err = err2; err == nil {
catList = append(catList, paretnCats...)
} else {
catList = nil
}
}
return catList, err
}
func RefershStoreSkusMidPrice(db *DaoDB, storeIDs []int) (count int64, err error) {
sql := `
UPDATE store_sku_bind a