fix(delivery): 硬化自动发货可靠性,避免双发与无限 Webhook 重试

恢复 ship_failed 可重试 UI;DLC 断点续传 queue;乐玩未绑定禁止进 delivering;Webhook 原子 nonce 与业务拒绝回 200。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-09-14 20:13:29 +08:00
co-authored by Cursor
parent df1a170d44
commit c2d8228512
10 changed files with 235 additions and 29 deletions
@@ -33,6 +33,17 @@ type ShipNotifyResult struct {
Message string `json:"message"`
}
// ErrShipNotifyRejected 表示业务永久拒绝(如已取消/已交付拒失败),Webhook 应回 200 避免无限重试。
var ErrShipNotifyRejected = errors.New("ship notify rejected")
// wrapShipNotifyRejected 将永久拒绝包装为可识别错误。
func wrapShipNotifyRejected(err error) error {
if err == nil {
return ErrShipNotifyRejected
}
return errors.Join(ErrShipNotifyRejected, err)
}
// HandleShipNotify 处理上游发货结果推送(幂等),基于 FulfillmentOrder。
func (s *FulfillmentService) HandleShipNotify(in ShipNotifyInput) (*ShipNotifyResult, error) {
in.ShipStatus = strings.TrimSpace(in.ShipStatus)
@@ -97,7 +108,7 @@ func (s *FulfillmentService) HandleShipNotify(in ShipNotifyInput) (*ShipNotifyRe
if err := writeShipNotifyRejectedAudit(tx, &order, in, "订单已取消,拒绝更新"); err != nil {
return err
}
rejectionErr = errors.New("订单已取消,无法更新发货状态")
rejectionErr = wrapShipNotifyRejected(errors.New("订单已取消,无法更新发货状态"))
return nil
}
@@ -112,7 +123,7 @@ func (s *FulfillmentService) HandleShipNotify(in ShipNotifyInput) (*ShipNotifyRe
if err := writeShipNotifyRejectedAudit(tx, &order, in, message); err != nil {
return err
}
rejectionErr = err
rejectionErr = wrapShipNotifyRejected(err)
return nil
}
updates["delivered_at"] = shippedAt
@@ -130,7 +141,7 @@ func (s *FulfillmentService) HandleShipNotify(in ShipNotifyInput) (*ShipNotifyRe
if err := writeShipNotifyRejectedAudit(tx, &order, in, message); err != nil {
return err
}
rejectionErr = err
rejectionErr = wrapShipNotifyRejected(err)
return nil
}
updates["failure_reason"] = in.FailReason