提交 2204b23f authored 作者: limeng's avatar limeng

Merge branch 'supplier'

# Conflicts:
#	supplier/yz/base.go
...@@ -24,8 +24,9 @@ type Config struct { ...@@ -24,8 +24,9 @@ type Config struct {
} }
type CommonRes struct { type CommonRes struct {
Success bool `json:"success"` Success bool `json:"success"`
Code string `json:"code"` Code int `json:"code"`
Message string `json:"message"` Message string `json:"message"`
TraceId string `json:"trace_id"` TraceId string `json:"trace_id"`
} }
...@@ -86,17 +87,20 @@ func (s *client) postImg(ctx context.Context, method string, params string) (str ...@@ -86,17 +87,20 @@ func (s *client) postImg(ctx context.Context, method string, params string) (str
return return
} }
fileWrite, err := bodyWrite.CreateFormFile("image", params) fileWrite, err := bodyWrite.CreateFormFile("image", params)
_, err = io.Copy(fileWrite, file) _, err = io.Copy(fileWrite, file)
if err != nil { if err != nil {
return return
} }
bodyWrite.Close() //要关闭,会将w.w.boundary刷写到w.writer中 bodyWrite.Close() //要关闭,会将w.w.boundary刷写到w.writer中
// 创建请求 // 创建请求
contentType := bodyWrite.FormDataContentType() contentType := bodyWrite.FormDataContentType()
req, err := http.NewRequest(http.MethodPost, url, bodyBuf) req, err := http.NewRequest(http.MethodPost, url, bodyBuf)
if err != nil { if err != nil {
return return
} }
// 设置头 // 设置头
...@@ -105,11 +109,16 @@ func (s *client) postImg(ctx context.Context, method string, params string) (str ...@@ -105,11 +109,16 @@ func (s *client) postImg(ctx context.Context, method string, params string) (str
if err != nil { if err != nil {
return return
} }
if resp==nil{
return
}
defer func() { defer func() {
_ = resp.Body.Close() _ = resp.Body.Close()
paramStr := gjson.New(params).MustToJsonString() paramStr := gjson.New(params).MustToJsonString()
ctx = context.WithValue(ctx, "Method", "POST") ctx = context.WithValue(ctx, "Method", "POST")
ctx = context.WithValue(ctx, "URI", url) ctx = context.WithValue(ctx, "URI", url)
_ = os.Remove(params)
if err != nil { if err != nil {
g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start) g.Log().Ctx(ctx).Cat(pkgName).Cat("error").Infof("参数【%v】错误【%v】响应时间【%v ms】", paramStr, err.Error(), gtime.TimestampMilli()-Start)
} else { } else {
......
...@@ -4,15 +4,43 @@ import ( ...@@ -4,15 +4,43 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"github.com/gogf/gf/encoding/gjson" "github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
) )
type goodsJD struct { type goodsJD struct {
} }
var Goods = goodsJD{} var Goods = goodsJD{}
type UpdateGoodsReq struct {
Param UpdateGoodsParam `json:"param"`
}
type UpdateGoodsParam struct {
ItemId int `json:"item_id"`
//NodeKdtId int `json:"node_kdt_id"`
ItemDeliveryParam ItemDeliveryParam `json:"item_delivery_param"`
ItemWeight int `json:"item_weight"`
ItemNo string `json:"item_no"`
SkuList []SkuListUpdate `json:"sku_list"`
Desc string `json:"desc"`
ImageIds []int64 `json:"image_ids"`
SkuValueProps []SkuValueProps `json:"sku_value_props"`
ItemType int `json:"item_type"`
ItemPriceParam ItemPriceParam `json:"item_price_param"`
Title string `json:"title"`
IsDisplay int `json:"is_display"`
Quantity int `json:"quantity"`
HideStock int `json:"hide_stock"`
}
type SkuListUpdate struct {
//SkuProps []SkuProps `json:"sku_props"`
Price int `json:"price"`
MaxGuidePrice int `json:"max_guide_price"`
CostPrice int `json:"cost_price"`
SkuNo string `json:"sku_no"`
StockNum int `json:"stock_num"`
SkuId int64 `json:"sku_id"`
}
type AddGoodsReq struct { type AddGoodsReq struct {
Param AddGoodsParam `json:"param"` Param AddGoodsParam `json:"param"`
} }
...@@ -21,14 +49,14 @@ type ItemDeliveryParam struct { ...@@ -21,14 +49,14 @@ type ItemDeliveryParam struct {
DeliverySetting DeliverySetting `json:"delivery_setting"` DeliverySetting DeliverySetting `json:"delivery_setting"`
} }
type DeliverySetting struct { type DeliverySetting struct {
Express bool `json:"express"` Express bool `json:"express"`
} }
type SkuList struct { type SkuList struct {
SkuProps []SkuProps `json:"sku_props"` SkuProps []SkuProps `json:"sku_props"`
Price int `json:"price"` Price int `json:"price"`
MaxGuidePrice int `json:"max_guide_price"` MaxGuidePrice int `json:"max_guide_price"`
CostPrice int `json:"cost_price"` CostPrice int `json:"cost_price"`
SkuNo int `json:"sku_no"` SkuNo string `json:"sku_no"`
StockNum int `json:"stock_num"` StockNum int `json:"stock_num"`
} }
type SkuProps struct { type SkuProps struct {
...@@ -44,16 +72,16 @@ type SkuValueProps struct { ...@@ -44,16 +72,16 @@ type SkuValueProps struct {
Id int `json:"id"` Id int `json:"id"`
} }
type ItemPriceParam struct { type ItemPriceParam struct {
Origin int `json:"origin"` Origin string `json:"origin"`
CostPrice int `json:"cost_price"` CostPrice int `json:"cost_price"`
Price int `json:"price"` Price int `json:"price"`
} }
type AddGoodsParam struct { type AddGoodsParam struct {
ItemId int `json:"item_id"` ItemId int `json:"item_id"`
NodeKdtId int `json:"node_kdt_id"` //NodeKdtId int `json:"node_kdt_id"`
ItemDeliveryParam ItemDeliveryParam `json:"item_delivery_param"` ItemDeliveryParam ItemDeliveryParam `json:"item_delivery_param"`
ItemWeight int `json:"item_weight"` ItemWeight int `json:"item_weight"`
ItemNo int `json:"item_no"` ItemNo string `json:"item_no"`
SkuList []SkuList `json:"sku_list"` SkuList []SkuList `json:"sku_list"`
Desc string `json:"desc"` Desc string `json:"desc"`
ImageIds []int64 `json:"image_ids"` ImageIds []int64 `json:"image_ids"`
...@@ -76,6 +104,21 @@ type UplpadImgReq struct { ...@@ -76,6 +104,21 @@ type UplpadImgReq struct {
Image string `json:"image"` Image string `json:"image"`
} }
type FindGoodsDataReq struct {
ItemId int `json:"item_id"`
}
type FindGoodsDataRes struct {
CommonRes
Data GoodsData `json:"data"`
}
type GoodsData struct {
SkuList []SkuListData `json:"sku_list"`
}
type SkuListData struct {
SkuId int64 `json:"sku_id"`
SkuNo string `json:"sku_no"`
}
// type UplpadImgRes struct { // type UplpadImgRes struct {
// CommonRes // CommonRes
// Data struct { // Data struct {
...@@ -85,8 +128,7 @@ type UplpadImgReq struct { ...@@ -85,8 +128,7 @@ type UplpadImgReq struct {
// } // }
type UplpadImgRes struct { type UplpadImgRes struct {
TraceId string `json:"trace_id"` CommonRes
Code int `json:"code"`
Data struct { Data struct {
KdtId int `json:"kdt_id"` KdtId int `json:"kdt_id"`
ImageUrl string `json:"image_url"` ImageUrl string `json:"image_url"`
...@@ -94,14 +136,12 @@ type UplpadImgRes struct { ...@@ -94,14 +136,12 @@ type UplpadImgRes struct {
ImageId int64 `json:"image_id"` ImageId int64 `json:"image_id"`
Height int `json:"height"` Height int `json:"height"`
} `json:"data"` } `json:"data"`
Success bool `json:"success"`
Message string `json:"message"`
} }
// 添加商品 // 添加商品
func (*goodsJD) AddGoods(ctx context.Context, req *AddGoodsReq) (res *AddGoodsRes, err error) { func (*goodsJD) AddGoods(ctx context.Context, req *AddGoodsReq) (res *AddGoodsRes, err error) {
// g.Dump(11111111,req) g.Dump(11111111,req)
// return return
method := "youzan.item.add/1.0.1" method := "youzan.item.add/1.0.1"
param := gconv.Map(req) param := gconv.Map(req)
...@@ -114,7 +154,8 @@ func (*goodsJD) AddGoods(ctx context.Context, req *AddGoodsReq) (res *AddGoodsRe ...@@ -114,7 +154,8 @@ func (*goodsJD) AddGoods(ctx context.Context, req *AddGoodsReq) (res *AddGoodsRe
} }
// 编辑商品 // 编辑商品
func (*goodsJD) UpdateGoods(ctx context.Context, req *AddGoodsReq) (res *AddGoodsRes, err error) { func (*goodsJD) UpdateGoods(ctx context.Context, req *UpdateGoodsReq) (res *AddGoodsRes, err error) {
method := "youzan.item.incremental.update/1.0.1" method := "youzan.item.incremental.update/1.0.1"
param := gconv.Map(req) param := gconv.Map(req)
result, err := server.requestApi(ctx, method, param) result, err := server.requestApi(ctx, method, param)
...@@ -134,14 +175,22 @@ func (*goodsJD) UploadImg(ctx context.Context, req *UplpadImgReq) (res *UplpadIm ...@@ -134,14 +175,22 @@ func (*goodsJD) UploadImg(ctx context.Context, req *UplpadImgReq) (res *UplpadIm
//} //}
result, err := server.requestApiImg(ctx, method, req.Image) result, err := server.requestApiImg(ctx, method, req.Image)
if err != nil { if err != nil {
g.Dump("111111123",err)
return return
} }
err = json.Unmarshal([]byte(result), &res) err = json.Unmarshal([]byte(result), &res)
g.Dump("11111112344444",err)
return return
} }
// 商品详情
func (*goodsJD) FindGoodsData(ctx context.Context, req *FindGoodsDataReq) (res *FindGoodsDataRes, err error) {
method := "youzan.item.detail.get/1.0.0"
param := gconv.Map(req)
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = json.Unmarshal([]byte(result), &res)
return
}
//type UpDateStockReq struct { //type UpDateStockReq struct {
// Quantity string `json:"quantity"` // Quantity string `json:"quantity"`
// ItemId string `json:"item_id"` // ItemId string `json:"item_id"`
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论