diff --git a/platformapi/jdapi/sku.go b/platformapi/jdapi/sku.go index 991ea341..11aba65a 100644 --- a/platformapi/jdapi/sku.go +++ b/platformapi/jdapi/sku.go @@ -2,7 +2,6 @@ package jdapi import ( "fmt" - "math" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/globals" @@ -58,6 +57,10 @@ const ( KeyWeight = "weight" ) +const ( + FakeKeySpecAttr = "specAttr" +) + const ( MaxBatchSize4BatchUpdateOutSkuId = 50 ) @@ -410,11 +413,12 @@ func (a *API) GetProductStatus(storeId, skuId string) (retVal *ProductStatus, er func (a *API) AddSpu(outSpuId string, cagtegoryId int, shopCategories []int64, brandId int, spuName string, images []string, fixedStatus int, addParams map[string]interface{}, skus []map[string]interface{}) (spuId int64, skuPairs []*SkuIDPair, err error) { attrList := []string{} for k, v := range skus { - attr := getSkuAttr(v[KeyWeight].(float32)) + attr := v[FakeKeySpecAttr].(string) //getSkuAttr(v[KeyWeight].(float32)) attrList = append(attrList, attr) skus[k] = utils.MergeMaps(map[string]interface{}{ "saleAttrValues": genAttrMapList(attr), }, v) + delete(skus[k], FakeKeySpecAttr) } fixedParams := map[string]interface{}{ KeyOutSpuId: outSpuId, @@ -431,10 +435,6 @@ func (a *API) AddSpu(outSpuId string, cagtegoryId int, shopCategories []int64, b "saleAttrName": "规格", "saleAttrValueNameList": attrList, }, - // map[string]interface{}{ - // "saleAttrName": "口味", - // "saleAttrValueNameList": []string{"."}, - // }, }, } result, err := a.AccessAPINoPage("pms/addSpu", utils.MergeMaps(fixedParams, addParams), nil, nil, nil) @@ -456,8 +456,8 @@ func (a *API) AddSpu(outSpuId string, cagtegoryId int, shopCategories []int64, b // 追加新的SKU到指定的SPU接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=cffb839b06f042b28d6397b6bd4f2676 -func (a *API) AppendSku(outSpuId string, outSkuId string, cagtegoryId int, shopCategories []int64, brandId int, skuName string, skuPrice int, weight float32, images []string, fixedStatus int, isSale bool, addParams map[string]interface{}) (skuID int64, err error) { - attr := getSkuAttr(weight) +func (a *API) AppendSku(outSpuId string, outSkuId string, cagtegoryId int, shopCategories []int64, brandId int, skuName string, skuPrice int, weight float32, images []string, fixedStatus int, isSale bool, specAttr string, addParams map[string]interface{}) (skuID int64, err error) { + attr := specAttr //getSkuAttr(weight) if err = a.AppendSpuSaleAttr(outSpuId, "1001", attr); err != nil { return 0, err } @@ -591,10 +591,10 @@ func interface2CatList(data interface{}, level int, interface2CatHandler func(da return cats } -func getSkuAttr(weight float32) (attr string) { - attr = fmt.Sprintf("约%dg", int(math.Round(float64(weight*1000)))) - return attr -} +// func getSkuAttr(weight float32) (attr string) { +// attr = fmt.Sprintf("约%dg", int(math.Round(float64(weight*1000)))) +// return attr +// } func genAttrMapList(kgAttr string) (attrList []map[string]interface{}) { return []map[string]interface{}{ @@ -602,9 +602,5 @@ func genAttrMapList(kgAttr string) (attrList []map[string]interface{}) { "saleAttrName": "规格", "saleAttrValueName": kgAttr, }, - // map[string]interface{}{ - // "saleAttrName": "口味", - // "saleAttrValueName": ".", - // }, } }