feat 修改获取最低价返回值

This commit is contained in:
timerzz 2024-09-02 21:08:17 +08:00
parent a19977d88f
commit 235a5f1bd6
2 changed files with 19 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package dw_sdk
import ( import (
"fmt" "fmt"
"net/http"
"github.com/bytedance/sonic" "github.com/bytedance/sonic"
"github.com/gofiber/fiber/v3/client" "github.com/gofiber/fiber/v3/client"
@ -14,7 +15,7 @@ import (
//https://open.dewu.com/#/api/body?apiId=42&id=3&title=%E5%87%BA%E4%BB%B7%E6%9C%8D%E5%8A%A1API //https://open.dewu.com/#/api/body?apiId=42&id=3&title=%E5%87%BA%E4%BB%B7%E6%9C%8D%E5%8A%A1API
type BidClient interface { type BidClient interface {
LowestPrice(skuId int) (*PublicResponse[LowestPriceResponse], error) LowestPrice(skuId int) (LowestPriceResponse, error)
} }
type ConsignBidClientImpl struct { type ConsignBidClientImpl struct {
@ -62,9 +63,9 @@ type LowestPriceItem struct {
BiddingType BiddingType `json:"bidding_type"` BiddingType BiddingType `json:"bidding_type"`
} }
func (a *ConsignBidClientImpl) LowestPrice(skuId int) (*PublicResponse[LowestPriceResponse], error) { func (a *ConsignBidClientImpl) LowestPrice(skuId int) (LowestPriceResponse, error) {
if skuId == 0 { if skuId == 0 {
return nil, Err_Params_None return LowestPriceResponse{}, Err_Params_None
} }
data := LowestPriceReq{ data := LowestPriceReq{
PublicParams: PublicParams{ PublicParams: PublicParams{
@ -81,12 +82,15 @@ func (a *ConsignBidClientImpl) LowestPrice(skuId int) (*PublicResponse[LowestPri
response, err := r.SetJSON(data).Post(FastLowestPriceUrl) response, err := r.SetJSON(data).Post(FastLowestPriceUrl)
if err != nil { if err != nil {
return nil, errors.Wrapf(Err_Request_Err, "consign/bidding/lowest_price err:%v", err) return LowestPriceResponse{}, errors.Wrapf(Err_Request_Err, "consign/bidding/lowest_price err:%v", err)
} }
defer client.ReleaseResponse(response) defer client.ReleaseResponse(response)
var resp PublicResponse[LowestPriceResponse] var resp PublicResponse[LowestPriceResponse]
if err = response.JSON(&resp); err != nil { if err = response.JSON(&resp); err != nil {
return nil, errors.Wrapf(Err_JSON_UNMarshal, "consign/bidding/lowest_price err:%v", err) return LowestPriceResponse{}, errors.Wrapf(Err_JSON_UNMarshal, "consign/bidding/lowest_price err:%v", err)
} }
return &resp, nil if resp.Code != http.StatusOK {
return LowestPriceResponse{}, errors.Wrapf(Err_Request_Err, "consign/bidding/lowest_price resp.msg:%v", resp.Msg)
}
return resp.Data, nil
} }

View File

@ -2,6 +2,7 @@ package dw_sdk
import ( import (
"fmt" "fmt"
"net/http"
"time" "time"
"github.com/bytedance/sonic" "github.com/bytedance/sonic"
@ -44,9 +45,9 @@ func NewPreSaleBidClient(cfg Config) BidClient {
// 获取平台sku最低价【全款预售】 // 获取平台sku最低价【全款预售】
const PreSaleLowestPriceUrl = "/dop/api/v1/bidding/normal_pre_sale/lowest_price" const PreSaleLowestPriceUrl = "/dop/api/v1/bidding/normal_pre_sale/lowest_price"
func (a *PreSaleBidClientImpl) LowestPrice(skuId int) (*PublicResponse[LowestPriceResponse], error) { func (a *PreSaleBidClientImpl) LowestPrice(skuId int) (LowestPriceResponse, error) {
if skuId == 0 { if skuId == 0 {
return nil, Err_Params_None return LowestPriceResponse{}, Err_Params_None
} }
data := LowestPriceReq{ data := LowestPriceReq{
PublicParams: PublicParams{ PublicParams: PublicParams{
@ -64,12 +65,15 @@ func (a *PreSaleBidClientImpl) LowestPrice(skuId int) (*PublicResponse[LowestPri
response, err := r.Get(PreSaleLowestPriceUrl + "?" + s) response, err := r.Get(PreSaleLowestPriceUrl + "?" + s)
if err != nil { if err != nil {
return nil, errors.Wrapf(Err_Request_Err, "%s err:%v", PreSaleLowestPriceUrl, err) return LowestPriceResponse{}, errors.Wrapf(Err_Request_Err, "%s err:%v", PreSaleLowestPriceUrl, err)
} }
defer client.ReleaseResponse(response) defer client.ReleaseResponse(response)
var resp PublicResponse[LowestPriceResponse] var resp PublicResponse[LowestPriceResponse]
if err = response.JSON(&resp); err != nil { if err = response.JSON(&resp); err != nil {
return nil, errors.Wrapf(Err_JSON_UNMarshal, "%s err:%v", PreSaleLowestPriceUrl, err) return LowestPriceResponse{}, errors.Wrapf(Err_JSON_UNMarshal, "%s err:%v", PreSaleLowestPriceUrl, err)
} }
return &resp, nil if resp.Code != http.StatusOK {
return LowestPriceResponse{}, errors.Wrapf(Err_Request_Err, "%s resp.msg:%v", PreSaleLowestPriceUrl, resp.Msg)
}
return resp.Data, nil
} }