feat: 统一蝦皮与顺运宝 PDD 关联入口 (#68)
This commit is contained in:
@@ -244,6 +244,27 @@ func GetShopeeProductByGoodsID(q Execer, goodsID string) (*model.ShopeeProduct,
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
// UpdateShopeePddLink 更新蝦皮商品当前关联的 PDD 商品。
|
||||
// 调用方必须先在同一事务里保证 PDD 商品存在,避免留下悬空关联。
|
||||
func UpdateShopeePddLink(q Execer, shopeeGoodsID, pddGoodsID, pddURL string) error {
|
||||
result, err := q.Exec(`
|
||||
UPDATE shopee_products
|
||||
SET pdd_goods_id = ?, pdd_goods_url = ?, updated_at = ?
|
||||
WHERE goods_id = ?`,
|
||||
pddGoodsID, pddURL, model.NowISO(), shopeeGoodsID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("更新蝦皮商品 %s 的 PDD 关联失败: %w", shopeeGoodsID, err)
|
||||
}
|
||||
n, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return fmt.Errorf("读取蝦皮商品 %s 的更新结果失败: %w", shopeeGoodsID, err)
|
||||
}
|
||||
if n != 1 {
|
||||
return fmt.Errorf("蝦皮商品 %s 不存在", shopeeGoodsID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetShopeeCollectStatus 查一个 PDD 商品的采集状态和失败原因。
|
||||
// pddGoodsID 为空(蝦皮商品还没填链接)或查不到对应的 pdd_products 行时,
|
||||
// 返回的两个 sql.NullString 都是 Valid=false,调用方按"未填链接"/"PDD 商品缺失"处理。
|
||||
|
||||
Reference in New Issue
Block a user