美团分类管理RetailCatUpdate,支持所有可能参数
This commit is contained in:
@@ -112,6 +112,21 @@ type AppFoodResult4SellStatus struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
type Param4UpdateCat struct {
|
||||
CategoryCodeOrigin string `json:"category_code_origin,omitempty"`
|
||||
CategoryNameOrigin string `json:"category_name_origin,omitempty"`
|
||||
CategoryCode string `json:"category_code,omitempty"`
|
||||
SecondaryCategoryCode string `json:"secondary_category_code,omitempty"`
|
||||
SecondaryCategoryName string `json:"secondary_category_name,omitempty"`
|
||||
Sequence int `json:"sequence,omitempty"`
|
||||
TargetLevel string `json:"target_level,omitempty"`
|
||||
TargetParentName string `json:"target_parent_name,omitempty"`
|
||||
|
||||
TopFlag string `json:"top_flag,omitempty"`
|
||||
WeeksTime string `json:"weeks_time,omitempty"`
|
||||
Period string `json:"period,omitempty"`
|
||||
}
|
||||
|
||||
// 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名
|
||||
// name(和originName)的长度不能超过10个字符(字符,不是字节)
|
||||
// 创建一级分类,originName为空,name为新分类名,secondaryName为空
|
||||
@@ -119,72 +134,24 @@ type AppFoodResult4SellStatus struct {
|
||||
// 创建二级分类,secondaryName为二级分类名,
|
||||
// (如果originName为空,同时创建一级分类,所以如果只是创建二级分类,originName与name要填一样的,此时sequence指的二级分类的sequence,一级分类的sequence为缺省值)
|
||||
// 修改二级分类,originName为二级分类名,name为二级分类新名,secondaryName为空
|
||||
// https://developer.waimai.meituan.com/home/docDetail/71
|
||||
// https://developer.waimai.meituan.com/home/questionDetail/4669
|
||||
func (a *API) RetailCatUpdate(poiCode, originName, name, secondaryName string, sequence int) (err error) {
|
||||
params := map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"category_name": name,
|
||||
"sequence": sequence,
|
||||
}
|
||||
if originName != "" {
|
||||
params["category_name_origin"] = originName
|
||||
}
|
||||
if secondaryName != "" {
|
||||
params["secondary_category_name"] = secondaryName
|
||||
}
|
||||
_, err = a.AccessAPI("retailCat/update", false, params)
|
||||
if err != nil {
|
||||
if err2, ok := err.(*utils.ErrorWithCode); ok {
|
||||
if err2.IntCode() == 833 {
|
||||
return nil
|
||||
}
|
||||
func (a *API) RetailCatUpdate(poiCode, catName string, updateParams *Param4UpdateCat) (err error) {
|
||||
if updateParams != nil {
|
||||
if updateParams.CategoryCodeOrigin != "" {
|
||||
updateParams.CategoryNameOrigin = ""
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailCatUpdate2(poiCode, originCode, originName, code, name, secondCode, secondaryName string, sequence int) (err error) {
|
||||
params := map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"category_name": name,
|
||||
"sequence": sequence,
|
||||
}
|
||||
if code != "" {
|
||||
params["category_code"] = code
|
||||
}
|
||||
if secondCode != "" {
|
||||
params["secondary_category_code"] = secondCode
|
||||
}
|
||||
if secondaryName != "" {
|
||||
params["secondary_category_name"] = secondaryName
|
||||
}
|
||||
|
||||
if originCode != "" {
|
||||
params["category_code_origin"] = originCode
|
||||
} else if originName != "" {
|
||||
params["category_name_origin"] = originName
|
||||
}
|
||||
|
||||
params := utils.Struct2MapByJson(updateParams)
|
||||
params[KeyAppPoiCode] = poiCode
|
||||
params["category_name"] = catName
|
||||
_, err = a.AccessAPI("retailCat/update", false, params)
|
||||
if err != nil {
|
||||
if err2, ok := err.(*utils.ErrorWithCode); ok {
|
||||
if err2.IntCode() == 833 {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailCatDelete(poiCode, name string) (err error) {
|
||||
_, err = a.AccessAPI("retailCat/delete", false, map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
"category_name": name,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *API) RetailCatDelete2(poiCode, code, name string) (err error) {
|
||||
// 删除商品分类
|
||||
// 当分类下存在子级分类或商品时,不允许直接删除此分类。
|
||||
func (a *API) RetailCatDelete(poiCode, code, name string) (err error) {
|
||||
params := map[string]interface{}{
|
||||
KeyAppPoiCode: poiCode,
|
||||
}
|
||||
|
||||
@@ -15,25 +15,29 @@ func TestRetailCatList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetailCatUpdate(t *testing.T) {
|
||||
// err := api.RetailCatUpdate(testPoiCode, "测试一级类别", "测试一级类别2", "", 2)
|
||||
err := api.RetailCatUpdate(testPoiCode, "测试一级类别", "测试一级类别", "", 2)
|
||||
err := api.RetailCatUpdate(testPoiCode, "测试一级类别", &Param4UpdateCat{
|
||||
CategoryNameOrigin: "测试一级类别",
|
||||
Sequence: 2,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
func TestRetailCatDelete(t *testing.T) {
|
||||
var err error
|
||||
err = api.RetailCatDelete(testPoiCode, utils.GetUpperUUID())
|
||||
err = api.RetailCatDelete(testPoiCode, "", utils.GetUpperUUID())
|
||||
if err == nil {
|
||||
t.Fatal("should return error that can not find such cat")
|
||||
}
|
||||
uniqueCatName := "一二三四五六七八九十"
|
||||
// uniqueCatName := "1234567890" //fmt.Sprintf("CAT%d", time.Now().Unix())
|
||||
err = api.RetailCatUpdate(testPoiCode, "", uniqueCatName, "", 15)
|
||||
err = api.RetailCatUpdate(testPoiCode, uniqueCatName, &Param4UpdateCat{
|
||||
Sequence: 15,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = api.RetailCatDelete(testPoiCode, uniqueCatName)
|
||||
err = api.RetailCatDelete(testPoiCode, "", uniqueCatName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user