package repository import ( "fmt" "cmautobuy/admin/model" ) // SetCollectResult 把采集回来的 PDD 商品数据存到商品级。 // // `[必须]` pdd_data 存在**商品级**(shopee_products),不是订单级—— // 一个 PDD 商品采一次,所有相关订单共用这份结果。 // 见 docs/admin/03-data-model.md §3.1。 func SetCollectResult(q Execer, goodsID, pddData string) error { if goodsID == "" { return nil // 任务没关联蝦皮商品(比如手工造的测试任务),跳过 } now := model.NowISO() _, err := q.Exec(` UPDATE shopee_products SET pdd_data = ?, collect_status = 'collected', collect_error = NULL, collected_at = ?, updated_at = ? WHERE goods_id = ?`, pddData, now, now, goodsID) if err != nil { return fmt.Errorf("保存商品 %s 的采集结果失败: %w", goodsID, err) } return nil } // SetCollectFailed 标记采集失败,并记下原因。 // // 错误信息要能在界面上看见,否则操作员不知道为什么采不到。 func SetCollectFailed(q Execer, goodsID, errMsg string) error { if goodsID == "" { return nil } now := model.NowISO() _, err := q.Exec(` UPDATE shopee_products SET collect_status = 'failed', collect_error = ?, updated_at = ? WHERE goods_id = ?`, errMsg, now, goodsID) if err != nil { return fmt.Errorf("标记商品 %s 采集失败出错: %w", goodsID, err) } return nil }