feat: 完善 Rock 发货异常闭环与绑定判定

This commit is contained in:
yml
2026-11-14 23:58:57 +08:00
parent 9353b439a7
commit 6a87fe5228
45 changed files with 3497 additions and 389 deletions
+11 -14
View File
@@ -30,7 +30,7 @@ func (s *RockService) importPackageDetail(ctx context.Context, detail *RockPacka
continue
}
upstreamID := strconv.FormatInt(pt.ID, 10)
status := normalizeRockPackageStatus(pt.Status)
status := rockStatusFromPackageToken(pt)
raw, marshalErr := json.Marshal(pt)
if marshalErr != nil {
raw = []byte(`{}`)
@@ -174,22 +174,19 @@ func (s *RockService) importPackageDetail(ctx context.Context, detail *RockPacka
return inserted, updated, skipped, err
}
func normalizeRockPackageStatus(status string) string {
switch strings.TrimSpace(status) {
case model.RockStatusAvailable:
return model.RockStatusAvailable
case model.RockStatusUsing:
return model.RockStatusUsing
case model.RockStatusBound:
return model.RockStatusBound
case model.RockStatusRedeemed:
// rockStatusFromPackageToken 以真实事件字段推导状态,避免 status=bound 的历史残留污染库存。
func rockStatusFromPackageToken(token RockPackageToken) string {
if strings.TrimSpace(token.RedeemedAt) != "" {
return model.RockStatusRedeemed
case model.RockStatusMismatch:
return model.RockStatusMismatch
default:
// 未知上游状态默认落 abnormal,避免被错误分配为可用库存。
}
if strings.TrimSpace(token.BindChangedAt) != "" {
return model.RockStatusBound
}
if strings.TrimSpace(token.BindChangeType) != "" {
// 只有事件类型没有时间,无法判定真实状态,保守落异常等待人工核对。
return model.RockStatusAbnormal
}
return model.RockStatusAvailable
}
func parseRockPackageTime(raw string) *time.Time {