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

Merge branch 'master' into itao

# Conflicts:
#	notify/message.go
...@@ -29,7 +29,6 @@ const ( ...@@ -29,7 +29,6 @@ const (
//内部消息通知 //内部消息通知
MsgGoodsUpdateTopic = "goodsUpdate" MsgGoodsUpdateTopic = "goodsUpdate"
//消息类型 //消息类型
//商品消息 //商品消息
...@@ -69,7 +68,7 @@ const ( ...@@ -69,7 +68,7 @@ const (
GoodsStorageRemove = 502 //移除选品库 GoodsStorageRemove = 502 //移除选品库
//内部修改商品消息 //内部修改商品消息
GoodsSaleUpdate = 10000 //修1改销量 GoodsSaleUpdate = 10000 //修1改销量
ErrMsgParamEmpty = "该类型消息对应字段不能为空" ErrMsgParamEmpty = "该类型消息对应字段不能为空"
ErrMsgAppIDEmpty = "该类型消息appid字段不能为空" ErrMsgAppIDEmpty = "该类型消息appid字段不能为空"
...@@ -196,9 +195,12 @@ func (p *NsqProducer) NotifyMessage(notifyMessage *NotifyMessage) (err error) { ...@@ -196,9 +195,12 @@ func (p *NsqProducer) NotifyMessage(notifyMessage *NotifyMessage) (err error) {
} }
err = NsqProducers.Publish(notifyMsg, gjson.New(notifyMessage).MustToJsonString()) err = NsqProducers.Publish(notifyMsg, gjson.New(notifyMessage).MustToJsonString())
if !logs.CheckErr(err, "NotifyMessage") { if err != nil {
logs.Info("NotifyMessage", "消息内容:【%v】", gjson.New(notifyMessage).MustToJsonString()) g.Log().Cat("NotifyMessage").Cat("error").Infof(`消息内容【%v】错误【%v】`, gjson.New(notifyMessage).MustToJsonString(), err.Error())
} else {
g.Log().Cat("NotifyMessage").Infof(`消息内容【%v】`, gjson.New(notifyMessage).MustToJsonString())
} }
return return
} }
...@@ -209,8 +211,10 @@ func (p *NsqProducer) NotifyMessage(notifyMessage *NotifyMessage) (err error) { ...@@ -209,8 +211,10 @@ func (p *NsqProducer) NotifyMessage(notifyMessage *NotifyMessage) (err error) {
func (p *NsqProducer) NotifyApiLog(notifyApiLog *NotifyApiLog) (err error) { func (p *NsqProducer) NotifyApiLog(notifyApiLog *NotifyApiLog) (err error) {
jsonBytes, _ := json.Marshal(notifyApiLog) jsonBytes, _ := json.Marshal(notifyApiLog)
err = NsqProducers.Publish(ApiRequestTopic, string(jsonBytes)) err = NsqProducers.Publish(ApiRequestTopic, string(jsonBytes))
if !logs.CheckErr(err, "NotifyApiLog") { if err != nil {
logs.Info("NotifyApiLog", "消息内容:【%v】", string(jsonBytes)) g.Log().Cat("NotifyApiLog").Cat("error").Infof(`消息内容【%v】错误【%v】`, gjson.New(notifyApiLog).MustToJsonString(), err.Error())
} else {
g.Log().Cat("NotifyApiLog").Infof(`消息内容【%v】`, gjson.New(notifyApiLog).MustToJsonString())
} }
return return
} }
...@@ -2,6 +2,7 @@ package notify ...@@ -2,6 +2,7 @@ package notify
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/frame/g"
"github.com/nsqio/go-nsq" "github.com/nsqio/go-nsq"
"gitlab.jxhh.com/stbz/library.git/logs" "gitlab.jxhh.com/stbz/library.git/logs"
"time" "time"
...@@ -13,7 +14,7 @@ type NsqProducer struct { ...@@ -13,7 +14,7 @@ type NsqProducer struct {
var ( var (
NsqProducers *NsqProducer NsqProducers *NsqProducer
nsqConfig *NsqConfig //重试 nsqConfig *NsqConfig //重试
) )
func New(config *NsqConfig) { func New(config *NsqConfig) {
...@@ -21,16 +22,15 @@ func New(config *NsqConfig) { ...@@ -21,16 +22,15 @@ func New(config *NsqConfig) {
NsqProducers = InitProducer(config) NsqProducers = InitProducer(config)
} }
func InitProducer(config *NsqConfig) *NsqProducer { func InitProducer(config *NsqConfig) *NsqProducer {
producer, err := nsq.NewProducer(config.Addr, nsq.NewConfig()) producer, err := nsq.NewProducer(config.Addr, nsq.NewConfig())
if logs.CheckErr(err,"InitProducer") { if logs.CheckErr(err, "InitProducer") {
//panic(err) //panic(err)
producer.Stop() producer.Stop()
} }
err = producer.Ping() err = producer.Ping()
if logs.CheckErr(err,"InitProducer") { if logs.CheckErr(err, "InitProducer") {
producer.Stop() producer.Stop()
} }
...@@ -40,10 +40,7 @@ func InitProducer(config *NsqConfig) *NsqProducer { ...@@ -40,10 +40,7 @@ func InitProducer(config *NsqConfig) *NsqProducer {
} }
//发布消息 //发布消息
func (p *NsqProducer) Publish(topic string, message string) error { func (p *NsqProducer) Publish(topic string, message string) (err error) {
//logs.Info("topic","topic:%v,message:%v",topic,message)
var err error
defer func() { defer func() {
if err != nil { if err != nil {
//重试连接 //重试连接
...@@ -51,21 +48,24 @@ func (p *NsqProducer) Publish(topic string, message string) error { ...@@ -51,21 +48,24 @@ func (p *NsqProducer) Publish(topic string, message string) error {
} }
}() }()
if p.producer != nil { if p.producer != nil {
if message == "" { //不能发布空串,否则会导致error if message == "" { //不能发布空串,否则会导致error
return nil return nil
} }
err = p.producer.Publish(topic, []byte(message)) // 发布消息 err = p.producer.Publish(topic, []byte(message)) // 发布消息
logs.CheckErr(err, "Nsq Publish") if err != nil {
return err g.Log().Cat("Producer").Cat("error").Infof(`消息内容【%v】错误【%v】`, message, err.Error())
} else {
g.Log().Cat("Producer").Infof(`消息内容【%v】`, message)
}
return
} }
return fmt.Errorf("producer is nil", err) return fmt.Errorf("producer is nil", err)
} }
//发布延迟消息 //发布延迟消息
func (p *NsqProducer) DeferredPublish(topic string,delay time.Duration, message string) error { func (p *NsqProducer) DeferredPublish(topic string, delay time.Duration, message string) error {
//logs.Infof(context.Background(),"topic",message) //logs.Infof(context.Background(),"topic",message)
...@@ -74,8 +74,12 @@ func (p *NsqProducer) DeferredPublish(topic string,delay time.Duration, message ...@@ -74,8 +74,12 @@ func (p *NsqProducer) DeferredPublish(topic string,delay time.Duration, message
if message == "" { //不能发布空串,否则会导致error if message == "" { //不能发布空串,否则会导致error
return nil return nil
} }
err = p.producer.DeferredPublish(topic,delay,[]byte(message)) // 发布消息 err = p.producer.DeferredPublish(topic, delay, []byte(message)) // 发布消息
logs.CheckErr(err, "Nsq Publish") if err != nil {
g.Log().Cat("Producer").Cat("error").Infof(`消息内容【%v】错误【%v】`, message, err.Error())
} else {
g.Log().Cat("Producer").Infof(`消息内容【%v】`, message)
}
return err return err
} }
......
...@@ -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()
......
...@@ -2,7 +2,7 @@ package hdh ...@@ -2,7 +2,7 @@ package hdh
import ( import (
"context" "context"
"encoding/json" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/net/ghttp"
) )
...@@ -214,7 +214,10 @@ func GetGoodsList(ctx context.Context, req *GoodsListReq) (res *GoodsListRes, er ...@@ -214,7 +214,10 @@ func GetGoodsList(ctx context.Context, req *GoodsListReq) (res *GoodsListRes, er
if nil != err { if nil != err {
return return
} }
err = json.Unmarshal([]byte(result), &res) //err = json.Unmarshal([]byte(result), &res)
err = gjson.NewWithOptions([]byte(result), gjson.Options{
StrNumber: true,
}).Scan(&res)
return return
} }
...@@ -225,16 +228,26 @@ func GetGoodsInfo(ctx context.Context, req *GoodsInfoReq) (res *GoodsInfoRes, er ...@@ -225,16 +228,26 @@ func GetGoodsInfo(ctx context.Context, req *GoodsInfoReq) (res *GoodsInfoRes, er
if nil != err { if nil != err {
return return
} }
err = json.Unmarshal([]byte(result), &res) //err = json.Unmarshal([]byte(result), &res)
err = gjson.NewWithOptions([]byte(result), gjson.Options{
StrNumber: true,
}).Scan(&res)
return return
} }
//商品回调 //商品回调
func GoodsCallBack(r *ghttp.Request) (res *GoodsNotifyRes, err error) { func GoodsCallBack(r *ghttp.Request) (res *GoodsNotifyRes, err error) {
body, err := CheckSign(r) //body, err := CheckSign(r)
if nil != err { //if nil != err {
// return
//}
body := r.GetBodyString()
if body == "" {
return return
} }
err = json.Unmarshal([]byte(body), &res) //err = json.Unmarshal([]byte(body), &res)
err = gjson.NewWithOptions([]byte(body), gjson.Options{
StrNumber: true,
}).Scan(&res)
return return
} }
...@@ -81,8 +81,12 @@ func OrderCreate(ctx context.Context, req *OerCreateReq) (res *OerCreateRes, err ...@@ -81,8 +81,12 @@ func OrderCreate(ctx context.Context, req *OerCreateReq) (res *OerCreateRes, err
//订单回调 //订单回调
func OrderCallBack(r *ghttp.Request) (res *OrderNotifyRes, err error) { func OrderCallBack(r *ghttp.Request) (res *OrderNotifyRes, err error) {
body, err := CheckSign(r) //body, err := CheckSign(r)
if nil != err { //if nil != err {
// return
//}
body := r.GetBodyString()
if body == "" {
return return
} }
err = json.Unmarshal([]byte(body), &res) err = json.Unmarshal([]byte(body), &res)
......
...@@ -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,omitempty"` //搜索关键字,需要编码
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论