Merge pull request '添加返回数据' (#21) from test into master

Reviewed-on: https://git.oa00.com/recook/backend_v2/pulls/21
master
杨赟 3 years ago
commit 3b2efae0f6

@ -107,13 +107,20 @@ func QueryGoodsListByComprehension(c *gin.Context) {
Expression: clause.Expr{SQL: "FIELD(id,?)", Vars: []interface{}{ids}, WithoutParentheses: true}})
q3 = q3.Where("id in (?) and sale_publish = 1 and is_sale = 1", ids)
}
findByKeyWord(q3, p.Keyword, &goodsList, p.Page, p.IsSale, false)
filters := map[string]interface{}{}
if p.SecondCategoryID > 0 {
filters["brand_id"] = p.BrandID
}
if p.SecondCategoryID > 0 {
filters["second_category_id"] = p.SecondCategoryID
}
findByKeyWord(q3, p.Keyword, filters, &goodsList, p.Page, p.IsSale, false)
back.Suc(c, "", GetGoodsRespByInfoList(goodsList, p.UserId, p.IsSale))
}
func findByKeyWord(q *gorm2.DB, str string, data *[]goods.Information, page uint, isSale bool, isCondition bool) {
func findByKeyWord(q *gorm2.DB, str string, filters map[string]interface{}, data *[]goods.Information, page uint, isSale bool, isCondition bool) {
if str != "" {
gl, _, _ := search_ali.SearchByAliES(str, isSale, 20, int(page))
gl, _, _ := search_ali.SearchByAliES(str, filters, isSale, 20, int(page))
q = q.Where("a.id in (?)", gl)
if !isCondition {
q = q.Clauses(clause.OrderBy{
@ -167,7 +174,14 @@ func QueryGoodsListBySalesVolume(c *gin.Context) {
sub := mysql2.Db.Table((&ac2.ActivityGoods{}).TableName()).Select("goods_id").Where("activity_id = ?", p.ActivityID)
q3 = q3.Where("id in (?) and sale_publish = 1 and is_sale = 1", sub)
}
findByKeyWord(q3, p.Keyword, &goodsList, p.Page, p.IsSale, true)
filters := map[string]interface{}{}
if p.SecondCategoryID > 0 {
filters["brand_id"] = p.BrandID
}
if p.SecondCategoryID > 0 {
filters["second_category_id"] = p.SecondCategoryID
}
findByKeyWord(q3, p.Keyword, filters, &goodsList, p.Page, p.IsSale, true)
back.Suc(c, "", GetGoodsRespByInfoList(goodsList, p.UserId, p.IsSale))
}
@ -204,7 +218,14 @@ func QueryGoodsListByDiscountPrice(c *gin.Context) {
q3 = q3.Where("id in (?) and sale_publish = 1 and is_sale= 1", sub)
}
findByKeyWord(q3, p.Keyword, &goodsList, p.Page, p.IsSale, true)
filters := map[string]interface{}{}
if p.SecondCategoryID > 0 {
filters["brand_id"] = p.BrandID
}
if p.SecondCategoryID > 0 {
filters["second_category_id"] = p.SecondCategoryID
}
findByKeyWord(q3, p.Keyword, filters, &goodsList, p.Page, p.IsSale, true)
back.Suc(c, "", GetGoodsRespByInfoList(goodsList, p.UserId, p.IsSale))
}

@ -139,7 +139,7 @@ func PushMessage() {
}
func SearchByAliES(keyWords string, isSale bool, limit, page int) (goodsList []uint, total uint, err error) {
func SearchByAliES(keyWords string, filters map[string]interface{}, isSale bool, limit, page int) (goodsList []uint, total uint, err error) {
// 创建请求用客户端实例
// Endpoint 为 要访问服务的区域域名.
// AccessKeyId 及AccessKeySecret 用于构造鉴权信息.
@ -162,6 +162,9 @@ func SearchByAliES(keyWords string, isSale bool, limit, page int) (goodsList []u
if isSale {
query = fmt.Sprintf("config=start:%v,hit:%v,format:fulljson&&query=default:'%s'&&filter=sale_publish=1", limit*(page), limit, keyWords)
}
for key, value := range filters {
query += fmt.Sprintf(" AND %s=%v", key, value)
}
// requestParams 信息
requestParams := map[string]interface{}{
"query": query,

Loading…
Cancel
Save