1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
package ali
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
)
type orderAli struct {
}
var Order = orderAli{}
type CreateOrderReq struct {
AddressParam AddressParam
CargoParam []CargoParam
OuterOrderInfo OuterOrderInfo
}
type AddressParam struct {
FullName string `json:"fullName"`
Mobile string `json:"mobile"`
Phone string `json:"phone"`
PostCode string `json:"postCode"`
CityText string `json:"cityText"`
ProvinceText string `json:"provinceText"`
AreaText string `json:"areaText"`
TownText string `json:"townText"`
Address string `json:"address"`
}
type CargoParam struct {
SpecId string `json:"specId"`
OfferId int64 `json:"offerId"`
Quantity int `json:"quantity"`
}
type OuterOrderInfo struct {
MediaOrderId string `json:"mediaOrderId"`
Phone string `json:"phone"`
Offers []Offer `json:"offers"`
}
type Offer struct {
SpecId string `json:"specId"`
Id int64 `json:"id"`
Num int `json:"num"`
Price int64 `json:"price"`
}
type CreateOrderRes struct {
*CommonRes
Result struct {
TotalSuccessAmount int64 `json:"totalSuccessAmount"` //下单成功的订单总金额,单位:分
OrderId string `json:"orderId"` //下单成功后的订单id
PostFee int64 `json:"postFee"` //原始运费,单位:分。注意:下单后卖家可能调整,因此该值可能不等于最终支付运费
} `json:"result,omitempty"`
}
type OrderDetailRes struct {
*CommonRes
Result struct {
BaseInfo struct {
PayTime string `json:"payTime"`
Discount int `json:"discount"`
AlipayTradeID string `json:"alipayTradeId"`
SumProductPayment float64 `json:"sumProductPayment"`
FlowTemplateCode string `json:"flowTemplateCode"`
SellerOrder bool `json:"sellerOrder"`
BuyerLoginID string `json:"buyerLoginId"`
ModifyTime string `json:"modifyTime"`
ID int64 `json:"id"`
BuyerContact struct {
Phone string `json:"phone"`
ImInPlatform string `json:"imInPlatform"`
Name string `json:"name"`
CompanyName string `json:"companyName"`
} `json:"buyerContact"`
SellerLoginID string `json:"sellerLoginId"`
BuyerID string `json:"buyerID"`
CloseOperateType string `json:"closeOperateType"`
TotalAmount float64 `json:"totalAmount"`
SellerID string `json:"sellerID"`
ShippingFee int `json:"shippingFee"`
Refund int `json:"refund"`
Status string `json:"status"`
RefundPayment int `json:"refundPayment"`
SellerContact struct {
Phone string `json:"phone"`
Email string `json:"email"`
ImInPlatform string `json:"imInPlatform"`
Name string `json:"name"`
Mobile string `json:"mobile"`
CompanyName string `json:"companyName"`
} `json:"sellerContact"`
CouponFee int `json:"couponFee"`
ReceiverInfo struct {
ToFullName string `json:"toFullName"`
ToDivisionCode string `json:"toDivisionCode"`
ToMobile string `json:"toMobile"`
ToPhone string `json:"toPhone"`
ToPost string `json:"toPost"`
ToArea string `json:"toArea"`
} `json:"receiverInfo"`
TradeType string `json:"tradeType"`
IDOfStr string `json:"idOfStr"`
StepPayAll bool `json:"stepPayAll"`
CreateTime string `json:"createTime"`
BusinessType string `json:"businessType"`
OverSeaOrder bool `json:"overSeaOrder"`
TradeTypeDesc string `json:"tradeTypeDesc"`
PayChannelList []string `json:"payChannelList"`
TradeTypeCode string `json:"tradeTypeCode"`
PayTimeout int `json:"payTimeout"`
PayTimeoutType int `json:"payTimeoutType"`
} `json:"baseInfo"`
OrderBizInfo struct {
OdsCyd bool `json:"odsCyd"`
CreditOrder bool `json:"creditOrder"`
} `json:"orderBizInfo"`
TradeTerms []struct {
Phase int64 `json:"phase"`
PayWayDesc string `json:"payWayDesc"`
ExpressPay bool `json:"expressPay"`
PayTime string `json:"payTime"`
PayStatusDesc string `json:"payStatusDesc"`
PayWay string `json:"payWay"`
CardPay bool `json:"cardPay"`
PayStatus string `json:"payStatus"`
PhasAmount float64 `json:"phasAmount"`
} `json:"tradeTerms"`
ProductItems []struct {
ItemAmount float64 `json:"itemAmount"`
Name string `json:"name"`
Price float64 `json:"price"`
ProductID int64 `json:"productID"`
ProductImgURL []string `json:"productImgUrl"`
ProductSnapshotURL string `json:"productSnapshotUrl"`
Quantity int `json:"quantity"`
Refund int `json:"refund"`
SkuID int64 `json:"skuID"`
Status string `json:"status"`
SubItemID int64 `json:"subItemID"`
Type string `json:"type"`
Unit string `json:"unit"`
GuaranteesTerms []struct {
AssuranceInfo string `json:"assuranceInfo"`
AssuranceType string `json:"assuranceType"`
QualityAssuranceType string `json:"qualityAssuranceType"`
} `json:"guaranteesTerms"`
ProductCargoNumber string `json:"productCargoNumber"`
SkuInfos []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfos"`
EntryDiscount int `json:"entryDiscount"`
SpecID string `json:"specId"`
QuantityFactor int `json:"quantityFactor"`
StatusStr string `json:"statusStr"`
LogisticsStatus int `json:"logisticsStatus"`
GmtCreate string `json:"gmtCreate"`
GmtModified string `json:"gmtModified"`
GmtPayExpireTime string `json:"gmtPayExpireTime"`
SubItemIDString string `json:"subItemIDString"`
} `json:"productItems"`
NativeLogistics struct {
Address string `json:"address"`
Area string `json:"area"`
AreaCode string `json:"areaCode"`
City string `json:"city"`
ContactPerson string `json:"contactPerson"`
Mobile string `json:"mobile"`
Province string `json:"province"`
Telephone string `json:"telephone"`
Zip string `json:"zip"`
} `json:"nativeLogistics"`
GuaranteesTerms struct {
AssuranceInfo string `json:"assuranceInfo"`
AssuranceType string `json:"assuranceType"`
QualityAssuranceType string `json:"qualityAssuranceType"`
} `json:"guaranteesTerms"`
OrderRateInfo struct {
BuyerRateStatus int `json:"buyerRateStatus"`
SellerRateStatus int `json:"sellerRateStatus"`
} `json:"orderRateInfo"`
ExtAttributes []interface{} `json:"extAttributes"`
} `json:"result"`
}
type ProductItems struct {
Status string `json:"status"` //子订单状态
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"` //总运费信息, 单位为分.
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"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"webSite": WebSite,
"orderId": orderSn,
})
_ = gjson.New(result).Scan(&res)
return
}
//Pay 支付
func (s *orderAli) Pay(ctx context.Context, orderSn string) (res *CommonRes, err error) {
method := "com.alibaba.trade/alibaba.trade.pay.protocolPay"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"orderId": orderSn,
})
_ = gjson.New(result).Scan(&res)
return
}
//BeforeCreate 验证订单商品
func (s *orderAli) BeforeCreate(ctx context.Context, req *CreateOrderReq) (res *BeforeCreateRes, err error) {
method := "com.alibaba.trade/alibaba.createOrder.preview4CybMedia"
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 获取物流信息
func (s *orderAli) Deliver(ctx context.Context, orderSn string) (res *DeliverRes, err error) {
method := "com.alibaba.logistics/alibaba.trade.getLogisticsTraceInfo.buyerView"
result, err := server.Post(ctx, method, g.Map{
"access_token": server.AccessToken,
"orderId": orderSn,
"webSite": WebSite,
})
_ = gjson.New(result).Scan(&res)
return
}
//GetLogisticCompany 物流公司
func (s *orderAli) GetLogisticCompany(ctx context.Context) (res *GetLogisticCompanyRes, 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
}