Commit 4a7f6a13 by hcy001

更新比价

parent 208f5105
...@@ -42,12 +42,16 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) ...@@ -42,12 +42,16 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse)
results.ErrorMsg = "目标比价型号不得为空" results.ErrorMsg = "目标比价型号不得为空"
return return
} }
if number == "" {
number = "1";
}
stockCheck := gconv.Int(number); //比价数量
//获取查询条件 //获取查询条件
queryString := query.GetParityQuery(ctx,target_goods_name,target_goods_type) queryString := query.GetParityQuery(ctx,target_goods_name,target_goods_type,stockCheck)
indexTarget := config.Get("es.search_supplier").String()+",liexin_ziying" //所有索引参与比价 indexTarget := config.Get("es.search_supplier").String()+",liexin_ziying" //所有索引参与比价
//查询es //查询es
esResult, err := es.CurlEsPrimary(indexTarget, queryString) esResult, err := es.CurlES(indexTarget, queryString)
if err != nil { if err != nil {
results.ErrorCode = 1002; results.ErrorCode = 1002;
results.ErrorMsg = err.Error() results.ErrorMsg = err.Error()
...@@ -79,6 +83,10 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) ...@@ -79,6 +83,10 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse)
var slic []model.DullGoodsData var slic []model.DullGoodsData
goodsList, _ := GetGoodsInfo(ctx,goodsIds) goodsList, _ := GetGoodsInfo(ctx,goodsIds)
for _,v := range goodsList{ for _,v := range goodsList{
if v.Stock < stockCheck {
continue
}
GoodsUrl := "" GoodsUrl := ""
BrandUrl := "" BrandUrl := ""
referer := ctx.GetHeader("Referer") referer := ctx.GetHeader("Referer")
......
...@@ -10,8 +10,9 @@ import ( ...@@ -10,8 +10,9 @@ import (
/* /*
比价拼接查询语句 比价拼接查询语句
@param target_goods_name 目标比价型号名称,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK @param target_goods_name 目标比价型号名称,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK
@param number 比价数量
*/ */
func GetParityQuery(ctx *gin.Context,target_goods_name string,target_goods_type int) (param string){ func GetParityQuery(ctx *gin.Context,target_goods_name string,target_goods_type int,number int) (param string){
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
subQuery := elastic.NewBoolQuery() subQuery := elastic.NewBoolQuery()
...@@ -30,12 +31,12 @@ func GetParityQuery(ctx *gin.Context,target_goods_name string,target_goods_type ...@@ -30,12 +31,12 @@ func GetParityQuery(ctx *gin.Context,target_goods_name string,target_goods_type
} }
query.Must(elastic.NewTermQuery("goods_status", 1)) query.Must(elastic.NewTermQuery("goods_status", 1))
query.Must(elastic.NewTermQuery("status", 1)) query.Must(elastic.NewTermQuery("status", 1))
query.Must(elastic.NewRangeQuery("stock").Gt(0)) query.Must(elastic.NewRangeQuery("stock").Gte(number))
query.Must(subQuery) query.Must(subQuery)
source := elastic.NewSearchSource() source := elastic.NewSearchSource()
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id","goods_name")) //显示字段 source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id","goods_name","stock")) //显示字段
source.Size(200) source.Size(200)
source.From(0) source.From(0)
......
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