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

淘特

上级 5d7cc674
...@@ -27,7 +27,7 @@ type NotifyGoodsData struct { ...@@ -27,7 +27,7 @@ type NotifyGoodsData struct {
type ThirdGoods struct { type ThirdGoods struct {
ThirdId interface{} `json:"third_id"` //三方商品id ThirdId interface{} `json:"third_id"` //三方商品id
Skus []int `json:"skus"` //三方规格id Skus []int `json:"skus,omitempty"` //三方规格id
} }
//通知消息系统 //通知消息系统
......
...@@ -86,9 +86,9 @@ func (s *Config) Post(ctx context.Context, method string, params g.Map) (str str ...@@ -86,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 {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Cat(PkgName).Ctx(ctx).Infof("参数【%v】响应【%v】响应时间【%v】", str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", str, gtime.TimestampMilli()-Start)
} }
}() }()
str = resp.ReadAllString() str = resp.ReadAllString()
......
...@@ -15,6 +15,7 @@ type Config struct { ...@@ -15,6 +15,7 @@ type Config struct {
AppKey string AppKey string
AppSecret string AppSecret string
API string API string
DB int
} }
var server *Config var server *Config
...@@ -24,6 +25,9 @@ const CacheKey = "dwd:token" ...@@ -24,6 +25,9 @@ const CacheKey = "dwd:token"
func New(req *Config) { func New(req *Config) {
server = req server = req
if server.DB == 0 {
server.DB = 10
}
return return
} }
...@@ -89,7 +93,7 @@ func post(ctx context.Context, method string, req interface{}) (res *CommonRes, ...@@ -89,7 +93,7 @@ func post(ctx context.Context, method string, req interface{}) (res *CommonRes,
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 {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), str, gtime.TimestampMilli()-Start)
} }
......
...@@ -52,7 +52,7 @@ func (s *tokenDwd) Access(ctx context.Context) (res string, err error) { ...@@ -52,7 +52,7 @@ func (s *tokenDwd) Access(ctx context.Context) (res string, err error) {
defer func() { defer func() {
_ = conn.Close() _ = conn.Close()
}() }()
_, _ = conn.DoVar("SELECT", 10) _, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey) cache, _ := conn.DoVar("HGETALL", CacheKey)
if !cache.IsEmpty() { if !cache.IsEmpty() {
_ = cache.Scan(&s) _ = cache.Scan(&s)
...@@ -90,7 +90,7 @@ func (s *tokenDwd) post(ctx context.Context, req interface{}) (res string, err e ...@@ -90,7 +90,7 @@ func (s *tokenDwd) post(ctx context.Context, req interface{}) (res string, err e
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", "token") ctx = context.WithValue(ctx, "URI", "token")
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", request.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), res, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", request.MustToJsonString(), res, gtime.TimestampMilli()-Start)
} }
......
...@@ -48,7 +48,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err ...@@ -48,7 +48,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
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 {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", param.MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", param.MustToJsonString(), res, gtime.TimestampMilli()-Start)
} }
......
...@@ -8,9 +8,7 @@ import ( ...@@ -8,9 +8,7 @@ import (
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/errors/gerror" "github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gctx"
"github.com/gogf/gf/os/gtime" "github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtimer"
"github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gconv"
"net/url" "net/url"
"sort" "sort"
...@@ -22,6 +20,7 @@ type Config struct { ...@@ -22,6 +20,7 @@ type Config struct {
ApiUrl string ApiUrl string
AppKey string AppKey string
AppSecret string AppSecret string
DB int
} }
var server *Config var server *Config
...@@ -32,10 +31,9 @@ const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/" ...@@ -32,10 +31,9 @@ const Host = "https://open.huoju6.com/openapi/param2/1/com.huoju6.open/"
func New(req *Config) { func New(req *Config) {
server = req server = req
gtimer.Add(time.Hour, func() { if server.DB == 0 {
var ctx = gctx.New() server.DB = 10
_, _ = server.accessToken(ctx) }
})
return return
} }
...@@ -78,7 +76,7 @@ func sign(method string, req g.Map) (err error) { ...@@ -78,7 +76,7 @@ func sign(method string, req g.Map) (err error) {
} }
func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) { func (s *Config) Post(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = s.GetAccessToken(ctx) params["access_token"], err = AccessToken(ctx)
if err != nil { if err != nil {
return return
} }
...@@ -116,7 +114,7 @@ func Post(ctx context.Context, method string, params g.Map) (str string, err err ...@@ -116,7 +114,7 @@ func Post(ctx context.Context, method string, params g.Map) (str string, err err
} }
func (s *Config) Get(ctx context.Context, method string, params g.Map) (str string, err error) { func (s *Config) Get(ctx context.Context, method string, params g.Map) (str string, err error) {
params["access_token"], err = s.GetAccessToken(ctx) params["access_token"], err = AccessToken(ctx)
if err != nil { if err != nil {
return return
} }
...@@ -157,43 +155,43 @@ func Get(ctx context.Context, method string, params g.Map) (str string, err erro ...@@ -157,43 +155,43 @@ func Get(ctx context.Context, method string, params g.Map) (str string, err erro
} }
func (s *Config) GetAccessToken(ctx context.Context) (res string, err error) { func AccessToken(ctx context.Context) (res string, err error) {
var conn = g.Redis().Conn() var conn = g.Redis().Conn()
defer func() { defer func() {
_ = conn.Close() _ = conn.Close()
}() }()
_, _ = conn.DoVar("SELECT", 10) _, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey) cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() { if cache.IsEmpty() {
err = gerror.New("获取token 失败") g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return return
} }
var result *AuthTokenRes var result *AuthTokenRes
_ = gjson.New(cache).Scan(&result) _ = gjson.New(cache).Scan(&result)
if result == nil || result.AccessToken == "" { if result == nil {
err = gerror.New("获取token 失败") g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
return err = gerror.New("获取token失败")
}
if result.AccessTokenExpireTime < gtime.TimestampMilli() {
result, err = s.accessToken(ctx)
if err != nil {
return return
} }
if result.AccessToken == "" || result.AccessTokenExpireTime < gtime.TimestampMilli() {
result, err = RefreshToken(ctx)
} }
res = result.AccessToken res = result.AccessToken
return return
} }
//accessToken 刷新 //RefreshToken 刷新
func (s *Config) accessToken(ctx context.Context) (res *AuthTokenRes, err error) { func RefreshToken(ctx context.Context) (res *AuthTokenRes, err error) {
var conn = g.Redis().Conn() var conn = g.Redis().Conn()
defer func() { defer func() {
_ = conn.Close() _ = conn.Close()
}() }()
_, _ = conn.DoVar("SELECT", 10) _, _ = conn.DoVar("SELECT", server.DB)
cache, _ := conn.DoVar("HGETALL", CacheKey) cache, _ := conn.DoVar("HGETALL", CacheKey)
if cache.IsEmpty() { if cache.IsEmpty() {
err = gerror.New("获取token 失败") g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return return
} }
_ = gjson.New(cache).Scan(&res) _ = gjson.New(cache).Scan(&res)
...@@ -205,7 +203,8 @@ func (s *Config) accessToken(ctx context.Context) (res *AuthTokenRes, err error) ...@@ -205,7 +203,8 @@ func (s *Config) accessToken(ctx context.Context) (res *AuthTokenRes, err error)
return return
} }
if res.Code != "success" { if res.Code != "success" {
err = gerror.New("获取token 失败") g.Log().Ctx(ctx).Cat(PkgName).Line(true).Info("获取token失败")
err = gerror.New("获取token失败")
return return
} }
_, _ = conn.Do("HMSET", CacheKey, "accessToken", res.AccessToken, "accessTokenExpireTime", res.AccessTokenExpireTime) _, _ = conn.Do("HMSET", CacheKey, "accessToken", res.AccessToken, "accessTokenExpireTime", res.AccessTokenExpireTime)
......
...@@ -95,12 +95,12 @@ type GoodsDetailRes struct { ...@@ -95,12 +95,12 @@ type GoodsDetailRes struct {
} `json:"debugInfoMap"` } `json:"debugInfoMap"`
EnterNewLink string `json:"enterNewLink"` EnterNewLink string `json:"enterNewLink"`
Item struct { Item struct {
CategoryId []string `json:"categoryId"` CategoryId []string `json:"categoryId"` //商品的类目列表,从一级类目开始
CategoryName []string `json:"categoryName"` CategoryName []string `json:"categoryName"` //商品的类目标题
City string `json:"city"` City string `json:"city"`
FastPostFee int `json:"fastPostFee"` FastPostFee int `json:"fastPostFee"` //商品的快递费用
Images []string `json:"images"` Images []string `json:"images"`
ItemId string `json:"itemId"` ItemId string `json:"itemId"` //商品id
ItemServices []struct { ItemServices []struct {
ActionTitle string `json:"actionTitle,omitempty"` ActionTitle string `json:"actionTitle,omitempty"`
ActionUrl string `json:"actionUrl,omitempty"` ActionUrl string `json:"actionUrl,omitempty"`
...@@ -108,33 +108,33 @@ type GoodsDetailRes struct { ...@@ -108,33 +108,33 @@ type GoodsDetailRes struct {
Title string `json:"title"` Title string `json:"title"`
} `json:"itemServices"` } `json:"itemServices"`
MainPic string `json:"mainPic"` MainPic string `json:"mainPic"`
OrdinaryPostFee int `json:"ordinaryPostFee"` OrdinaryPostFee int `json:"ordinaryPostFee"` //商品的平邮费用
Props []struct { Props []struct {
Content string `json:"content"` Content string `json:"content"`
Word string `json:"word"` Word string `json:"word"`
} `json:"props"` } `json:"props"`
Prov string `json:"prov"` Prov string `json:"prov"`
Receipt bool `json:"receipt"` Receipt bool `json:"receipt"`
SoldQuantity int `json:"soldQuantity"` SoldQuantity int `json:"soldQuantity"` //商品的销量
Status int `json:"status"` Status int `json:"status"` //商品的状态 0,1正常,-1:用户删除,-2:用户下架,-3 小二下架,-4 小二删除,-5 从未上架,-9 CC
Title string `json:"title"` Title string `json:"title"` //商品的类目标题
} `json:"item"` } `json:"item"`
Seller struct { Seller struct { //商品的卖家信息
ShopName string `json:"shopName"` ShopName string `json:"shopName"` //店铺名称
SellerId string `json:"sellerId"` SellerId string `json:"sellerId"`
} `json:"seller"` } `json:"seller"`
SkuBase struct { SkuBase struct {
Props []struct { Props []struct {
Name string `json:"name"` Name string `json:"name"` //sku的属性名称
Pid string `json:"pid"` Pid string `json:"pid"` //sku的属性id
Values []struct { Values []struct {
Image string `json:"image"` Image string `json:"image"`
Name string `json:"name"` Name string `json:"name"` //sku的属性内容
Vid string `json:"vid"` Vid string `json:"vid"` //sku的属性内容id
} `json:"values"` } `json:"values"`
} `json:"props"` } `json:"props"`
Skus []struct { Skus []struct {
PropPath string `json:"propPath"` PropPath string `json:"propPath"` //sku的属性路径
SkuId string `json:"skuId"` SkuId string `json:"skuId"`
} `json:"skus"` } `json:"skus"`
} `json:"skuBase"` } `json:"skuBase"`
...@@ -144,11 +144,11 @@ type GoodsDetailRes struct { ...@@ -144,11 +144,11 @@ type GoodsDetailRes struct {
} }
type GoodsItem struct { type GoodsItem struct {
QuantityVague string `json:"quantityVague"` QuantityVague string `json:"quantityVague"` //模糊化库存,实际库存大于200时展示200,小于200时展示实际的值
OriginalPrice string `json:"originalPrice"` OriginalPrice string `json:"originalPrice"` //特价,报名特价版的价格 单位:分
FinalPrice string `json:"finalPrice"` FinalPrice string `json:"finalPrice"`
TjbMarketPrice string `json:"tjbMarketPrice"` TjbMarketPrice string `json:"tjbMarketPrice"` //市场价
PriceMoney string `json:"priceMoney"` PriceMoney string `json:"priceMoney"` //单品优惠价,参与活动后得价格
} }
//Detail 详情 //Detail 详情
......
...@@ -12,8 +12,14 @@ type logistics struct { ...@@ -12,8 +12,14 @@ type logistics struct {
var Logistics = logistics{} var Logistics = logistics{}
type LogisticsTraceRes struct { type LogisticsTraceRes struct {
Result struct { Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
Result []struct { Result []struct {
CompanyList []struct {
BrandCode string `json:"brandCode"`
CompanyName string `json:"companyName"`
} `json:"companyList"`
DetailList []struct { DetailList []struct {
Action string `json:"action"` Action string `json:"action"`
GmtCreate string `json:"gmtCreate"` GmtCreate string `json:"gmtCreate"`
...@@ -38,10 +44,6 @@ type LogisticsTraceRes struct { ...@@ -38,10 +44,6 @@ type LogisticsTraceRes struct {
StatusDesc string `json:"statusDesc"` StatusDesc string `json:"statusDesc"`
} `json:"status"` } `json:"status"`
} `json:"result"` } `json:"result"`
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
} `json:"result"`
} }
//Trace 物流轨迹 //Trace 物流轨迹
......
...@@ -110,7 +110,7 @@ func (s refund) Create(ctx context.Context, req RefundCreateReq, image ...string ...@@ -110,7 +110,7 @@ func (s refund) Create(ctx context.Context, req RefundCreateReq, image ...string
//Cancle 取消售后 //Cancle 取消售后
//`bizOrderId` 子订单号 //`bizOrderId` 子订单号
//`disputeId` 售后单号 //`disputeId` 售后单号
func (s refund) Cancle(ctx context.Context, bizOrderId, disputeId string) (res *CommonRes, err error) { func (s refund) Cancel(ctx context.Context, bizOrderId, disputeId string) (res *CommonRes, err error) {
method := "tt.refund.refundRevoke" method := "tt.refund.refundRevoke"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
...@@ -153,7 +153,7 @@ type RefundSubmitRes struct { ...@@ -153,7 +153,7 @@ type RefundSubmitRes struct {
//Submit 提交物流信息 //Submit 提交物流信息
func (s refund) Submit(ctx context.Context, req RefundSubmitReq, image ...string) (res *CommonRes, err error) { func (s refund) Submit(ctx context.Context, req RefundSubmitReq, image ...string) (res *CommonRes, err error) {
method := "tt.refund.refundSubmit" method := "tt.refund.submitLogisticInfo.v1"
if len(image) > 0 { if len(image) > 0 {
for _, item := range image { for _, item := range image {
req.LeaveMessagePics = append(req.LeaveMessagePics, RefundPic{MessagePic: item}) req.LeaveMessagePics = append(req.LeaveMessagePics, RefundPic{MessagePic: item})
......
...@@ -33,7 +33,7 @@ func (s upload) Image(ctx context.Context, req UploadImageReq) (res *UploadImage ...@@ -33,7 +33,7 @@ func (s upload) Image(ctx context.Context, req UploadImageReq) (res *UploadImage
req.FileContent = "base64" req.FileContent = "base64"
} }
var request = g.Map{} var request = g.Map{}
request["access_token"], err = server.GetAccessToken(ctx) request["access_token"], err = AccessToken(ctx)
if err != nil { if err != nil {
return return
} }
......
...@@ -46,10 +46,10 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st ...@@ -46,10 +46,10 @@ func (c *Config) Post(ctx context.Context, api string, bodyMap g.Map) (result st
defer func() { defer func() {
ctx = context.WithValue(ctx, "URI", api) ctx = context.WithValue(ctx, "URI", api)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Cat("error").Async(true). g.Log().Ctx(ctx).Cat(pkgName).Cat("error").
Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start) Infof("参数【%v】错误【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Async(true). g.Log().Ctx(ctx).Cat(pkgName).
Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start) Infof("参数【%v】响应【%v】响应时间:【%v ms】", gjson.New(bodyMap).MustToJsonString(), result, gtime.TimestampMilli()-Start)
} }
}() }()
......
...@@ -110,7 +110,7 @@ func post(ctx context.Context, method string, params map[string]string) (str str ...@@ -110,7 +110,7 @@ func post(ctx context.Context, method string, params map[string]string) (str str
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"]) ctx = context.WithValue(ctx, "URI", apiUrl+params["Action"])
if err != nil { if err != nil {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(PkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, str, gtime.TimestampMilli()-Start)
} }
......
...@@ -95,7 +95,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err ...@@ -95,7 +95,7 @@ func post(ctx context.Context, method string, req interface{}) (res string, err
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 {
g.Log().Ctx(ctx).Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, res, gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Infof("参数【%v】响应【%v】响应时间【%v】", paramStr, res, gtime.TimestampMilli()-Start)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论