feat: 完善 Rock 发货异常闭环与绑定判定
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user