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
package jingdong
import (
"context"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
type orderJD struct {
}
// Order 订单
var Order = orderJD{}
// PriceSnap 商品价格
type PriceSnap struct {
SkuID int64 `json:"skuId"` //商品编号
Price float64 `json:"price"` //商品价格 格式:21.30
}
// OrderCreateReq 下单
type OrderCreateReq struct {
OrderSn string //订单单号
SkuNums []*SkuNums
Consignee string //收货人姓名,最多20个字符
Phone string //手机号,最多20个字符
Address *PlaceOrderAddress
PriceSnap []*PriceSnap
InvoiceType InvoiceType
}
// PlaceOrderAddress 下单地址
type PlaceOrderAddress struct {
Province string //一级地址编码
City string //二级地址编码
County string //三级地址编码
Town string //四级地址编码
Desc string //收货人详细地址,最多100个字符
}
// OrderCreateRes 下单
type OrderCreateRes struct {
*CommonRes
Result struct {
JdOrderID int64 `json:"jdOrderId"` //京东订单号
OrderPrice float64 `json:"orderPrice"` //订单总金额
OrderNakedPrice float64 `json:"orderNakedPrice"` //订单未税金额
OrderTaxPrice float64 `json:"orderTaxPrice"` //订单税额
Sku []*OrderSkuItem `json:"sku"`
} `json:"result"`
}
// OrderSkuItem 订单商品
type OrderSkuItem struct {
SkuID int64 `json:"skuId"` //商品编号
Num int `json:"num"` //商品数量
Price float64 `json:"price"` //商品单价
Name string `json:"name"` //商品名称
NakedPrice float64 `json:"nakedPrice"` //商品未税价
}
// OrderReflectRes 反查订单
type OrderReflectRes struct {
*CommonRes
Result string `json:"result"` //第三方订单号(非京东订单号)
}
type OrderDetailBase struct {
*CommonRes
Result struct {
JdOrderID int64 `json:"jdOrderId"` //京东订单编号
Type int `json:"type"` //订单类型。1是父订单 2是子订单
}
}
// OrderDetailRes 订单详情
// jdOrderState 京东状态
// 1.新单 2.等待支付 3.等待支付确认 4.延迟付款确认 5.订单暂停 6.店长最终审核 7.等待打印 8.等待出库 9.等待打包 10.等待发货
// 11.自提途中 12.上门提货 13.自提退货 14.确认自提 16.等待确认收货 17.配送退货 18.货到付款确认 19.已完成 21.收款确认 22.锁定
type OrderDetailRes struct {
CommonRes
Result struct {
JdOrderState int `json:"jdOrderState"` //京东状态
SubmitState int `json:"submitState"` //预占确认状态。0没确认预占。 1已确认预占。
Type int `json:"type"` //订单类型。1是父订单 2是子订单
OrderState int `json:"orderState"` //订单状态。0为取消订单 1为有效
POrder OrderDetailPOrder `json:"pOrder"`
COrder []OrderDetailCOrder `json:"cOrder"`
} `json:"result"`
}
type OrderDetailPOrder struct {
JdOrderId int64 `json:"jdOrderId"` //京东主订单编号
Freight float64 `json:"freight"` //运费
OrderPrice float64 `json:"orderPrice"` //订单总金额
OrderNakedPrice float64 `json:"orderNakedPrice"` //订单未含税金额
OrderTaxPrice float64 `json:"orderTaxPrice"` //订单税额
Sku []OrderSkuItem `json:"sku"` //商品列表
}
type OrderDetailCOrder struct {
POrder int64 `json:"pOrder"` //京东主订单编号
OrderState int `json:"orderState"`
JdOrderState int `json:"jdOrderState"` //1.新单 2.等待支付 3.等待支付确认 4.延迟付款确认 5.订单暂停 6.店长最终审核
// 7.等待打印 8.等待出库 9.等待打包 10.等待发货 11.自提途中 12.上门提货 13.自提退货 14.确认自提
// 16.等待确认收货 17.配送退货 18.货到付款确认 19.已完成 21.收款确认 22.锁定
JdOrderId int64 `json:"jdOrderId"` //京东子订单编号
State int `json:"state"`
Freight float64 `json:"freight"`
SubmitState int `json:"submitState"`
OrderPrice float64 `json:"orderPrice"`
OrderNakedPrice float64 `json:"orderNakedPrice"`
Type int `json:"type"` //商品类型。 0 普通、1 附件、2 赠品、3延保
OrderTaxPrice float64 `json:"orderTaxPrice"`
Sku []OrderSkuItem `json:"sku"`
}
type OrderDetailChild struct {
CommonRes
Result struct {
JdOrderState int `json:"jdOrderState"` //京东状态
OrderDetailCOrder
} `json:"result"`
}
// OrderFreightRes 运费
type OrderFreightRes struct {
*CommonRes
Result struct {
Freight float64 `json:"freight"` //总运费
BaseFreight float64 `json:"baseFreight"` //基础运费
RemoteRegionFreight float64 `json:"remoteRegionFreight"` //偏远地区加收运费
} `json:"result"`
}
// SkuNums 商品数量
type SkuNums struct {
SkuID int64 `json:"skuId"` //商品编号
Num int `json:"num"` //商品数量
}
// Create 下单
func (*orderJD) Create(ctx context.Context, req *OrderCreateReq) (res *OrderCreateRes, err error) {
method := "order/submitOrder"
var param = g.Map{
"thirdOrder": req.OrderSn,
"sku": gjson.New(req.SkuNums).MustToJsonString(),
"orderPriceSnap": gjson.New(req.PriceSnap).MustToJsonString(),
"name": req.Consignee,
"mobile": req.Phone,
"province": req.Address.Province,
"city": req.Address.City,
"county": req.Address.County,
"town": req.Address.Town,
"address": req.Address.Desc,
"email": server.Email,
"companyName": server.CompanyName,
"submitState": server.SubmitState,
"invoicePhone": server.Mobile,
"invoiceState": "2",
"invoiceType": req.InvoiceType,
"selectedInvoiceTitle": "5",
"invoiceContent": "1",
"paymentType": "4",
"isUseBalance": "1",
"doOrderPriceMode": "1",
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
// Reflect 反查订单
func (*orderJD) Reflect(ctx context.Context, thirdOrder string) (res *OrderReflectRes, err error) {
method := "order/selectJdOrderIdByThirdOrder"
param := g.Map{
"thirdOrder": thirdOrder,
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
// Detail 订单详情
func (*orderJD) Detail(ctx context.Context, OrderID string) (res *OrderDetailRes, err error) {
method := "order/selectJdOrder"
param := g.Map{
"jdOrderId": gconv.Int64(OrderID),
"queryExts": "jdOrderState",
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
var base *OrderDetailBase
_ = gjson.New(result).Scan(&base)
if base.Result.Type == 1 {
_ = gjson.New(result).Scan(&res)
return
} else {
var child *OrderDetailChild
_ = gjson.New(result).Scan(&child)
res = &OrderDetailRes{}
res.CommonRes = child.CommonRes
res.Result.Type = child.Result.Type
res.Result.SubmitState = child.Result.SubmitState
res.Result.OrderState = child.Result.OrderState
res.Result.JdOrderState = child.Result.JdOrderState
res.Result.POrder = OrderDetailPOrder{
JdOrderId: child.Result.JdOrderId,
Freight: child.Result.Freight,
OrderPrice: child.Result.OrderPrice,
OrderNakedPrice: child.Result.OrderNakedPrice,
OrderTaxPrice: child.Result.OrderTaxPrice,
Sku: child.Result.Sku,
}
child.Result.OrderDetailCOrder.POrder = child.Result.OrderDetailCOrder.JdOrderId
res.Result.COrder = append(res.Result.COrder, child.Result.OrderDetailCOrder)
}
return
}
// Freight 查询运费
func (*orderJD) Freight(ctx context.Context, sku []*SkuNums, province, city, county, town string) (res *OrderFreightRes, err error) {
method := "order/getFreight"
param := g.Map{
"sku": gjson.New(sku).MustToJsonString(),
"province": province,
"city": city,
"county": county,
"town": town,
"paymentType": "4",
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}
// Confirm 确认收货
func (*orderJD) Confirm(ctx context.Context, OrderID string) (res *CommonRes, err error) {
method := "order/confirmReceived"
param := g.Map{
"jdOrderId": gconv.Int64(OrderID),
}
result, err := server.requestApi(ctx, method, param)
if err != nil {
return
}
err = gjson.New(result).Scan(&res)
return
}