fix(dlc): 发货重试不再改写订单号

代练仓按原单号回查能不能发货。随机后缀查不到,正式单会失败。已有队列时应续发原单,不能换号。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-10-06 18:45:08 +08:00
co-authored by Cursor
parent c85b9f4173
commit a2c4eb59b6
2 changed files with 47 additions and 52 deletions
+34 -2
View File
@@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"time"
@@ -179,6 +180,39 @@ func TestSignProxyDoesNotRetryOnRateLimit(t *testing.T) {
}
}
func TestDLCCreateOrderQueueKeepsOriginalOrderSN(t *testing.T) {
const orderNo = "FO20261006180010b19fbe66ec3"
var requestedSN string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var body struct {
Path string `json:"path"`
Data map[string]interface{} `json:"data"`
}
_ = json.NewDecoder(r.Body).Decode(&body)
requestedSN, _ = body.Data["order_sn"].(string)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"code": 1,
"message": "该订单已有发货记录,请续发未完成项或重试失败项",
})
}))
defer server.Close()
p := NewDLCProvider(server.URL, "dlc", &http.Client{Timeout: 5 * time.Second})
_, sn, err := p.createOrderQueue("good-1", orderNo, "suit_romantic_destiny")
if err == nil {
t.Fatal("已有发货记录时应返回代练仓原文,不能换成新单号重试")
}
if !strings.Contains(err.Error(), "请续发未完成项或重试失败项") {
t.Fatalf("应保留代练仓原文,实际: %v", err)
}
if requestedSN != orderNo || sn != orderNo || strings.Contains(requestedSN, "_") {
t.Fatalf("请求单号被改写: requested=%s returned=%s", requestedSN, sn)
}
}
func TestSignProxyDoesNotRetryOnFormalOrderCreation(t *testing.T) {
var callCount int32
@@ -211,5 +245,3 @@ func TestSignProxyDoesNotRetryOnFormalOrderCreation(t *testing.T) {
t.Fatalf("正式下单接口预期只调用 1 次且不触发重试,实际调用: %d", finalCount)
}
}