提交 4cb05bd4 authored 作者: zhanglibo's avatar zhanglibo

阿里

上级 7cbe3ee7
...@@ -6,12 +6,12 @@ import ( ...@@ -6,12 +6,12 @@ import (
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
) )
type deliverAli struct { type logisticsAli struct {
} }
var Deliver = deliverAli{} var Logistics = logisticsAli{}
type DeliverInfosRes struct { type LogisticsInfosRes struct {
CommonRes CommonRes
Result []struct { Result []struct {
Sender struct { Sender struct {
...@@ -54,7 +54,7 @@ type DeliverInfosRes struct { ...@@ -54,7 +54,7 @@ type DeliverInfosRes struct {
} `json:"result"` } `json:"result"`
} }
type DeliverTraceRes struct { type LogisticsTraceRes struct {
CommonRes CommonRes
LogisticsTrace []struct { LogisticsTrace []struct {
LogisticsId string `json:"logisticsId"` LogisticsId string `json:"logisticsId"`
...@@ -68,7 +68,7 @@ type DeliverTraceRes struct { ...@@ -68,7 +68,7 @@ type DeliverTraceRes struct {
} }
//Info 物流详情 //Info 物流详情
func (*deliverAli) Info(ctx context.Context, orderSn string) (res *DeliverInfosRes, err error) { func (*logisticsAli) Info(ctx context.Context, orderSn string) (res *LogisticsInfosRes, err error) {
method := "com.alibaba.logistics/alibaba.trade.getLogisticsInfos.buyerView" method := "com.alibaba.logistics/alibaba.trade.getLogisticsInfos.buyerView"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken, "access_token": server.AccessToken,
...@@ -80,7 +80,7 @@ func (*deliverAli) Info(ctx context.Context, orderSn string) (res *DeliverInfosR ...@@ -80,7 +80,7 @@ func (*deliverAli) Info(ctx context.Context, orderSn string) (res *DeliverInfosR
} }
//Trace 物流轨迹 //Trace 物流轨迹
func (*deliverAli) Trace(ctx context.Context, orderSn string) (res *DeliverTraceRes, err error) { func (*logisticsAli) Trace(ctx context.Context, orderSn string) (res *LogisticsTraceRes, err error) {
method := "com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView" method := "com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken, "access_token": server.AccessToken,
...@@ -90,3 +90,24 @@ func (*deliverAli) Trace(ctx context.Context, orderSn string) (res *DeliverTrace ...@@ -90,3 +90,24 @@ func (*deliverAli) Trace(ctx context.Context, orderSn string) (res *DeliverTrace
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
} }
type LogisticsCompanyRes struct {
CommonRes
Result []LogisticsCompanyItem `json:"result"` //result
}
type LogisticsCompanyItem struct {
Id int64 `json:"id"`
CompanyName string `json:"companyName"` //物流公司名称
CompanyNo string `json:"companyNo"` // 物流公司编号
}
//Company 物流公司
func (s *logisticsAli) Company(ctx context.Context) (res *LogisticsCompanyRes, err error) {
method := "com.alibaba.logistics/alibaba.logistics.OpQueryLogisticCompanyList"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
})
_ = gjson.New(result).Scan(&res)
return
}
...@@ -11,13 +11,13 @@ type orderAli struct { ...@@ -11,13 +11,13 @@ type orderAli struct {
var Order = orderAli{} var Order = orderAli{}
type CreateOrderReq struct { type OrderCommonReq struct {
AddressParam AddressParam AddressParam OrderAddress
CargoParam []CargoParam CargoParam []OrderCargo
OuterOrderInfo OuterOrderInfo OuterOrderInfo OuterOrderInfo
} }
type AddressParam struct { type OrderAddress struct {
FullName string `json:"fullName"` FullName string `json:"fullName"`
Mobile string `json:"mobile"` Mobile string `json:"mobile"`
Phone string `json:"phone"` Phone string `json:"phone"`
...@@ -29,7 +29,7 @@ type AddressParam struct { ...@@ -29,7 +29,7 @@ type AddressParam struct {
Address string `json:"address"` Address string `json:"address"`
} }
type CargoParam struct { type OrderCargo struct {
SpecId string `json:"specId"` SpecId string `json:"specId"`
OfferId int64 `json:"offerId"` OfferId int64 `json:"offerId"`
Quantity int `json:"quantity"` Quantity int `json:"quantity"`
...@@ -38,17 +38,17 @@ type CargoParam struct { ...@@ -38,17 +38,17 @@ type CargoParam struct {
type OuterOrderInfo struct { type OuterOrderInfo struct {
MediaOrderId string `json:"mediaOrderId"` MediaOrderId string `json:"mediaOrderId"`
Phone string `json:"phone"` Phone string `json:"phone"`
Offers []Offer `json:"offers"` Offers []OrderOffer `json:"offers"`
} }
type Offer struct { type OrderOffer struct {
SpecId string `json:"specId"` SpecId string `json:"specId"`
Id int64 `json:"id"` Id int64 `json:"id"`
Num int `json:"num"` Num int `json:"num"`
Price int64 `json:"price"` Price int64 `json:"price"`
} }
type CreateOrderRes struct { type OrderCreateRes struct {
CommonRes CommonRes
Result struct { Result struct {
TotalSuccessAmount int64 `json:"totalSuccessAmount"` //下单成功的订单总金额,单位:分 TotalSuccessAmount int64 `json:"totalSuccessAmount"` //下单成功的订单总金额,单位:分
...@@ -57,6 +57,20 @@ type CreateOrderRes struct { ...@@ -57,6 +57,20 @@ type CreateOrderRes struct {
} `json:"result,omitempty"` } `json:"result,omitempty"`
} }
//Create 下单
func (s *orderAli) Create(ctx context.Context, req *OrderCommonReq) (res *OrderCreateRes, err error) {
method := "com.alibaba.trade/alibaba.trade.createOrder4CybMedia"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"addressParam": gjson.New(req.AddressParam).MustToJsonString(),
"cargoParamList": gjson.New(req.CargoParam).MustToJsonString(),
"outerOrderInfo": gjson.New(req.OuterOrderInfo).MustToJsonString(),
})
_ = gjson.New(result).Scan(&res)
return
}
type OrderDetailRes struct { type OrderDetailRes struct {
CommonRes CommonRes
Result struct { Result struct {
...@@ -187,92 +201,8 @@ type OrderDetailRes struct { ...@@ -187,92 +201,8 @@ type OrderDetailRes struct {
} `json:"result"` } `json:"result"`
} }
type ProductItems struct { //Detail 订单详情
Status string `json:"status"` //子订单状态 func (s *orderAli) Detail(ctx context.Context, orderSn string) (res *OrderDetailRes, err error) {
SubItemID int64 `json:"subItemID"` //子订单号,或商品明细条目ID
SubItemIDString string `json:"subItemIDString"` //子订单号,或商品明细条目ID
SkuID int64 `json:"skuID"` //skuID
ProductID int64 `json:"productID"` //产品ID(非在线产品为空)
Quantity int64 `json:"quantity"` //以unit为单位的数量
ItemAmount float64 `json:"itemAmount"` //实付金额,单位为元
Refund float64 `json:"refund"` //退款金额,单位为元
LogisticsStatus int `json:"logisticsStatus"` //1 未发货 2 已发货 3 已收货 4 已经退货 5 部分发货 8 还未创建物流订单
RefundIdForAs string `json:"refundIdForAs"` //售后退款单号
NativeLogistics struct {
LogisticsItems struct {
LogisticsCompanyId int64 `json:"logisticsCompanyId"` //物流公司Id
LogisticsCompanyNo int64 `json:"logisticsCompanyNo"` //物流公司编号
LogisticsCompanyName string `json:"logisticsCompanyName"` //物流公司名称
LogisticsBillNo string `json:"logisticsBillNo"` //物流公司运单号
Carriage float64 `json:"carriage"` //运费(单位为元)
DeliveredTime string `json:"deliveredTime"` //发货时间
} `json:"logisticsItems"` //运单明细
} `json:"nativeLogistics"` //国内物流
}
type BeforeCreateRes struct {
CommonRes
OrderPreviewResuslt []BeforeCreateItem `json:"orderPreviewResuslt"`
}
type BeforeCreateItem struct {
SumPayment int64 `json:"sumPayment"` //订单总费用, 单位为分
SumPaymentNoCarriage int64 `json:"sumPaymentNoCarriage"` //不包含运费的货品总费用, 单位为分.
AdditionalFee int64 `json:"additionalFee"` //附加费,单位,分
SumCarriage int64 `json:"sumCarriage"` //总运费信息, 单位为分.
ResultCode string `json:"resultCode"` //
ShopPromotionList []struct { //可用店铺级别优惠列表
PromotionId int64 `json:"promotionId"` //优惠券ID
} `json:"shopPromotionList"` //规格信息
Message string `json:"message"` //返回信息
CargoList []struct {
FinalUnitPrice float64 `json:"finalUnitPrice"` //最终单价
SpecId string `json:"specId"` //规格ID,offer内唯一
OfferId string `json:"offerId"` //规格ID,offer内唯一
} `json:"cargoList"` //规格信息
}
type DeliverRes struct {
CommonRes
LogisticsTrace []struct {
LogisticsBillNo string `json:"logisticsBillNo"` //物流单号,运单号
LogisticsId string `json:"logisticsId"` //物流信息ID
OrderId int64 `json:"orderId"` //订单编号
LogisticsCompanyName string `json:"LogisticsCompanyName"` //物流公司编码
LogisticsSteps []struct {
AcceptTime string `json:"acceptTime"` //物流跟踪单该步骤的时间
Remark string `json:"remark"` //备注,如:“在浙江浦江县公司进行下级地点扫描,即将发往:广东深圳公司”
} `json:"logisticsSteps"` //物流跟踪步骤
} `json:"logisticsTrace"` //跟踪单详情
}
type GetLogisticCompanyRes struct {
CommonRes
Result []CompanyInfo `json:"result"` //result
}
type CompanyInfo struct {
Id int64 `json:"id"`
CompanyName string `json:"companyName"` //物流公司名称
CompanyNo string `json:"companyNo"` // 物流公司编号
}
//CreateOrder 下单
func (s *orderAli) CreateOrder(ctx context.Context, req *CreateOrderReq) (res *CreateOrderRes, err error) {
method := "com.alibaba.trade/alibaba.trade.createOrder4CybMedia"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"addressParam": gjson.New(req.AddressParam).MustToJsonString(),
"cargoParamList": gjson.New(req.CargoParam).MustToJsonString(),
"outerOrderInfo": gjson.New(req.OuterOrderInfo).MustToJsonString(),
})
_ = gjson.New(result).Scan(&res)
return
}
//OrderDetail 订单详情
func (s *orderAli) OrderDetail(ctx context.Context, orderSn string) (res *OrderDetailRes, err error) {
method := "com.alibaba.trade/alibaba.trade.get.buyerView" method := "com.alibaba.trade/alibaba.trade.get.buyerView"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
...@@ -296,37 +226,36 @@ func (s *orderAli) Pay(ctx context.Context, orderSn string) (res *CommonRes, err ...@@ -296,37 +226,36 @@ func (s *orderAli) Pay(ctx context.Context, orderSn string) (res *CommonRes, err
return return
} }
//BeforeCreate 验证订单商品 type OrderBeforeRes struct {
func (s *orderAli) BeforeCreate(ctx context.Context, req *CreateOrderReq) (res *BeforeCreateRes, err error) { CommonRes
method := "com.alibaba.trade/alibaba.createOrder.preview4CybMedia" OrderPreviewResuslt []OrderBeforeItem `json:"orderPreviewResuslt"`
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"addressParam": gjson.New(req.AddressParam).MustToJsonString(),
"cargoParamList": gjson.New(req.CargoParam).MustToJsonString(),
})
_ = gjson.New(result).Scan(&res)
return
} }
//Deliver 获取物流信息 type OrderBeforeItem struct {
func (s *orderAli) Deliver(ctx context.Context, orderSn string) (res *DeliverRes, err error) { SumPayment int64 `json:"sumPayment"` //订单总费用, 单位为分
method := "com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView" SumPaymentNoCarriage int64 `json:"sumPaymentNoCarriage"` //不包含运费的货品总费用, 单位为分.
AdditionalFee int64 `json:"additionalFee"` //附加费,单位,分
result, err := server.Post(ctx, method, g.Map{ SumCarriage int64 `json:"sumCarriage"` //总运费信息, 单位为分.
"access_token": server.AccessToken, ResultCode string `json:"resultCode"` //
"orderId": orderSn, ShopPromotionList []struct { //可用店铺级别优惠列表
"webSite": WebSite, PromotionId int64 `json:"promotionId"` //优惠券ID
}) } `json:"shopPromotionList"` //规格信息
_ = gjson.New(result).Scan(&res) Message string `json:"message"` //返回信息
return CargoList []struct {
FinalUnitPrice float64 `json:"finalUnitPrice"` //最终单价
SpecId string `json:"specId"` //规格ID,offer内唯一
OfferId string `json:"offerId"` //规格ID,offer内唯一
} `json:"cargoList"` //规格信息
} }
//GetLogisticCompany 物流公司 //Before 验证订单商品
func (s *orderAli) GetLogisticCompany(ctx context.Context) (res *GetLogisticCompanyRes, err error) { func (s *orderAli) Before(ctx context.Context, req *OrderCommonReq) (res *OrderBeforeRes, err error) {
method := "com.alibaba.logistics/alibaba.logistics.OpQueryLogisticCompanyList" method := "com.alibaba.trade/alibaba.createOrder.preview4CybMedia"
result, err := server.Post(ctx, method, g.Map{ result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken, "access_token": server.AccessToken,
"addressParam": gjson.New(req.AddressParam).MustToJsonString(),
"cargoParamList": gjson.New(req.CargoParam).MustToJsonString(),
}) })
_ = gjson.New(result).Scan(&res) _ = gjson.New(result).Scan(&res)
return return
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论