提交 dbf8070d authored 作者: 张立波's avatar 张立波

京东搜索

上级 f38c8611
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"gitlab.jxhh.com/stbz/library.git/logs"
"sort" "sort"
"strings" "strings"
"time" "time"
...@@ -31,7 +30,7 @@ type CommonRes struct { ...@@ -31,7 +30,7 @@ type CommonRes struct {
var server *Config var server *Config
const pkgName = "ali" const PkgName = "ali"
const WebSite = "1688" const WebSite = "1688"
func New(config *Config) { func New(config *Config) {
...@@ -87,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str ...@@ -87,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", Url) ctx = context.WithValue(ctx, "URI", Url)
if err != nil { if err != nil {
logs.Errorf(ctx, pkgName, logs.FormatErr, paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
logs.Infof(ctx, pkgName, logs.FormatSuc, paramStr, str, gtime.TimestampMilli()-Start) g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", str, gtime.TimestampMilli()-Start)
} }
}() }()
str = resp.ReadAllString() str = resp.ReadAllString()
......
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
"github.com/gogf/gf/text/gstr" "github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gutil" "github.com/gogf/gf/util/gutil"
"gitlab.jxhh.com/stbz/library.git/logs"
"time" "time"
) )
...@@ -58,7 +57,7 @@ type CommonRes struct { ...@@ -58,7 +57,7 @@ type CommonRes struct {
var server *Client var server *Client
const pkgName = "gome" const PkgName = "gome"
const CacheKey = "gome:token" const CacheKey = "gome:token"
func New(config *Config) { func New(config *Config) {
...@@ -93,9 +92,9 @@ func (s *Client) post(ctx context.Context, method string, req interface{}) (str ...@@ -93,9 +92,9 @@ func (s *Client) post(ctx context.Context, method string, req interface{}) (str
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", method) ctx = context.WithValue(ctx, "URI", method)
if err != nil { if err != nil {
logs.Errorf(ctx, pkgName, logs.FormatErr, paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
logs.Infof(ctx, pkgName, logs.FormatSuc, paramStr, str, gtime.TimestampMilli()-Start) g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
} }
}() }()
str = resp.ReadAllString() str = resp.ReadAllString()
......
...@@ -339,3 +339,99 @@ func (*goodsJD) QueryByPage(ctx context.Context, pageNum, pageNo, offset interfa ...@@ -339,3 +339,99 @@ func (*goodsJD) QueryByPage(ctx context.Context, pageNum, pageNo, offset interfa
err = gjson.New(result).Scan(&res) err = gjson.New(result).Scan(&res)
return return
} }
type GoodsSearchReq struct {
Keyword string `json:"Keyword"` //搜索关键字,需要编码
Cid1 string `json:"cid1,omitempty"` //一级分类
Cid2 string `json:"cid2,omitempty"` //二级分类
CatId string `json:"catId,omitempty"` //分类Id,只支持三级类目Id
PageIndex int `json:"pageIndex"` //当前第几页
PageSize int `json:"pageSize"` //当前页显示
Min string `json:"Min,omitempty"` //价格区间搜索,低价
Max string `json:"Max,omitempty"` //价格区间搜索,高价
Brands string `json:"Brands,omitempty"` //品牌搜索 多个品牌以逗号分隔,需要编码
PriceCol string `json:"priceCol,omitempty"` //价格汇总 priceCol=”yes”
ExtAttrCol string `json:"extAttrCol,omitempty"` //扩展属性汇总 extAttrCol=”yes”
MergeSku bool `json:"mergeSku,omitempty"` //true:合并同一产品不同规格sku;false:不合并同一产品不同规格sku
SortType string `json:"sortType,omitempty"` //销量降序="sale_desc"; 价格升序="price_asc"; 价格降序="price_desc"; 上架时间降序="winsdate_desc";
//按销量排序_15天销售额="sort_totalsales15_desc"; 按15日销量排序="sort_days_15_qtty_desc"; 按30日销量排序="sort_days_30_qtty_desc";
//按15日销售额排序="sort_days_15_gmv_desc"; 按30日销售额排序="sort_days_30_gmv_desc";
}
type GoodsSearchRes struct {
CommonRes
Result struct {
ResultCount int `json:"resultCount"`
PageSize int `json:"pageSize"`
PageIndex int `json:"pageIndex"`
PageCount int `json:"pageCount"`
BrandAggregate struct {
PinyinAggr []string `json:"pinyinAggr"`
BrandList []struct {
Id string `json:"id"`
Pinyin string `json:"pinyin"`
Name string `json:"name"`
} `json:"brandList"`
} `json:"brandAggregate"`
PriceIntervalAggregate []struct {
Min int `json:"min"`
Max int `json:"max"`
} `json:"priceIntervalAggregate"`
CategoryAggregate struct {
FirstCategory []struct {
CatId int `json:"catId"`
Count int `json:"count"`
ParentId int `json:"parentId"`
Field string `json:"field"`
Name string `json:"name"`
Weight int `json:"weight"`
} `json:"firstCategory"`
SecondCategory []struct {
CatId int `json:"catId"`
Count int `json:"count"`
ParentId int `json:"parentId"`
Field string `json:"field"`
Name string `json:"name"`
Weight int `json:"weight"`
} `json:"secondCategory"`
ThridCategory []struct {
CatId int `json:"catId"`
Count int `json:"count"`
ParentId int `json:"parentId"`
Field string `json:"field"`
Name string `json:"name"`
Weight int `json:"weight"`
} `json:"thridCategory"`
} `json:"categoryAggregate"`
ExpandAttrAggregate interface{} `json:"expandAttrAggregate"`
HitResult []struct {
WareId string `json:"wareId"`
WarePId string `json:"warePId"`
BrandId string `json:"brandId"`
Brand string `json:"brand"`
WareName string `json:"wareName"`
CatName interface{} `json:"catName"`
ImageUrl string `json:"imageUrl"`
CatId string `json:"catId"`
Cid1 string `json:"cid1"`
Cid2 string `json:"cid2"`
Cid1Name interface{} `json:"cid1Name"`
Cid2Name interface{} `json:"cid2Name"`
Wstate string `json:"wstate"`
Wyn string `json:"wyn"`
Synonyms interface{} `json:"synonyms"`
} `json:"hitResult"`
} `json:"result"`
}
//Search 搜索商品
func (*goodsJD) Search(ctx context.Context, req GoodsSearchReq) (res *GoodsSearchRes, err error) {
method := "/search/search"
result, err := server.requestApi(ctx, method, gconv.Map(req))
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论