fix: 阻断规格重量数字误当货号 (#273)
This commit is contained in:
@@ -436,12 +436,12 @@ func innerCodeStallMatches(stall string, item syb.DetailItem) bool {
|
||||
}
|
||||
return innerCodeTextHasNumericArticle(sku, article) ||
|
||||
innerCodeTextHasNumericArticle(variation, article) ||
|
||||
innerCodeTextHasNumericArticle(item.ProductSpec, article)
|
||||
innerCodeProductSpecStartsWithArticle(item.ProductSpec, article, true)
|
||||
}
|
||||
|
||||
return innerCodeTextHasExactArticle(sku, article) ||
|
||||
innerCodeTextHasExactArticle(variation, article) ||
|
||||
innerCodeTextHasExactArticle(item.ProductSpec, article)
|
||||
innerCodeProductSpecStartsWithArticle(item.ProductSpec, article, false)
|
||||
}
|
||||
|
||||
// splitInnerCodeStall 从“档口名称#货号”取最后一个 #,避免档口名称本身含 # 时截错。
|
||||
@@ -493,6 +493,20 @@ func innerCodeTextHasExactArticle(text, article string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func innerCodeProductSpecStartsWithArticle(productSpec, article string, numeric bool) bool {
|
||||
productSpec = strings.TrimSpace(productSpec)
|
||||
separator := strings.IndexAny(productSpec, " ,,")
|
||||
if separator <= 0 {
|
||||
return false
|
||||
}
|
||||
prefix := strings.TrimSpace(productSpec[:separator])
|
||||
if numeric {
|
||||
return isInnerCodeNumericArticle(prefix) &&
|
||||
normalizeInnerCodeNumericArticle(prefix) == normalizeInnerCodeNumericArticle(article)
|
||||
}
|
||||
return prefix == article
|
||||
}
|
||||
|
||||
// innerCodeArticleTokens 只把连续字母或数字视为货号候选。
|
||||
// `【】`、`#`、横线、空格等标点自然成为边界,因此能识别 `067【档口】`,
|
||||
// 又不会把 `PDD256437` 中间的数字误认为独立货号。
|
||||
|
||||
@@ -254,6 +254,14 @@ func TestInnerCodeStallMatches_中文括号货号与数字前导零(t *testing.T
|
||||
}),
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "规格重量数字不能冒充货号",
|
||||
stall: "将客大码网批#067",
|
||||
item: innerCodeTestItem(6, "黑色,2XL【建議67.5-82.5公斤】", map[string]any{
|
||||
"sku": "将客大码网批-黑色-2XL",
|
||||
}),
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "非数字货号不做类似转换",
|
||||
stall: "A档#A01",
|
||||
|
||||
Reference in New Issue
Block a user