You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kashangwl/api.product.go

51 lines
2.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package kashangwl
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
)
type ApiProductResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
Id int `json:"id"` // 商品编号
ProductName string `json:"product_name,omitempty"` // 商品名称
Name string `json:"name"` // 规格名称
Price string `json:"price"` // 售价
ValidPurchasingQuantity string `json:"valid_purchasing_quantity"` // 合法的购买数量
SuperiorCommissionsRate int `json:"superior_commissions_rate"` // 上级佣金比例
Type int `json:"type"` // 商品类型1充值2卡密3卡券4人工
SupplyState int `json:"supply_state"` // 库存状态1充足2断货
StockState int `json:"stock_state"` // 状态1上架2维护3下架
BanStartAt string `json:"ban_start_at,omitempty"` // 禁售开始时间
BanEndAt string `json:"ban_end_at,omitempty"` // 禁售结束时间
} `json:"data"`
}
type ApiProductResult struct {
Result ApiProductResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newApiProductResult(result ApiProductResponse, body []byte, http gorequest.Response, err error) *ApiProductResult {
return &ApiProductResult{Result: result, Body: body, Http: http, Err: err}
}
// ApiProduct 获取单个商品信息
// http://doc.cqmeihu.cn/sales/product-info.html
func (c *Client) ApiProduct(ctx context.Context, productId int64) *ApiProductResult {
// 参数
params := gorequest.NewParams()
params.Set("product_id", productId)
// 请求
request, err := c.request(ctx, apiUrl+"/api/product", params)
// 定义
var response ApiProductResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newApiProductResult(response, request.ResponseBody, request, err)
}