- mtwm.RetailGet与ebai.SkuList用struct替换map
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SkuStatusOnline = 1
|
||||
SkuStatusOffline = 0
|
||||
SkuStatusOnline = 1 // 为上架
|
||||
SkuStatusOffline = 0 // 为下架
|
||||
SkuStatusDeleted = 2 // 为删除
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,11 +30,67 @@ type CategoryInfo struct {
|
||||
Level int `json:"level"`
|
||||
}
|
||||
|
||||
type SkuListParams struct {
|
||||
Page int `json:"page,omitempty"`
|
||||
PageSize int `json:"pagesize,omitempty"`
|
||||
Upc string `json:"upc,omitempty"`
|
||||
SkuID int64 `json:"sku_id,omitempty"`
|
||||
CustomSkuID string `json:"custom_sku_id,omitempty"`
|
||||
UpcType int `json:"upc_type,omitempty"`
|
||||
GetUncate int `json:"get_uncate,omitempty"`
|
||||
Delete int `json:"delete,omitempty"`
|
||||
Enabled int `json:"enabled,omitempty"`
|
||||
StartTime int `json:"start_time,omitempty"`
|
||||
EndTime int `json:"end_time,omitempty"`
|
||||
}
|
||||
|
||||
type SkuPhotoInfo struct {
|
||||
IsMaster int `json:"is_master"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type SkuCustomCatInfo struct {
|
||||
CustomCatID string `json:"custom_cat_id"`
|
||||
CustomCatName string `json:"custom_cat_name"`
|
||||
}
|
||||
|
||||
type SkuInfo struct {
|
||||
CustomCatIDs string `json:"custom_cat_ids"`
|
||||
CustomCatList []*SkuCustomCatInfo `json:"custom_cat_list"`
|
||||
CustomSkuID string `json:"custom_sku_id"`
|
||||
IsInActivity int `json:"is_in_activity"`
|
||||
LeftNum int `json:"left_num"`
|
||||
MarketPrice int `json:"market_price"`
|
||||
Minimum int `json:"minimum"`
|
||||
Name string `json:"name"`
|
||||
NeedIce int `json:"need_ice"`
|
||||
Photos []*SkuPhotoInfo `json:"photos"`
|
||||
PreminusWeight int `json:"preminus_weight"`
|
||||
PreparationTime string `json:"preparation_time"`
|
||||
ProductionAddr1 string `json:"production_addr1"`
|
||||
ProductionAddr2 string `json:"production_addr2"`
|
||||
ProductionAddr3 string `json:"production_addr3"`
|
||||
Rtf string `json:"rtf"`
|
||||
SalePrice int64 `json:"sale_price"`
|
||||
SaleStep string `json:"sale_step"`
|
||||
SaleUnit string `json:"sale_unit"`
|
||||
ShelfNumber string `json:"shelf_number"`
|
||||
SkuID int64 `json:"sku_id"`
|
||||
// SkuProperty []interface{} `json:"sku_property"`
|
||||
Status int `json:"status"`
|
||||
Summary string `json:"summary"`
|
||||
Upc string `json:"upc"`
|
||||
UpcType string `json:"upc_type"`
|
||||
UpdateTime string `json:"update_time"`
|
||||
Weight int `json:"weight"`
|
||||
WeightFlag int `json:"weight_flag"`
|
||||
}
|
||||
|
||||
type PageDataInfo struct {
|
||||
Total int
|
||||
Page int
|
||||
Pages int
|
||||
List []map[string]interface{}
|
||||
Total int `json:"Total"`
|
||||
Page int `json:"Page"`
|
||||
Pages int `json:"Pages"`
|
||||
List []*SkuInfo `json:"List"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -114,21 +171,14 @@ func (a *API) SkuGetItemsByCategoryId(shopID string, categoryID int64) (skus []m
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (a *API) SkuList(shopID string, params map[string]interface{}) (skuInfo *PageDataInfo, err error) {
|
||||
defParams := map[string]interface{}{
|
||||
KeyShopID: shopID,
|
||||
}
|
||||
result, err := a.AccessAPI("sku.list", utils.MergeMaps(params, defParams))
|
||||
func (a *API) SkuList(shopID string, params *SkuListParams) (skuInfo *PageDataInfo, err error) {
|
||||
paramMap := utils.Struct2FlatMap(params)
|
||||
paramMap[KeyShopID] = shopID
|
||||
result, err := a.AccessAPI("sku.list", paramMap)
|
||||
if err == nil {
|
||||
data := result.Data.(map[string]interface{})
|
||||
return &PageDataInfo{
|
||||
Total: int(utils.MustInterface2Int64(data["total"])),
|
||||
Page: int(utils.MustInterface2Int64(data["page"])),
|
||||
Pages: int(utils.MustInterface2Int64(data["pages"])),
|
||||
List: utils.Slice2MapSlice(data["list"].([]interface{})),
|
||||
}, nil
|
||||
err = utils.Map2StructByJson(result.Data, &skuInfo, true)
|
||||
}
|
||||
return nil, err
|
||||
return skuInfo, err
|
||||
}
|
||||
|
||||
func (a *API) SkuCreate(shopID string, customSkuID int, params map[string]interface{}) (skuID int64, err error) {
|
||||
|
||||
@@ -48,9 +48,8 @@ func TestSkuGetItemsByCategoryId(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSkuList(t *testing.T) {
|
||||
result, err := api.SkuList(testShopID, map[string]interface{}{
|
||||
KeySkuID: 15579787500720732,
|
||||
// "delete": 1,
|
||||
result, err := api.SkuList(testShopID, &SkuListParams{
|
||||
SkuID: 15579787500720732,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -94,9 +93,12 @@ func TestSkuCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSkuUpdate(t *testing.T) {
|
||||
result, err := api.SkuUpdate("2", 15579787500720732, map[string]interface{}{
|
||||
// 15579787500720732 高级
|
||||
|
||||
result, err := api.SkuUpdate("2", 1557043939079105, map[string]interface{}{
|
||||
// "name": "高级商品2015a333约1100g/份",
|
||||
"rtf": "http://www.rosy.net.cn/rtf.html",
|
||||
// "rtf": "http://www.rosy.net.cn/rtf.html",
|
||||
"shelf_number": 12,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user