-
Notifications
You must be signed in to change notification settings - Fork 3
/
ship.order.packing_test.go
121 lines (112 loc) · 4.83 KB
/
ship.order.packing_test.go
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
package temu
import (
"github.com/hiscaler/gox/jsonx"
"github.com/hiscaler/temu-go/entity"
"github.com/stretchr/testify/assert"
"gopkg.in/guregu/null.v4"
"testing"
"time"
)
func TestShipOrderPackingService_Match(t *testing.T) {
req := ShipOrderPackingMatchRequest{
DeliveryOrderSnList: []string{"FH2408231977953"},
}
_, err := temuClient.Services.ShipOrder.Packing.Match(ctx, req)
assert.Nilf(t, err, "temuClient.Services.ShipOrder.Packing.Match(ctx, %s)", jsonx.ToJson(req, "{}"))
}
// TestShipOrderPackingService_SendForSelf 自送发货
func TestShipOrderPackingService_SendForSelf(t *testing.T) {
// 发货地址
addresses, err := temuClient.Services.Mall.Address.Query(ctx)
assert.Nilf(t, err, "temuClient.Services.Mall.Address.Query(ctx): error")
assert.Equal(t, true, len(addresses) > 0, "temuClient.Services.Mall.Address.Query(ctx): results")
address := addresses[0]
params := ShipOrderQueryParams{
Status: null.IntFrom(entity.ShipOrderStatusWaitingPacking),
}
params.PageSize = 1
items, _, _, _, err := temuClient.Services.ShipOrder.Query(ctx, params)
assert.Nilf(t, err, "temuClient.Services.ShipOrder.Query(ctx, %s)", jsonx.ToJson(params, "{}"))
if len(items) != 0 {
shipOrder := items[0]
// 必须打印箱唛
if !shipOrder.IsPrintBoxMark {
_, err = temuClient.Services.Goods.Barcode.BoxMark(ctx, shipOrder.DeliveryOrderSn)
assert.Nilf(t, err, "temuClient.Services.Goods.Barcode.BoxMark(ctx, %s)", shipOrder.DeliveryOrderSn)
}
driverName := shipOrder.DriverName
if driverName == "" {
driverName = "Zhang San"
}
req := ShipOrderPackingSendRequest{
DeliveryAddressId: address.ID,
DeliveryOrderSnList: []string{shipOrder.DeliveryOrderSn},
DeliverMethod: null.IntFrom(entity.DeliveryMethodSelf),
SelfDeliveryInfo: &ShipOrderPackingSendSelfDeliveryInformation{
// DriverUid: 0,
DriverName: driverName,
// PlateNumber: "",
// DeliveryContactNumber: "",
// DeliveryContactAreaNo: "",
ExpressPackageNum: len(shipOrder.PackageList),
},
}
_, err = temuClient.Services.ShipOrder.Packing.Send(ctx, req)
assert.Nilf(t, err, "temuClient.Services.ShipOrder.Packing.Send(ctx, %s)", jsonx.ToJson(req, "{}"))
} else {
t.Logf("not found waitingPackage status purchase order")
}
}
// TestShipOrderPackingService_SendForPlatformRecommendation 平台推荐物流发货
func TestShipOrderPackingService_SendForPlatformRecommendation(t *testing.T) {
// 发货地址
addresses, err := temuClient.Services.Mall.Address.Query(ctx)
assert.Nilf(t, err, "temuClient.Services.Mall.Address.Query(ctx): error")
assert.Equal(t, true, len(addresses) > 0, "temuClient.Services.Mall.Address.Query(ctx): results")
address := addresses[0]
// 快递公司
companies, err := temuClient.Services.Logistics.Companies(ctx)
assert.Nilf(t, err, "temuClient.Services.Logistics.Companies(ctx): error")
assert.Equal(t, true, len(companies) > 0, "temuClient.Services.Logistics.Companies(ctx): results")
company := companies[0]
params := ShipOrderQueryParams{
Status: null.IntFrom(entity.ShipOrderStatusWaitingPacking),
}
params.PageSize = 1
items, _, _, _, err := temuClient.Services.ShipOrder.Query(ctx, params)
assert.Nilf(t, err, "temuClient.Services.ShipOrder.Query(ctx, %s)", jsonx.ToJson(params, "{}"))
if len(items) != 0 {
shipOrder := items[0]
// 必须打印箱唛
if !shipOrder.IsPrintBoxMark {
_, err = temuClient.Services.Goods.Barcode.BoxMark(ctx, shipOrder.DeliveryOrderSn)
assert.Nilf(t, err, "temuClient.Services.Goods.Barcode.BoxMark(ctx, %s)", shipOrder.DeliveryOrderSn)
}
d, _ := time.ParseInLocation(time.DateTime, time.Now().Format(time.DateOnly)+" 18:00:00", temuClient.TimeLocation)
req := ShipOrderPackingSendRequest{
DeliveryAddressId: address.ID,
DeliveryOrderSnList: []string{shipOrder.DeliveryOrderSn},
DeliverMethod: null.IntFrom(entity.DeliveryMethodPlatformRecommendation),
ThirdPartyDeliveryInfo: &ShipOrderPackingSendPlatformRecommendationDeliveryInformation{
ExpressCompanyId: company.ShipId,
TmsChannelId: 0,
ExpressCompanyName: company.ShipName,
StandbyExpress: false,
ExpressDeliverySn: shipOrder.ExpressDeliverySn,
PredictTotalPackageWeight: shipOrder.PredictTotalPackageWeight,
ExpectPickUpGoodsTime: d.UnixMilli(),
ExpressPackageNum: len(shipOrder.PackageList),
MinChargeAmount: 0.01,
MaxChargeAmount: 0.02,
PredictId: 123, // ?
},
}
if req.ThirdPartyDeliveryInfo.PredictTotalPackageWeight < 1000 {
req.ThirdPartyDeliveryInfo.PredictTotalPackageWeight = 1000
}
_, err = temuClient.Services.ShipOrder.Packing.Send(ctx, req)
assert.Nilf(t, err, "temuClient.Services.ShipOrder.Packing.Send(ctx, %s)", jsonx.ToJson(req, "{}"))
} else {
t.Logf("not found waitingPackage status purchase order")
}
}