QueryFoodRecipes添加skuIDs参数

This commit is contained in:
gazebo
2019-11-06 17:16:35 +08:00
parent 5015620015
commit 5cc9787403
3 changed files with 19 additions and 7 deletions

View File

@@ -25,7 +25,7 @@ type FoodRecipeItemChoiceExt struct {
Comment string `json:"-"`
}
func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string, offset, pageSize int) (recipeList []*FoodRecipeWithAction, totalCount int, err error) {
func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID string, skuIDs []int, offset, pageSize int) (recipeList []*FoodRecipeWithAction, totalCount int, err error) {
var sql string
var sqlParams []interface{}
if userID != "" {
@@ -64,6 +64,14 @@ func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID
sql += " AND t1.author_id = ?"
sqlParams = append(sqlParams, authorID)
}
if len(skuIDs) > 0 {
sql += ` AND (
SELECT COUNT(*)
FROM food_recipe_item_choice t11
WHERE t11.recipe_id = t1.id AND t11.sku_id IN (` + GenQuestionMarks(len(skuIDs)) + `)
) > 0`
sqlParams = append(sqlParams, skuIDs)
}
offset = FormalizePageOffset(offset)
pageSize = FormalizePageSize(pageSize)
sql += `
@@ -80,7 +88,7 @@ func QueryFoodRecipes(db *DaoDB, keyword string, recipeID int, authorID, userID
}
func GetRecommendFoodRecipes(db *DaoDB, keyword, userID string, offset, pageSize int) (recipeList []*model.FoodRecipe, totalCount int, err error) {
list, totalCount, err := QueryFoodRecipes(db, keyword, 0, userID, "", offset, pageSize)
list, totalCount, err := QueryFoodRecipes(db, keyword, 0, userID, "", nil, offset, pageSize)
if err == nil {
recipeList = FoodRecipeWithActionList2Recipe(list)
}