Commit 82be365a by huangchengyi

比价

parent 93657b89
...@@ -3,6 +3,7 @@ package controller ...@@ -3,6 +3,7 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/service"
) )
/* /*
...@@ -13,10 +14,8 @@ import ( ...@@ -13,10 +14,8 @@ import (
*/ */
func GetParityData(ctx *gin.Context) { func GetParityData(ctx *gin.Context) {
common.PrintDebugHeader(ctx) //debug common.PrintDebugHeader(ctx) //debug
//调外链拿数据 optimumservice := service.ParityService{}
//optimumservice := service.OptimumService{} apiData := optimumservice.GetParity(ctx)
//apiData := optimumservice.GetOptimumAttr(ctx) common.PrintDebugHtml(ctx,"-----执行结束----") //debug
// common.Output(ctx,apiData.ErrorCode, "查询成功", apiData.Data)
//common.PrintDebugHtml(ctx,"-----执行结束----") //debug
//common.Output(ctx,errCode, "查询成功", "")
} }
package main
import "fmt"
func main() {
s := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
fmt.Println(len(s))
s = s[3:9]
fmt.Println(s)
fmt.Println(len(s))
fmt.Println(cap(s))
}
\ No newline at end of file
...@@ -60,6 +60,7 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) { ...@@ -60,6 +60,7 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) {
_, err := c.Do("PING") _, err := c.Do("PING")
return err return err
}, },
Wait: true,
} }
return return
} }
\ No newline at end of file
...@@ -22,20 +22,26 @@ type ParityService struct { ...@@ -22,20 +22,26 @@ type ParityService struct {
* 查询比价 * 查询比价
@param number 比价数量,eg:500 @param number 比价数量,eg:500
@param deliver 交货地: 1 大陆 2 香港 (默认大陆) @param deliver 交货地: 1 大陆 2 香港 (默认大陆)
@param target_goods_name 目标比价型号名称,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK @param target_goods_name/eq 目标比价型号名称精确搜索,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK
@param target_goods_name/like 目标比价型号名称模糊搜索,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK
*/ */
func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) { func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) {
number := ctx.Request.FormValue("number") //比价数量 number := ctx.Request.FormValue("number") //比价数量
deliver := ctx.Request.FormValue("deliver") //交货地 deliver := ctx.Request.FormValue("deliver") //交货地
target_goods_name := ctx.Request.FormValue("target_goods_name") //比价目标型号
target_goods_name := ctx.Request.FormValue("target_goods_name/eq") //比价目标型号
target_goods_type := 1 //精确匹配
if target_goods_name == "" {
target_goods_name = ctx.Request.FormValue("target_goods_name/like") //比价目标型号
target_goods_type = 2 //模糊匹配
}
if target_goods_name == "" { if target_goods_name == "" {
results.ErrorCode = 1001; results.ErrorCode = 1001;
results.ErrorMsg = "目标比价型号不得为空" results.ErrorMsg = "目标比价型号不得为空"
return return
} }
//获取查询条件 //获取查询条件
queryString := query.GetParityQuery(ctx,target_goods_name) queryString := query.GetParityQuery(ctx,target_goods_name,target_goods_type)
indexTarget := "liexin_ziying" indexTarget := "liexin_ziying"
if deliver == "2" { if deliver == "2" {
indexTarget = config.Get("es.search_supplier").String(); indexTarget = config.Get("es.search_supplier").String();
...@@ -88,6 +94,9 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) ...@@ -88,6 +94,9 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse)
} }
} }
} }
if len(v.LadderPrice) == 0 { //梯度价
continue;
}
//比价数量对应的梯度数量 //比价数量对应的梯度数量
var tprice float64 = 0; //对应梯度价 var tprice float64 = 0; //对应梯度价
for _,p := range v.LadderPrice { for _,p := range v.LadderPrice {
...@@ -97,10 +106,10 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) ...@@ -97,10 +106,10 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse)
}else{ //香港 }else{ //香港
tprice = p.PriceUs tprice = p.PriceUs
} }
break;
} }
} }
slic = append(slic,model.DullGoodsData{ slic = append(slic,model.DullGoodsData{
ApiGoods:v, ApiGoods:v,
GoodsUrl: GoodsUrl, GoodsUrl: GoodsUrl,
...@@ -112,6 +121,7 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) ...@@ -112,6 +121,7 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse)
sort.Sort(DullGoodsData(slic)) sort.Sort(DullGoodsData(slic))
allCount := len(slic) //总条数
//分页计算 //分页计算
page := ctx.Request.FormValue("page") page := ctx.Request.FormValue("page")
page_size := ctx.Request.FormValue("page_size") page_size := ctx.Request.FormValue("page_size")
...@@ -122,15 +132,20 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse) ...@@ -122,15 +132,20 @@ func (qs *ParityService) GetParity(ctx *gin.Context) (results model.LyResponse)
if page_size == "" { if page_size == "" {
page_size = "10"; page_size = "10";
} }
if page != "1" { if page != "1" && page != "" {
page_from = (gconv.Int(page)-1)*gconv.Int(page_size) page_from = (gconv.Int(page)-1)*gconv.Int(page_size)
if page_from >10000 { if page_from >10000 {
page_from = 10000; page_from = 10000;
} }
} }
offset := page_from+gconv.Int(page_size)
if offset > allCount || page_from > allCount {
page_from = allCount
offset = allCount
}
slicNew := slic[page_from:(page_from+gconv.Int(page_size))] slicNew := slic[page_from:offset]
pageData := PageClear(ctx,total); pageData := PageClear(ctx,gconv.Int64(allCount));
pageData["took"] = gjson.Get(esResult, "took").Int() pageData["took"] = gjson.Get(esResult, "took").Int()
A.Set("page",pageData) //分页信息 A.Set("page",pageData) //分页信息
A.Set("goods_lists",slicNew) A.Set("goods_lists",slicNew)
...@@ -151,5 +166,5 @@ func (a DullGoodsData) Swap(i, j int) { ...@@ -151,5 +166,5 @@ func (a DullGoodsData) Swap(i, j int) {
a[i], a[j] = a[j], a[i] a[i], a[j] = a[j], a[i]
} }
func (a DullGoodsData) Less(i, j int) bool { func (a DullGoodsData) Less(i, j int) bool {
return a[j].Tprice < a[i].Tprice return a[j].Tprice > a[i].Tprice
} }
\ No newline at end of file
...@@ -11,17 +11,21 @@ import ( ...@@ -11,17 +11,21 @@ import (
比价拼接查询语句 比价拼接查询语句
@param target_goods_name 目标比价型号名称,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK @param target_goods_name 目标比价型号名称,多个型号名称(类似型号一样这样拼接传) 以€分隔,如:LM358DT€LM358SK
*/ */
func GetParityQuery(ctx *gin.Context,target_goods_name string) (param string){ func GetParityQuery(ctx *gin.Context,target_goods_name string,target_goods_type int) (param string){
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
subQuery := elastic.NewBoolQuery() subQuery := elastic.NewBoolQuery()
if target_goods_name == "" { if target_goods_name == "" {
return "" return ""
} }
goodsSlice:= php2go.Explode("€",target_goods_name); goodsSlice:= php2go.Explode("€",target_goods_name);
for _,goods_name := range goodsSlice { for _,goods_name := range goodsSlice {
subQuery.Should(elastic.NewTermQuery("auto_goods_name.raw", goods_name)) if target_goods_type == 1 { //精确匹配
subQuery.Should(elastic.NewTermQuery("auto_goods_name.raw", goods_name))
}else{
subQuery.Should(elastic.NewTermQuery("goods_name", goods_name)) //DEBUG
}
} }
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))
......
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