美团分类管理RetailCatUpdate,支持所有可能参数

This commit is contained in:
gazebo
2019-10-18 16:09:09 +08:00
parent 629aa20fea
commit af35dc054f
2 changed files with 35 additions and 64 deletions

View File

@@ -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,
}