QueryFoodRecipes添加skuIDs参数
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -200,9 +200,9 @@ func tryRegisterDataRes4Recipe(ctx *jxcontext.Context, name, mainImg string, ste
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func QueryFoodRecipes(ctx *jxcontext.Context, keyword, authorID string, offset, pageSize int) (recipeInfo *model.PagedInfo, err error) {
|
||||
func QueryFoodRecipes(ctx *jxcontext.Context, keyword, authorID string, skuIDs []int, offset, pageSize int) (recipeInfo *model.PagedInfo, err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
recipeList, totalCount, err := dao.QueryFoodRecipes(dao.GetDB(), keyword, 0, authorID, userID, offset, pageSize)
|
||||
recipeList, totalCount, err := dao.QueryFoodRecipes(dao.GetDB(), keyword, 0, authorID, userID, skuIDs, offset, pageSize)
|
||||
if err == nil {
|
||||
recipeInfo = &model.PagedInfo{
|
||||
TotalCount: totalCount,
|
||||
@@ -227,7 +227,7 @@ func GetRecommendFoodRecipes(ctx *jxcontext.Context, keyword string, offset, pag
|
||||
func GetRecipeDetail(ctx *jxcontext.Context, recipeID int) (recipeDetail *FoodRecipeDetail, err error) {
|
||||
_, userID := ctx.GetMobileAndUserID()
|
||||
db := dao.GetDB()
|
||||
recipeList, _, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID, 0, 0)
|
||||
recipeList, _, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID, nil, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -275,7 +275,7 @@ func VoteFoodRecipe(ctx *jxcontext.Context, recipeID, voteType int) (err error)
|
||||
}
|
||||
|
||||
db := dao.GetDB()
|
||||
recipeList, _, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID, 0, 0)
|
||||
recipeList, _, err := dao.QueryFoodRecipes(db, "", recipeID, "", userID, nil, 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ func (c *FoodRecipeController) UpdateFoodRecipe() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param keyword query string false "关键字"
|
||||
// @Param authorID query string false "创建者ID"
|
||||
// @Param skuIDs query string false "skuID列表"
|
||||
// @Param offset query int false "菜谱列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "菜谱列表页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
@@ -82,7 +83,10 @@ func (c *FoodRecipeController) UpdateFoodRecipe() {
|
||||
// @router /QueryFoodRecipes [get]
|
||||
func (c *FoodRecipeController) QueryFoodRecipes() {
|
||||
c.callQueryFoodRecipes(func(params *tFoodrecipeQueryFoodRecipesParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = userstore.QueryFoodRecipes(params.Ctx, params.Keyword, params.AuthorID, params.Offset, params.PageSize)
|
||||
var skuIDs []int
|
||||
if err = jxutils.Strings2Objs(params.SkuIDs, &skuIDs); err == nil {
|
||||
retVal, err = userstore.QueryFoodRecipes(params.Ctx, params.Keyword, params.AuthorID, skuIDs, params.Offset, params.PageSize)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user