feat:采购日志
This commit is contained in:
@@ -374,6 +374,7 @@ func (r *RockPackageCreateResponse) ResolvePackage() (int64, string) {
|
||||
// CreatePackage 把一批已提取 Token 打包成公开分享包(需 Bearer Token)。
|
||||
// 注意:上游未返回 share_code 时不会在这里报错,由调用方决定兜底策略。
|
||||
func (c *RockClient) CreatePackage(ctx context.Context, bearerToken string, ids []string, note string) (*RockPackageCreateResponse, error) {
|
||||
startedAt := time.Now()
|
||||
if len(ids) == 0 {
|
||||
return nil, fmt.Errorf("打包 ids 不能为空")
|
||||
}
|
||||
@@ -404,6 +405,7 @@ func (c *RockClient) CreatePackage(ctx context.Context, bearerToken string, ids
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取 packages 创建响应失败: %w", err)
|
||||
}
|
||||
traceRockRequest(ctx, "package", http.MethodPost, reqURL, jsonBytes, resp.StatusCode, body, time.Since(startedAt), err)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("上游 packages 创建接口返回错误码 %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
@@ -420,6 +422,7 @@ func (c *RockClient) CreatePackage(ctx context.Context, bearerToken string, ids
|
||||
|
||||
// GetPackageDetail 按 share_code 查询打包详情(公开接口,无需 Bearer)。
|
||||
func (c *RockClient) GetPackageDetail(ctx context.Context, shareCode string) (*RockPackageDetailResponse, error) {
|
||||
startedAt := time.Now()
|
||||
shareCode = strings.TrimSpace(shareCode)
|
||||
if shareCode == "" {
|
||||
return nil, fmt.Errorf("share_code 不能为空")
|
||||
@@ -441,6 +444,7 @@ func (c *RockClient) GetPackageDetail(ctx context.Context, shareCode string) (*R
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取 package 详情响应失败: %w", err)
|
||||
}
|
||||
traceRockRequest(ctx, "detail", http.MethodGet, reqURL, nil, resp.StatusCode, body, time.Since(startedAt), err)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("上游 package 详情接口返回错误码 %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
@@ -456,6 +460,7 @@ func (c *RockClient) GetPackageDetail(ctx context.Context, shareCode string) (*R
|
||||
|
||||
// GetMe 获取商户个人信息及积分
|
||||
func (c *RockClient) GetMe(ctx context.Context, bearerToken string) (*RockMeResponse, error) {
|
||||
startedAt := time.Now()
|
||||
reqURL := fmt.Sprintf("%s/api/me", c.BaseURL())
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
|
||||
if err != nil {
|
||||
@@ -474,6 +479,7 @@ func (c *RockClient) GetMe(ctx context.Context, bearerToken string) (*RockMeResp
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取响应失败: %w", err)
|
||||
}
|
||||
traceRockRequest(ctx, "me", http.MethodGet, reqURL, nil, resp.StatusCode, body, time.Since(startedAt), err)
|
||||
|
||||
if resp.StatusCode == http.StatusUnauthorized {
|
||||
return nil, fmt.Errorf("上游 Bearer Token 已失效或未授权 (401)")
|
||||
@@ -532,6 +538,7 @@ func (r *RockDashboardResponse) ResolveBlueTokenCost() float64 {
|
||||
|
||||
// GetDashboard 获取上游可用库存与实时采购单价(需 Bearer Token)。
|
||||
func (c *RockClient) GetDashboard(ctx context.Context, bearerToken string) (*RockDashboardResponse, error) {
|
||||
startedAt := time.Now()
|
||||
reqURL := fmt.Sprintf("%s/api/user/dashboard", c.BaseURL())
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, reqURL, nil)
|
||||
if err != nil {
|
||||
@@ -552,6 +559,7 @@ func (c *RockClient) GetDashboard(ctx context.Context, bearerToken string) (*Roc
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取 dashboard 响应失败: %w", err)
|
||||
}
|
||||
traceRockRequest(ctx, "dashboard", http.MethodGet, reqURL, nil, resp.StatusCode, body, time.Since(startedAt), err)
|
||||
if resp.StatusCode == http.StatusUnauthorized {
|
||||
return nil, fmt.Errorf("上游 Bearer Token 已失效或未授权 (401)")
|
||||
}
|
||||
@@ -570,6 +578,7 @@ func (c *RockClient) GetDashboard(ctx context.Context, bearerToken string) (*Roc
|
||||
|
||||
// ClaimTokens 批量提取采购 Token
|
||||
func (c *RockClient) ClaimTokens(ctx context.Context, bearerToken string, color string, count int) ([]RockClaimedToken, error) {
|
||||
startedAt := time.Now()
|
||||
if count <= 0 {
|
||||
return nil, fmt.Errorf("提取数量必须大于 0")
|
||||
}
|
||||
@@ -600,6 +609,7 @@ func (c *RockClient) ClaimTokens(ctx context.Context, bearerToken string, color
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("读取 claim 响应失败: %w", err)
|
||||
}
|
||||
traceRockRequest(ctx, "claim", http.MethodPost, reqURL, jsonBytes, resp.StatusCode, body, time.Since(startedAt), err)
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("上游 claim 接口返回错误码 %d: %s", resp.StatusCode, string(body))
|
||||
|
||||
Reference in New Issue
Block a user