- mtwm.RetailGet与ebai.SkuList用struct替换map
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SkuStatusOnline = 1
|
SkuStatusOnline = 1 // 为上架
|
||||||
SkuStatusOffline = 0
|
SkuStatusOffline = 0 // 为下架
|
||||||
|
SkuStatusDeleted = 2 // 为删除
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -29,11 +30,67 @@ type CategoryInfo struct {
|
|||||||
Level int `json:"level"`
|
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 {
|
type PageDataInfo struct {
|
||||||
Total int
|
Total int `json:"Total"`
|
||||||
Page int
|
Page int `json:"Page"`
|
||||||
Pages int
|
Pages int `json:"Pages"`
|
||||||
List []map[string]interface{}
|
List []*SkuInfo `json:"List"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -114,21 +171,14 @@ func (a *API) SkuGetItemsByCategoryId(shopID string, categoryID int64) (skus []m
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) SkuList(shopID string, params map[string]interface{}) (skuInfo *PageDataInfo, err error) {
|
func (a *API) SkuList(shopID string, params *SkuListParams) (skuInfo *PageDataInfo, err error) {
|
||||||
defParams := map[string]interface{}{
|
paramMap := utils.Struct2FlatMap(params)
|
||||||
KeyShopID: shopID,
|
paramMap[KeyShopID] = shopID
|
||||||
}
|
result, err := a.AccessAPI("sku.list", paramMap)
|
||||||
result, err := a.AccessAPI("sku.list", utils.MergeMaps(params, defParams))
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data := result.Data.(map[string]interface{})
|
err = utils.Map2StructByJson(result.Data, &skuInfo, true)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
return nil, err
|
return skuInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) SkuCreate(shopID string, customSkuID int, params map[string]interface{}) (skuID int64, err error) {
|
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) {
|
func TestSkuList(t *testing.T) {
|
||||||
result, err := api.SkuList(testShopID, map[string]interface{}{
|
result, err := api.SkuList(testShopID, &SkuListParams{
|
||||||
KeySkuID: 15579787500720732,
|
SkuID: 15579787500720732,
|
||||||
// "delete": 1,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -94,9 +93,12 @@ func TestSkuCreate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSkuUpdate(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/份",
|
// "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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -31,6 +31,57 @@ type BareStoreFoodInfo struct {
|
|||||||
Skus []*BareStoreSkuInfo `json:"skus"`
|
Skus []*BareStoreSkuInfo `json:"skus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AvailableTimesInfo struct {
|
||||||
|
Friday string `json:"friday"`
|
||||||
|
Monday string `json:"monday"`
|
||||||
|
Saturday string `json:"saturday"`
|
||||||
|
Sunday string `json:"sunday"`
|
||||||
|
Thursday string `json:"thursday"`
|
||||||
|
Tuesday string `json:"tuesday"`
|
||||||
|
Wednesday string `json:"wednesday"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuInfo struct {
|
||||||
|
AvailableTimes *AvailableTimesInfo `json:"available_times"`
|
||||||
|
BoxNum string `json:"box_num"`
|
||||||
|
BoxPrice string `json:"box_price"`
|
||||||
|
LocationCode string `json:"location_code"`
|
||||||
|
Price string `json:"price"`
|
||||||
|
SkuID string `json:"sku_id"`
|
||||||
|
Spec string `json:"spec"`
|
||||||
|
Stock string `json:"stock"`
|
||||||
|
Upc string `json:"upc"`
|
||||||
|
Weight int `json:"weight"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppFood struct {
|
||||||
|
AppFoodCode string `json:"app_food_code"`
|
||||||
|
AppPoiCode string `json:"app_poi_code"`
|
||||||
|
BoxNum float64 `json:"box_num"`
|
||||||
|
BoxPrice float64 `json:"box_price"`
|
||||||
|
CategoryCode string `json:"category_code"`
|
||||||
|
CategoryName string `json:"category_name"`
|
||||||
|
Ctime int `json:"ctime"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
IsSp int `json:"isSp"`
|
||||||
|
IsSoldOut int `json:"is_sold_out"`
|
||||||
|
IsSpecialty int `json:"is_specialty"`
|
||||||
|
MinOrderCount int `json:"min_order_count"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Picture string `json:"picture"`
|
||||||
|
PictureContents string `json:"picture_contents"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
|
SecondaryCategoryCode string `json:"secondary_category_code"`
|
||||||
|
SecondaryCategoryName string `json:"secondary_category_name"`
|
||||||
|
Sequence int `json:"sequence"`
|
||||||
|
Skus string `json:"skus"`
|
||||||
|
SkuList []*SkuInfo `json:"skuList"`
|
||||||
|
TagID int `json:"tag_id"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
Utime int `json:"utime"`
|
||||||
|
ZhName string `json:"zh_name"`
|
||||||
|
}
|
||||||
|
|
||||||
// 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名
|
// 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名
|
||||||
// name(和originName)的长度不能超过10个字符(字符,不是字节)
|
// name(和originName)的长度不能超过10个字符(字符,不是字节)
|
||||||
// 创建一级分类,originName为空,name为新分类名,secondaryName为空
|
// 创建一级分类,originName为空,name为新分类名,secondaryName为空
|
||||||
@@ -127,15 +178,17 @@ func (a *API) RetailSkuStock(poiCode string, foodData []*BareStoreFoodInfo) (err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) RetailGet(poiCode, foodCode string) (food map[string]interface{}, err error) {
|
func (a *API) RetailGet(poiCode, foodCode string) (food *AppFood, err error) {
|
||||||
result, err := a.AccessAPI("retail/get", true, map[string]interface{}{
|
result, err := a.AccessAPI("retail/get", true, map[string]interface{}{
|
||||||
KeyAppPoiCode: poiCode,
|
KeyAppPoiCode: poiCode,
|
||||||
KeyAppFoodCode: foodCode,
|
KeyAppFoodCode: foodCode,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return result.(map[string]interface{}), nil
|
if err = utils.Map2StructByJson(result, &food, true); err == nil && food.Skus != "" {
|
||||||
|
err = utils.UnmarshalUseNumber([]byte(food.Skus), &food.SkuList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, err
|
return food, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) RetailSkuSave(poiCode, foodCode string, standardSkus, unstandardSkus []map[string]interface{}) (err error) {
|
func (a *API) RetailSkuSave(poiCode, foodCode string, standardSkus, unstandardSkus []map[string]interface{}) (err error) {
|
||||||
|
|||||||
@@ -47,7 +47,15 @@ func TestRetailList(t *testing.T) {
|
|||||||
if len(result) == 0 {
|
if len(result) == 0 {
|
||||||
t.Fatal("should have items")
|
t.Fatal("should have items")
|
||||||
}
|
}
|
||||||
// t.Log(utils.Format4Output(result, false))
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRetailGet(t *testing.T) {
|
||||||
|
result, err := api.RetailGet(testPoiCode, "5246")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRetailGetSpTagIds(t *testing.T) {
|
func TestRetailGetSpTagIds(t *testing.T) {
|
||||||
@@ -69,7 +77,7 @@ func TestRetailCatSkuBatchDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRetailDelete(t *testing.T) {
|
func TestRetailDelete(t *testing.T) {
|
||||||
err := api.RetailDelete(testPoiCode, "")
|
err := api.RetailDelete(testPoiCode, "614")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user