|
|
|
|
package order
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"git.oa00.com/go/jdsdk/address"
|
|
|
|
|
"git.oa00.com/go/jdsdk/config"
|
|
|
|
|
"git.oa00.com/go/jdsdk/request"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
freightFee = "jingdong.ctp.order.getFreightFee" // 运费
|
|
|
|
|
shipmentType = "jingdong.ctp.order.getShipmentType" // 配送方式
|
|
|
|
|
createOrder = "jingdong.ctp.order.submitOrder" // 创建订单
|
|
|
|
|
queryOrder = "jingdong.ctp.order.querySubmitOrder" // 查询订单
|
|
|
|
|
orderDetail = "jingdong.ctp.order.getOrderDetail" // 订单详情
|
|
|
|
|
orderCancel = "jingdong.ctp.order.cancelOrder" // 订单取消
|
|
|
|
|
orderTrajectory = "jingdong.ctp.order.getLogistics" // 订单轨迹
|
|
|
|
|
orderConfirm = "jingdong.ctp.order.confirmDelivery" // 确认收货
|
|
|
|
|
orderPush = "jingdong.ctp.order.pushOrder" // 订单推送
|
|
|
|
|
orderPayInfo = "jingdong.ctp.order.getOrderPayInfo" // 订单支付信息
|
|
|
|
|
|
|
|
|
|
NotSupport = 9 // 商品不支持当前地址配送
|
|
|
|
|
|
|
|
|
|
paymentType = 2 // 在线支付
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Order struct {
|
|
|
|
|
}
|
|
|
|
|
type SkuItem struct {
|
|
|
|
|
SkuPrice float64 `json:"skuPrice"` // 单价
|
|
|
|
|
SkuId string `json:"skuId"` // skuId
|
|
|
|
|
SkuName string `json:"skuName"` // skuName
|
|
|
|
|
Quantity uint `json:"quantity"` // 数量
|
|
|
|
|
}
|
|
|
|
|
type ApiFreightFeeParam struct {
|
|
|
|
|
SkuList []SkuItem `json:"skuList"` // 商品列表
|
|
|
|
|
OrderFee float64 `json:"orderFee"` // 商品总金额
|
|
|
|
|
Address address.Address `json:"address"` // 收货地址
|
|
|
|
|
}
|
|
|
|
|
type apiFreightFeeParam struct {
|
|
|
|
|
ApiFreightFeeParam
|
|
|
|
|
PaymentType uint `json:"paymentType"` // 支付方式。固定传2:在线支付
|
|
|
|
|
Pin string `json:"pin"` // 下单账号
|
|
|
|
|
}
|
|
|
|
|
type resFreightFee struct {
|
|
|
|
|
FreightFee float64 `json:"freightFee"` // 运费
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetFreightFee @Title 获取运费
|
|
|
|
|
func (o *Order) GetFreightFee(data ApiFreightFeeParam) (result resFreightFee, err error) {
|
|
|
|
|
err = request.ExecProtocol(freightFee, apiFreightFeeParam{
|
|
|
|
|
ApiFreightFeeParam: data,
|
|
|
|
|
PaymentType: paymentType,
|
|
|
|
|
Pin: config.SdkConfig.Pin,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type apiShipmentTypeParam struct {
|
|
|
|
|
apiFreightFeeParam
|
|
|
|
|
}
|
|
|
|
|
type skuShipmentType struct {
|
|
|
|
|
SkuId string `json:"skuId"` // skuId
|
|
|
|
|
ShipmentType uint `json:"shipmentType"` // 配送方式
|
|
|
|
|
}
|
|
|
|
|
type shipmentDetail struct {
|
|
|
|
|
GiftList []skuShipmentType `json:"giftList"` // 赠品sku列表
|
|
|
|
|
AttachmentList []skuShipmentType `json:"attachmentList"` // 附件sku信息
|
|
|
|
|
ShipmentType uint `json:"shipmentType"` // 配送方式
|
|
|
|
|
}
|
|
|
|
|
type shipmentItem struct {
|
|
|
|
|
ShipmentDetail shipmentDetail `json:"shipmentDetail"` // 配送明细
|
|
|
|
|
SkuId string `json:"skuId"` // skuId
|
|
|
|
|
}
|
|
|
|
|
type resShipmentType struct {
|
|
|
|
|
ShipmentType uint `json:"shipmentType"` // 配送方式。1:京东配送 2:京配转三方配送 3:第三方配送 4:普通快递配送 9:不支持配送
|
|
|
|
|
ShipmentInfoList []shipmentItem `json:"shipmentInfoList"` // 配送明细
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetShipmentType @Title 获取配送方式
|
|
|
|
|
func (o *Order) GetShipmentType(data ApiFreightFeeParam) (result resShipmentType, err error) {
|
|
|
|
|
err = request.ExecProtocol(shipmentType, apiShipmentTypeParam{
|
|
|
|
|
apiFreightFeeParam{
|
|
|
|
|
ApiFreightFeeParam: data,
|
|
|
|
|
PaymentType: paymentType,
|
|
|
|
|
Pin: config.SdkConfig.Pin,
|
|
|
|
|
},
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MainSku struct {
|
|
|
|
|
MainSku SkuItem `json:"mainSku"`
|
|
|
|
|
}
|
|
|
|
|
type Receiver struct {
|
|
|
|
|
ReceiverName string `json:"receiverName"` // 姓名
|
|
|
|
|
ReceiverMobile string `json:"receiverMobile"` // 手机号
|
|
|
|
|
ReceiverEmail string `json:"receiverEmail"` // 邮箱
|
|
|
|
|
ZipCode string `json:"zipCode"` // 邮编
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OrderParam struct {
|
|
|
|
|
ChannelOrderId string `json:"channelOrderId"` // 渠道订单号
|
|
|
|
|
ProductList []MainSku `json:"productList"` // 商品信息列表
|
|
|
|
|
OrderFee float64 `json:"orderFee"` // 总金额-不含运费
|
|
|
|
|
FreightFee float64 `json:"freightFee"` // 运费
|
|
|
|
|
Address address.Address `json:"address"` // 收货地址
|
|
|
|
|
Receiver Receiver `json:"receiver"` // 收货人
|
|
|
|
|
Invoice Invoice `json:"invoice"` // 发票信息
|
|
|
|
|
UserIp string `json:"userIp"` // 用户ip
|
|
|
|
|
ShipmentType uint `json:"shipmentType"` // 配送方式
|
|
|
|
|
AutoCancelTime uint `json:"autoCancelTime"` // 自动取消时间 秒
|
|
|
|
|
}
|
|
|
|
|
type Invoice struct {
|
|
|
|
|
InvoiceType uint `json:"invoiceType"` // 发票类型 2=增票 3=电子票
|
|
|
|
|
VatInvoice VatInvoice `json:"vatInvoice"` // 增值税发票信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type VatInvoiceAddress struct {
|
|
|
|
|
VatProvinceId uint `json:"vatProvinceId"` // 省
|
|
|
|
|
VatCityId uint `json:"vatCityId"` // 市
|
|
|
|
|
VatCountyId uint `json:"vatCountyId"` // 区
|
|
|
|
|
VatTownId uint `json:"vatTownId"` // 街道
|
|
|
|
|
VatFullAddress string `json:"vatFullAddress"` // 全地址
|
|
|
|
|
}
|
|
|
|
|
type VatInvoice struct {
|
|
|
|
|
CompanyName string `json:"companyName"` // 公司名
|
|
|
|
|
Code string `json:"code"` // 营业执照号
|
|
|
|
|
RegAddr string `json:"regAddr"` // 注册地址
|
|
|
|
|
RegPhone string `json:"regPhone"` // 注册手机
|
|
|
|
|
RegBank string `json:"regBank"` // 开户行
|
|
|
|
|
RegBankAccount string `json:"regBankAccount"` // 开户账号
|
|
|
|
|
ConsigneeName string `json:"consigneeName"` // 收件人
|
|
|
|
|
ConsigneeMobile string `json:"consigneeMobile"` // 收件电话
|
|
|
|
|
VatAddress VatInvoiceAddress `json:"vatAddress"` // 邮寄地址
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type param struct {
|
|
|
|
|
OrderParam
|
|
|
|
|
Pin string `json:"pin"` // 下单账号
|
|
|
|
|
PaymentType uint `json:"paymentType"` // 支付方式 2=在线支付
|
|
|
|
|
ChannelOrderSource string `json:"channelOrderSource"` // 订单来源 OTHER=其他
|
|
|
|
|
SendGoods uint `json:"sendGoods"` // 物品类型 固定1
|
|
|
|
|
}
|
|
|
|
|
type resOrder struct {
|
|
|
|
|
ChannelOrderId string `json:"channelOrderId"` // 渠道订单id
|
|
|
|
|
OrderId uint `json:"orderId"` // 京东订单id
|
|
|
|
|
ExtendInfo extendInfo `json:"extendInfo"` // 拓展属性
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type extendInfo struct {
|
|
|
|
|
Code string `json:"code"` // 返回码 0001=重复下单
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create @Title 下单
|
|
|
|
|
func (o *Order) Create(data OrderParam) (result resOrder, err error) {
|
|
|
|
|
err = request.ExecProtocol(createOrder, param{
|
|
|
|
|
OrderParam: data,
|
|
|
|
|
Pin: config.SdkConfig.Pin,
|
|
|
|
|
PaymentType: paymentType,
|
|
|
|
|
ChannelOrderSource: "OTHER",
|
|
|
|
|
SendGoods: 1,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Query @Title 订单查询
|
|
|
|
|
func (o *Order) Query(channelOrderId string) (result resOrder, err error) {
|
|
|
|
|
err = request.ExecParam(queryOrder, map[string]interface{}{
|
|
|
|
|
"channelOrderId": channelOrderId,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OrderInfo struct {
|
|
|
|
|
SkuList []orderSkuItem `json:"skuList"` // 商品列表
|
|
|
|
|
OrderId uint64 `json:"orderId"` // 订单号
|
|
|
|
|
BaseOrderInfo baseOrderInfo `json:"baseOrderInfo"` // 订单基本信息
|
|
|
|
|
OrderRelationFee orderRelationFee `json:"orderRelationFee"` // 订单费用信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type orderRelationFee struct {
|
|
|
|
|
ShouldPaymentFee float64 `json:"shouldPaymentFee"` // 订单总金额
|
|
|
|
|
DiscountFee float64 `json:"discountFee"` // 订单优惠金额
|
|
|
|
|
FreightFee float64 `json:"freightFee"` // 运费金额
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type baseOrderInfo struct {
|
|
|
|
|
RootOrderId uint64 `json:"rootOrderId"` // 父订单号
|
|
|
|
|
OrderStatus int `json:"orderStatus"` // 订单状态 -100=已取消 0=提单成功 1=等待付款 4=已支付 6=等待打印 7=拣货完成 8=出库完成 9=等待发货 15=待用户确认 16=用户拒收 18=用户签收 21=订单锁定
|
|
|
|
|
SubmitTime float64 `json:"submitTime"` // 订单创建时间
|
|
|
|
|
CompleteTime float64 `json:"completeTime"` // 订单完成时间
|
|
|
|
|
PayTime float64 `json:"payTime"` // 订单支付时间
|
|
|
|
|
OutWarehouseTime float64 `json:"outWarehouseTime"` // 订单出库时间
|
|
|
|
|
OrderType int `json:"orderType"` // 订单类型 0=自营/混单 1=商家自发订单 2=厂直订单 99=其他订单
|
|
|
|
|
Remark string `json:"remark"` // 订单备注
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type orderSkuItem struct {
|
|
|
|
|
SkuId uint64 `json:"skuId"` // skuId
|
|
|
|
|
SkuName string `json:"skuName"` // 商品名称
|
|
|
|
|
Quantity uint `json:"quantity"` // 数量
|
|
|
|
|
ShouldPrice float64 `json:"shouldPrice"` // 单价
|
|
|
|
|
SkuGiftType uint `json:"skuGiftType"` // sku类型 1=主品 2=赠品
|
|
|
|
|
MainSkuId uint64 `json:"mainSkuId"` // 赠品主skuId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Detail @Title 订单详情 京东订单id
|
|
|
|
|
func (o *Order) Detail(orderId string) (result OrderInfo, err error) {
|
|
|
|
|
err = request.ExecParam(orderDetail, map[string]interface{}{
|
|
|
|
|
"orderId": orderId,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cancel @Title 订单取消 京东订单id
|
|
|
|
|
func (o *Order) Cancel(orderId string) (result OrderInfo, err error) {
|
|
|
|
|
err = request.ExecParam(orderCancel, map[string]interface{}{
|
|
|
|
|
"orderId": orderId,
|
|
|
|
|
"cancelReasonCode": 100,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type resTrajectory struct {
|
|
|
|
|
WaybillCode string `json:"waybillCode"` // 运单号
|
|
|
|
|
OperatorNodeList []operatorNodeItem `json:"operatorNodeList"` // 轨迹
|
|
|
|
|
}
|
|
|
|
|
type operatorNodeItem struct {
|
|
|
|
|
Content string `json:"content"` // 详细信息
|
|
|
|
|
GroupState string `json:"groupState"` // 阶段状态
|
|
|
|
|
ScanState string `json:"scanState"` // 扫描状态
|
|
|
|
|
MsgTime int64 `json:"msgTime"` // 操作时间
|
|
|
|
|
SystemOperator string `json:"systemOperator"` // 操作人
|
|
|
|
|
OrderId uint64 `json:"orderId"` // 订单号
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trajectory @Title 订单轨迹
|
|
|
|
|
func (o *Order) Trajectory(orderId string) (result []resTrajectory, err error) {
|
|
|
|
|
err = request.ExecParam(orderTrajectory, map[string]interface{}{
|
|
|
|
|
"orderId": orderId,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Confirm @Title 确认收货
|
|
|
|
|
func (o *Order) Confirm(orderId string) (err error) {
|
|
|
|
|
err = request.ExecParam(orderConfirm, map[string]interface{}{
|
|
|
|
|
"orderId": orderId,
|
|
|
|
|
}, nil)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Push @Title 订单推送
|
|
|
|
|
func (o *Order) Push(orderId string) (err error) {
|
|
|
|
|
err = request.ExecParam(orderPush, map[string]interface{}{
|
|
|
|
|
"orderId": orderId,
|
|
|
|
|
}, nil)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type resPayInfo struct {
|
|
|
|
|
RefundTotalFee float64 `json:"refundTotalFee"` // 退款总金额
|
|
|
|
|
RootOrderId uint64 `json:"rootOrderId"` // 父订单号
|
|
|
|
|
ChannelOrderId uint64 `json:"channelOrderId"` // 渠道订单号
|
|
|
|
|
FreightFee float64 `json:"freightFee"` // 运费金额
|
|
|
|
|
PaidInTotalFee float64 `json:"paidInTotalFee"` // 实际支付金额
|
|
|
|
|
OrderFee float64 `json:"orderFee"` // 商品总金额
|
|
|
|
|
RefundDetailList []payRefundItem `json:"refundDetailList"` // 退款列表
|
|
|
|
|
PaidInDetailList []payItem `json:"paidInDetailList"` // 追夫列表
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type payRefundItem struct {
|
|
|
|
|
RefundFee float64 `json:"refundFee"` // 退款金额
|
|
|
|
|
RefundType float64 `json:"refundType"` // 退款类型 1=取消退款 2=售后退款 3=拆分取消非退款 4=多支付退款 5=其他退款类型
|
|
|
|
|
RefundTime int64 `json:"refundTime"` // 退款时间
|
|
|
|
|
}
|
|
|
|
|
type payItem struct {
|
|
|
|
|
PaidInFee float64 `json:"paidInFee"` // 支付金额
|
|
|
|
|
PaidInType float64 `json:"paidInType"` // 支付类型 2=在线支付
|
|
|
|
|
PaidInTime int64 `json:"paidInTime"` // 支付时间
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PayInfo @Title 订单支付信息
|
|
|
|
|
func (o *Order) PayInfo(orderId string) (result resPayInfo, err error) {
|
|
|
|
|
err = request.ExecParam(orderPayInfo, map[string]interface{}{
|
|
|
|
|
"orderId": orderId,
|
|
|
|
|
}, &result)
|
|
|
|
|
return
|
|
|
|
|
}
|