- 一些与门店商品信息操作相关的API
This commit is contained in:
@@ -37,6 +37,7 @@ const (
|
||||
|
||||
KeyCustomSkuID = "custom_sku_id"
|
||||
KeySkuID = "sku_id"
|
||||
KeyUPC = "upc"
|
||||
|
||||
KeyName = "name"
|
||||
KeyPhone = "phone"
|
||||
|
||||
@@ -40,6 +40,20 @@ var (
|
||||
skuExistReg = regexp.MustCompile(`\s?,\s?sku_id:(\d+)`)
|
||||
)
|
||||
|
||||
func genSkuIDParams(skuID int64, customSkuID, upc string) map[string]interface{} {
|
||||
params := map[string]interface{}{}
|
||||
if skuID != 0 {
|
||||
params[KeySkuID] = skuID
|
||||
} else if customSkuID != "" {
|
||||
params[KeyCustomSkuID] = customSkuID
|
||||
} else if upc != "" {
|
||||
params[KeyUPC] = upc
|
||||
} else {
|
||||
panic("skuID, customSkuID and upc are all no value!")
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
// category相关的函数,shop_custom_id可重
|
||||
|
||||
func (a *API) ShopCategoryCreate(shopID string, parentID int64, name string, rank int) (catID int64, err error) {
|
||||
@@ -169,9 +183,6 @@ func (a *API) SkuDelete(shopID, skuIDsStr string) (err error) {
|
||||
KeySkuID: skuIDsStr,
|
||||
}
|
||||
_, err = a.AccessAPI("sku.delete", params)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -181,9 +192,6 @@ func (a *API) SkuDeleteByCustomIDs(shopID, customSkuIDsStr string) (err error) {
|
||||
KeyCustomSkuID: customSkuIDsStr,
|
||||
}
|
||||
_, err = a.AccessAPI("sku.delete", params)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -193,9 +201,13 @@ func (a *API) SkuOnline(shopID, skuIDsStr string) (err error) {
|
||||
KeySkuID: skuIDsStr,
|
||||
}
|
||||
_, err = a.AccessAPI("sku.online", params)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) SkuOnlineOne(shopID string, skuID int64, customSkuID, upc string) (err error) {
|
||||
params := genSkuIDParams(skuID, customSkuID, upc)
|
||||
params[KeyShopID] = shopID
|
||||
_, err = a.AccessAPI("sku.online.one", params)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -205,9 +217,41 @@ func (a *API) SkuOffline(shopID, skuIDsStr string) (err error) {
|
||||
KeySkuID: skuIDsStr,
|
||||
}
|
||||
_, err = a.AccessAPI("sku.offline", params)
|
||||
if err == nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) SkuOfflineOne(shopID string, skuID int64, customSkuID, upc string) (err error) {
|
||||
params := genSkuIDParams(skuID, customSkuID, upc)
|
||||
params[KeyShopID] = shopID
|
||||
_, err = a.AccessAPI("sku.offline.one", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func genSkuPriceParams(skuPriceStr, customSkuPriceStr, upcPriceStr string) map[string]interface{} {
|
||||
params := map[string]interface{}{}
|
||||
if skuPriceStr != "" {
|
||||
params["skuid_price"] = skuPriceStr
|
||||
} else if skuPriceStr != "" {
|
||||
params["custom_sku_id"] = customSkuPriceStr
|
||||
} else if upcPriceStr != "" {
|
||||
params["upc_price"] = upcPriceStr
|
||||
} else {
|
||||
panic("skuPriceStr, customSkuPriceStr and upcPriceStr are all empty!")
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
func (a *API) SkuPriceUpdateBatch(shopID, skuPriceStr, customSkuPriceStr, upcPriceStr string) (err error) {
|
||||
params := genSkuPriceParams(skuPriceStr, customSkuPriceStr, upcPriceStr)
|
||||
params[KeyShopID] = shopID
|
||||
_, err = a.AccessAPI("sku.price.update.batch", params)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) SkuPriceUpdateOne(shopID, skuPriceStr, customSkuPriceStr, upcPriceStr string) (err error) {
|
||||
params := genSkuPriceParams(skuPriceStr, customSkuPriceStr, upcPriceStr)
|
||||
params[KeyShopID] = shopID
|
||||
_, err = a.AccessAPI("sku.price.update.one", params)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -218,9 +262,6 @@ func (a *API) SkuShopCategoryMap(shopID string, skuID int64, categoryIDsStr stri
|
||||
"category_id": categoryIDsStr,
|
||||
}
|
||||
_, err = a.AccessAPI("sku.shop.category.map", params)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,17 @@ type RetailTag struct {
|
||||
NamePath string `json:"namePath"`
|
||||
}
|
||||
|
||||
type BareStoreSkuInfo struct {
|
||||
SkuID string `json:"sku_id"`
|
||||
Price string `json:"price,omitempty"`
|
||||
Stock string `json:"stock,omitempty"`
|
||||
}
|
||||
|
||||
type BareStoreFoodInfo struct {
|
||||
AppFoodCode string `json:"app_food_code"`
|
||||
Skus []*BareStoreSkuInfo `json:"skus"`
|
||||
}
|
||||
|
||||
// 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名
|
||||
// name(和originName)的长度不能超过10个字符(字符,不是字节)
|
||||
// 创建一级分类,originName为空,name为新分类名,secondaryName为空
|
||||
@@ -100,7 +111,7 @@ func (a *API) RetailBatchInitData(poiCode string, foodDataList []map[string]inte
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailSkuPrice(poiCode string, foodData []map[string]interface{}) (err error) {
|
||||
func (a *API) RetailSkuPrice(poiCode string, foodData []*BareStoreFoodInfo) (err error) {
|
||||
_, err = a.AccessAPI("retail/sku/price", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"food_data": string(utils.MustMarshal(foodData)),
|
||||
@@ -108,7 +119,7 @@ func (a *API) RetailSkuPrice(poiCode string, foodData []map[string]interface{})
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailSkuStock(poiCode string, foodData []map[string]interface{}) (err error) {
|
||||
func (a *API) RetailSkuStock(poiCode string, foodData []*BareStoreFoodInfo) (err error) {
|
||||
_, err = a.AccessAPI("retail/sku/stock", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"food_data": string(utils.MustMarshal(foodData)),
|
||||
@@ -146,6 +157,15 @@ func (a *API) RetailSkuSellStatus(poiCode string, foodData []map[string]interfac
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailSkuSellStatus2(poiCode string, foodData []*BareStoreFoodInfo, sellStatus int) (err error) {
|
||||
_, err = a.AccessAPI("retail/sku/sellStatus", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"food_data": string(utils.MustMarshal(foodData)),
|
||||
"sell_status": sellStatus,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailDelete(poiCode, foodCode string) (err error) {
|
||||
_, err = a.AccessAPI("retail/delete", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
|
||||
@@ -32,14 +32,29 @@ type PendingSaveB2CSkuVo struct {
|
||||
|
||||
type PendingSaveSkuVo struct {
|
||||
OuterSkuCode string `json:"outerSkuCode"`
|
||||
ImageURL string `json:"imageUrl"`
|
||||
SalePrice float32 `json:"salePrice"`
|
||||
OriginalPrice float32 `json:"originalPrice"`
|
||||
CostPrice float32 `json:"costPrice"`
|
||||
ImageURL string `json:"imageUrl,omitempty"`
|
||||
SalePrice float64 `json:"salePrice"`
|
||||
OriginalPrice float64 `json:"originalPrice,omitempty"`
|
||||
CostPrice float64 `json:"costPrice"`
|
||||
EditStockNum int `json:"editStockNum"`
|
||||
B2cSku *PendingSaveB2CSkuVo `json:"b2cSku"`
|
||||
}
|
||||
|
||||
type PendingSaveGoodsVo struct {
|
||||
Title string `json:"title"`
|
||||
OuterGoodsCode string `json:"outerGoodsCode,omitempty"`
|
||||
IsMultiSku int `json:"isMultiSku"`
|
||||
GoodsImageURL []string `json:"goodsImageUrl"`
|
||||
GoodsDesc string `json:"goodsDesc"`
|
||||
InitialSales int `json:"initialSales,omitempty"`
|
||||
DeductStockType int `json:"deductStockType"`
|
||||
IsPutAway int `json:"isPutAway"`
|
||||
Sort int `json:"Sort,omitempty"`
|
||||
CategoryID int64 `json:"categoryId"`
|
||||
B2cGoods []*PendingSaveB2CGoodsVo `json:"b2cGoods"`
|
||||
SkuList []*PendingSaveSkuVo `json:"skuList"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
CategoryID int64 `json:"categoryId"`
|
||||
Title string `json:"title"`
|
||||
@@ -198,6 +213,16 @@ func (a *API) UpdateClassify(classifyID int64, title string, imageURL string) (e
|
||||
return err
|
||||
}
|
||||
|
||||
func getDataFromCUGoodsResult(result interface{}) (goodsId int64, skuMap map[string]int64, err error) {
|
||||
skuMap = make(map[string]int64)
|
||||
skuList := result.(map[string]interface{})["skuList"].([]interface{})
|
||||
for _, v := range skuList {
|
||||
sku := v.(map[string]interface{})
|
||||
skuMap[utils.Interface2String(sku[KeyOuterSkuCode])] = utils.MustInterface2Int64(sku[KeySkuID])
|
||||
}
|
||||
return utils.MustInterface2Int64(result.(map[string]interface{})["goodsId"]), skuMap, nil
|
||||
}
|
||||
|
||||
func (a *API) AddGoods(outerGoodsCode, title string, isMultiSku bool, goodsImageUrl []string, goodsDesc string, isPutAway bool, sort int, categoryId int64, classifyIdList []int64, b2cGoods *PendingSaveB2CGoodsVo, skuList []map[string]interface{}, addParams map[string]interface{}) (goodsId int64, skuMap map[string]int64, err error) {
|
||||
goodsInfo := map[string]interface{}{
|
||||
"outerGoodsCode": outerGoodsCode,
|
||||
@@ -221,13 +246,20 @@ func (a *API) AddGoods(outerGoodsCode, title string, isMultiSku bool, goodsImage
|
||||
"goods": mergedMap,
|
||||
})
|
||||
if err == nil {
|
||||
skuMap := make(map[string]int64)
|
||||
skuList := result.(map[string]interface{})["skuList"].([]interface{})
|
||||
for _, v := range skuList {
|
||||
sku := v.(map[string]interface{})
|
||||
skuMap[utils.Interface2String(sku[KeyOuterSkuCode])] = utils.MustInterface2Int64(sku[KeySkuID])
|
||||
}
|
||||
return utils.MustInterface2Int64(result.(map[string]interface{})["goodsId"]), skuMap, nil
|
||||
return getDataFromCUGoodsResult(result)
|
||||
}
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
func (a *API) AddGoods2(goodsInfo *PendingSaveGoodsVo) (goodsId int64, skuMap map[string]int64, err error) {
|
||||
if goodsInfo.DeductStockType == 0 {
|
||||
goodsInfo.DeductStockType = DeductStockTypePay
|
||||
}
|
||||
result, err := a.AccessAPI("goods/addGoods", map[string]interface{}{
|
||||
"goods": goodsInfo,
|
||||
})
|
||||
if err == nil {
|
||||
return getDataFromCUGoodsResult(result)
|
||||
}
|
||||
return 0, nil, err
|
||||
}
|
||||
@@ -254,13 +286,20 @@ func (a *API) UpdateGoods(goodsID int64, title string, isMultiSku bool, goodsIma
|
||||
"goods": mergedMap,
|
||||
})
|
||||
if err == nil {
|
||||
skuMap := make(map[string]int64)
|
||||
skuList := result.(map[string]interface{})["skuList"].([]interface{})
|
||||
for _, v := range skuList {
|
||||
sku := v.(map[string]interface{})
|
||||
skuMap[utils.Interface2String(sku[KeyOuterSkuCode])] = utils.MustInterface2Int64(sku[KeySkuID])
|
||||
}
|
||||
return utils.MustInterface2Int64(result.(map[string]interface{})["goodsId"]), skuMap, nil
|
||||
return getDataFromCUGoodsResult(result)
|
||||
}
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
func (a *API) UpdateGoods2(goodsInfo *PendingSaveGoodsVo) (goodsId int64, skuMap map[string]int64, err error) {
|
||||
if goodsInfo.DeductStockType == 0 {
|
||||
goodsInfo.DeductStockType = DeductStockTypePay
|
||||
}
|
||||
result, err := a.AccessAPI("goods/updateGoods", map[string]interface{}{
|
||||
"goods": goodsInfo,
|
||||
})
|
||||
if err == nil {
|
||||
return getDataFromCUGoodsResult(result)
|
||||
}
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user