- InitVendorCategory可对三个主流平台进行操作

This commit is contained in:
gazebo
2019-04-23 17:40:44 +08:00
parent f860307530
commit a857d40442
11 changed files with 130 additions and 13 deletions

View File

@@ -30,7 +30,7 @@ func (c *PurchaseHandler) GetVendorID() int {
return model.VendorIDMTWM
}
func (p *PurchaseHandler) GetVendorCategories() (vendorCats []*model.SkuVendorCategory, err error) {
func (p *PurchaseHandler) GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error) {
cats, err := api.MtwmAPI.RetailGetSpTagIds()
if err != nil {
return nil, err
@@ -40,10 +40,10 @@ func (p *PurchaseHandler) GetVendorCategories() (vendorCats []*model.SkuVendorCa
for i := 0; i < 3; i++ {
vendorCatMapList[i] = make(map[string]*model.SkuVendorCategory)
for _, v := range cats {
if utils.MustInterface2Int64(v["level"]) == 3 {
namePathList := strings.Split(strings.Trim(utils.Interface2String(v["namePath"]), ","), ",")
if v.Level == 3 {
namePathList := strings.Split(strings.Trim(v.NamePath, ","), ",")
if len(namePathList) != 3 {
panic(fmt.Sprintf("%s没有三级结构", v["namePath"]))
panic(fmt.Sprintf("%s没有三级结构", v.NamePath))
}
name := namePathList[i]
if _, ok := vendorCatMapList[i][name]; !ok {
@@ -56,8 +56,8 @@ func (p *PurchaseHandler) GetVendorCategories() (vendorCats []*model.SkuVendorCa
vendorCats = append(vendorCats, cat)
vendorCatMapList[i][name] = cat
if i == 2 {
cat.IsLeaf = int8(1)
cat.VendorCategoryID = utils.Int64ToStr(utils.MustInterface2Int64(v["id"]))
cat.IsLeaf = 1
cat.VendorCategoryID = utils.Int64ToStr(v.ID)
} else {
cat.VendorCategoryID = utils.Int2Str(manID) // 非叶子结点编码没有实际使用
manID++

View File

@@ -3,6 +3,8 @@ package mtwm
import (
"testing"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/baseapi/utils"
_ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/globals/testinit"
@@ -13,7 +15,7 @@ func init() {
}
func TestGetVendorCategories(t *testing.T) {
result, err := new(PurchaseHandler).GetVendorCategories()
result, err := new(PurchaseHandler).GetVendorCategories(jxcontext.AdminCtx)
if err != nil {
t.Fatal(err)
}