Commit 97fc5f98 by mushishixian

修复

parent 79a113ea
[web]
port = 9000
port = 9001
mode = debug
cors_domain = http://bom.liexin.com
......
......@@ -11,6 +11,7 @@ func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
corsDomain = append(corsDomain, "http://footstone.liexin.net")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
......
......@@ -22,6 +22,12 @@ type BomResponse struct {
Data interface{} `json:"data"`
}
type RecommendResponse struct {
Flag int `json:"flag"`
Total int `json:"total"`
Data interface{} `json:"data"`
}
func SuccessResponse(errCode int, errMsg string, data interface{}) Response {
return Response{
ErrCode: errCode,
......
......@@ -7,7 +7,6 @@ import (
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
......@@ -66,7 +65,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
}
//推荐商品搜索
func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model.ApiGoods) {
func Recommend(ctx *gin.Context, req *common.RecommendRequest) (rsp common.RecommendResponse) {
var err error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
var goodsName string
......@@ -92,7 +91,7 @@ func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model
}
//获取需要的数据
total := gjson.Get(result, "hits.total").Int()
var response common.BomResponse
var response common.RecommendResponse
response.Total = int(total)
//获取goods_id列表去商品服务获取商品
list := gjson.Get(result, "hits.hits.#._source").Array()
......@@ -103,8 +102,10 @@ func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model
goodsIdList = append(goodsIdList, goodsId)
}
goodsIdListStr = strings.Join(goodsIdList, ",")
goodsList, err = GetGoodsInfoByApi(ctx,goodsIdListStr)
return goodsList
goodsList, err := GetGoodsInfoByApi(ctx, goodsIdListStr)
response.Data = goodsList
response.Flag = req.Flag
return response
}
//处理recommend接口的请求参数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment