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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
package itao
import (
"context"
"fmt"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/util/gconv"
)
type order struct {
}
var Order = order{}
type OrderBeforeReq struct {
Address OrderAddress `json:"deliveryAddressInfo"`
List []OrderItem `json:"itemRequestList"`
}
type OrderAddress struct {
AddressDetail string `json:"addressDetail"`
City string `json:"city"`
CityId int64 `json:"cityId"`
Area string `json:"district"`
AreaId int64 `json:"districtId"`
FullName string `json:"fullName"`
Mobile string `json:"mobile"`
Prov string `json:"prov"`
ProvId int64 `json:"provId"`
Town string `json:"town"`
TownId int64 `json:"townId"`
}
type OrderItem struct {
Info struct {
ItemId int64 `json:"itemId"`
SkuId int64 `json:"skuId"`
} `json:"itemInfo"`
Quantity uint `json:"quantity"`
}
type OrderBeforeRes struct {
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
Success bool `json:"success"`
GwTraceId string `json:"gw_trace_id"`
Result struct {
ExtensionResp struct {
TradeId string `json:"tradeId"`
} `json:"extensionResp"`
InvalidOrderGroups []struct { //不可售商品
Image string `json:"image"`
OrderLineRenders []struct {
ErrorMessage struct {
ErrorCode string `json:"errorCode"`
ErrorMsg string `json:"errorMsg"`
} `json:"errorMessage"`
ItemInfo struct {
ItemId string `json:"itemId"`
SkuId string `json:"skuId"`
} `json:"itemInfo"`
ItemPayPrice uint `json:"itemPayPrice"`
OrderLineId int64 `json:"orderLineId"`
Quantity uint `json:"quantity"`
} `json:"orderLineRenders"`
OrderPayPrice int `json:"orderPayPrice"`
Quantity uint `json:"quantity"`
SellerToken string `json:"sellerToken"`
Title string `json:"title"`
} `json:"invalidOrderGroups"`
OriginPriceFee uint `json:"originPriceFee"`
PriceFee uint `json:"priceFee"` //单位分
PromotionResp OrderPromotion `json:"promotionResp"`
Quantity uint `json:"quantity"`
RealPayPrice uint `json:"realPayPrice"`
ReceiveMethodInfo struct {
DeliveryAddressId int `json:"deliveryAddressId"`
Options []interface{} `json:"options"`
} `json:"receiveMethodInfo"`
ValidOrderGroups []struct { //可售商品
DeliveryMethodInfo struct {
DeliveryMethodOptionList []struct {
FareCent uint `json:"fareCent"` //运费 单位分
Id string `json:"id"`
ServiceType int `json:"serviceType"`
} `json:"deliveryMethodOptionList"`
SelectedId string `json:"selectedId"`
} `json:"deliveryMethodInfo"`
Image string `json:"image"`
OrderLineRenders []struct {
ErrorMessage struct {
ErrorCode string `json:"errorCode"`
ErrorMsg string `json:"errorMsg"`
}
ItemInfo struct {
ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price string `json:"price"`
SkuId string `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
ItemPayPrice uint `json:"itemPayPrice"`
OrderLineId int64 `json:"orderLineId"`
Quantity uint `json:"quantity"`
} `json:"orderLineRenders"`
OrderPayPrice int `json:"orderPayPrice"`
PostFee int `json:"postFee"`
Quantity int `json:"quantity"`
SellerToken string `json:"sellerToken"`
Title string `json:"title"`
} `json:"validOrderGroups"`
} `json:"result"`
}
type OrderPromotion struct {
CrossShopPromotions []struct {
Discount int `json:"discount"`
IdValues []string `json:"idValues"`
PromotionKey string `json:"promotionKey"`
} `json:"crossShopPromotions"`
InvalidPromotions []interface {
} `json:"invalidPromotions"`
ItemPromotions []struct {
HasPromotion bool `json:"hasPromotion"`
IdValues []interface {
} `json:"idValues"`
OrderLineId int64 `json:"orderLineId"`
PromotionPriceMap struct {
LtaoMonthPkCard int `json:"ltaoMonthPkCard"`
} `json:"promotionPriceMap"`
} `json:"itemPromotions"`
ShopPromotions []struct {
Discount int `json:"discount"`
GoldStandardDiscount int `json:"goldStandardDiscount"`
HasShopPromotion bool `json:"hasShopPromotion"`
IdValues []interface {
} `json:"idValues"`
OutId string `json:"outId"`
SellerToken string `json:"sellerToken"`
} `json:"shopPromotions"`
}
//Before 前置校验
func (s order) Before(ctx context.Context, req OrderBeforeReq) (res *OrderBeforeRes, err error) {
method := "tt.order.render"
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type OrderCreateReq struct {
Address OrderAddress `json:"deliveryAddressInfo"`
List []OrderCreateItem `json:"orderDTOs"`
PromotionResp OrderPromotion `json:"promotionResp"`
}
type OrderCreateItem struct {
DTO []OrderCreateDto `json:"orderLineDTOs"`
OrderSn string `json:"outId"`
Token string `json:"sellerToken"`
}
type OrderCreateDto struct {
GoodsID int64 `json:"itemId"`
SkuId int64 `json:"skuId"`
Quantity uint `json:"buyQuantity"`
LineId int64 `json:"orderLineId"`
}
type OrderCreateRes struct {
CommonRes
Result struct {
AlipaySuccess bool `json:"alipaySuccess"`
EnablingOrdersResult struct {
Model struct {
AlipayTradeIds []string `json:"alipayTradeIds"`
OrderIds []string `json:"orderIds"`
} `json:"model"`
} `json:"enablingOrdersResult"`
ExtensionResult struct {
TraceId string `json:"traceId"`
} `json:"extensionResult"`
PartSuccess bool `json:"partSuccess"`
} `json:"result"`
}
//Create 下单
func (s order) Create(ctx context.Context, req OrderCreateReq) (res *OrderCreateRes, err error) {
method := "tt.order.create"
for k, item := range req.List {
req.List[k].OrderSn = s.outId(item.OrderSn)
}
result, err := server.Post(ctx, method, g.Map{
"request": req,
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
func (s order) outId(req string) (res string) {
res = gstr.SubStr(req, 2, -1)
res = gstr.Replace(res, "_15_", "_")
return fmt.Sprintf("%s_%s", server.AppKey, res)
}
type OrderDetailRes struct {
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
Result struct {
BizOrderId string `json:"bizOrderId"`
BuyAmount int `json:"buyAmount"`
BuyerToken string `json:"buyerToken"`
Detail int `json:"detail"`
DetailOrderList []struct {
BizOrderId string `json:"bizOrderId"`
BuyAmount int `json:"buyAmount"`
BuyerToken string `json:"buyerToken"`
Detail int `json:"detail"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price string `json:"price"`
SkuId int64 `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee int `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PayTime string `json:"payTime"`
PostFee int `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"detailOrderList"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId int64 `json:"itemId"`
Pic string `json:"pic"`
Price string `json:"price"`
SkuId int64 `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee int `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PayTime string `json:"payTime"`
PostFee int `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"result"`
}
//Detail 详情
func (s order) Detail(ctx context.Context, req interface{}) (res *OrderDetailRes, err error) {
method := "tt.order.detail"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": gconv.Int64(req),
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type OrderReflectRes struct {
Success bool `json:"success"`
ErrMsg string `json:"errMsg"`
ErrCode string `json:"errCode"`
Result struct {
BizOrderId string `json:"bizOrderId"`
BuyAmount uint `json:"buyAmount"`
BuyerToken string `json:"buyerToken"`
Detail int `json:"detail"`
DetailOrderList []struct {
BizOrderId string `json:"bizOrderId"`
BuyAmount uint `json:"buyAmount"`
BuyerToken string `json:"buyerToken"`
Detail int `json:"detail"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId string `json:"itemId"`
Pic string `json:"pic"`
Price uint `json:"price"`
SkuId string `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId int64 `json:"parentId"`
PayFee uint `json:"payFee"`
PayOrderId int64 `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PostFee uint `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"detailOrderList"`
GmtCreate string `json:"gmtCreate"`
ItemInfo struct {
ItemId string `json:"itemId"`
Pic string `json:"pic"`
Price uint `json:"price"`
SkuId string `json:"skuId"`
SkuInfoList []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"skuInfoList"`
Title string `json:"title"`
} `json:"itemInfo"`
LogisticsOrderId int64 `json:"logisticsOrderId"`
LogisticsStatus int `json:"logisticsStatus"`
//1 - 未发货 -> 等待卖家发货
//2 - 已发货 -> 等待买家确认收货
//3 - 已收货 -> 交易成功
//4 - 已经退货 -> 交易失败
//5 - 部分收货 -> 交易成功
//6 - 部分发货中
//8 - 还未创建物流订单
Main int `json:"main"`
ParentId string `json:"parentId"`
PayFee uint `json:"payFee"`
PayOrderId string `json:"payOrderId"`
PayStatus int `json:"payStatus"`
//1 - 未冻结/未付款 -> 等待买家付款
//2 - 已冻结/已付款 -> 等待卖家发货
//4 - 已退款 -> 交易关闭
//6 - 已转交易 -> 交易成功
//7 - 没有创建外部交易
//8 - 交易被关闭
//9 - 不可付款
PostFee uint `json:"postFee"`
RefundStatus int `json:"refundStatus"`
SellerToken string `json:"sellerToken"`
Status int `json:"status"`
} `json:"result"`
}
//Reflect 详情[反查]
func (s order) Reflect(ctx context.Context, req string) (res *OrderReflectRes, err error) {
method := "tt.order.detail.outid"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"outOrderId": s.outId(req),
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}
type OrderPayRes struct {
Result struct {
Result struct {
Result string `json:"result"`
Success bool `json:"success"`
ErrCode string `json:"errCode"`
ErrMsg string `json:"errMsg"`
} `json:"result"`
} `json:"result"`
}
func (s order) Pay(ctx context.Context, req string) (res *OrderPayRes, err error) {
method := "tt.agreementpay.dopay"
result, err := server.Post(ctx, method, g.Map{
"request": g.Map{
"bizOrderId": gconv.Int64(req),
},
})
_ = gjson.NewWithOptions(result, gjson.Options{
StrNumber: true,
}).Scan(&res)
return
}