- 继续重构新版同步逻辑
This commit is contained in:
@@ -31,15 +31,18 @@ type BareStoreSkuInfo struct {
|
||||
type FullSkuInfo struct {
|
||||
BareStoreSkuInfo
|
||||
SkuName string
|
||||
SpecQuality int
|
||||
Comment string
|
||||
SpecQuality float64
|
||||
SpecUnit string
|
||||
Weight int
|
||||
ActPrice int64
|
||||
}
|
||||
|
||||
type SkuNameInfo struct {
|
||||
NameID int `json:"nameID,omitempty"`
|
||||
VendorNameID string `json:"vendorNameID,omitempty"`
|
||||
NameID int `json:"nameID,omitempty"`
|
||||
VendorNameID string `json:"vendorNameID,omitempty"`
|
||||
|
||||
Prefix string
|
||||
Name string
|
||||
Description string
|
||||
Unit string
|
||||
@@ -100,7 +103,7 @@ type ISingleStoreStoreSkuHandler interface {
|
||||
IPurchasePlatformStoreSkuHandler
|
||||
|
||||
// 这个函数与GetStoreSkusInfo的区别是GetStoreAllSkus取的是全信息,而GetStoreSkusInfo只含库存,价格与可售信息
|
||||
// GetStoreAllSkus(ctx *jxcontext.Context, vendorStoreID string) (skuNameList []*SkuNameInfo, err error)
|
||||
GetStoreAllSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (skuNameList []*SkuNameInfo, err error)
|
||||
CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
|
||||
UpdateStoreSkus(ctx *jxcontext.Context, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
|
||||
DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error)
|
||||
|
||||
@@ -12,8 +12,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
testShopBaiduID = 2233976901
|
||||
testShopBaiduID = "2233976901"
|
||||
testShopID = 100077
|
||||
|
||||
// testShopBaiduID = "2267254343"
|
||||
// testShopID = 2
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -228,12 +228,14 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
|
||||
for _, v := range inStoreSkuList {
|
||||
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
|
||||
}
|
||||
for _, skuInfo := range vendorSkuList {
|
||||
storeSku := storeSkuMap[skuInfo.SkuID]
|
||||
globals.SugarLogger.Debug(utils.Format4Output(storeSku, false))
|
||||
for _, vendorSku := range vendorSkuList {
|
||||
storeSku := storeSkuMap[vendorSku.SkuID]
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(storeSku, false))
|
||||
storeSku.Stock = vendorSku.LeftNum
|
||||
storeSku.Price = vendorSku.SalePrice
|
||||
storeSku.Status = ebaiSkuStatus2Jx(vendorSku.Status)
|
||||
|
||||
outStoreSkuList = append(outStoreSkuList, storeSku)
|
||||
storeSku.Price = skuInfo.SalePrice
|
||||
storeSku.Status = ebaiSkuStatus2Jx(skuInfo.Status)
|
||||
}
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
@@ -249,3 +251,83 @@ func ebaiSkuStatus2Jx(ebaiSkuStatus int) (jxSkuStatus int) {
|
||||
}
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreAllSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||
PageSize: MaxPageSize,
|
||||
})
|
||||
if err == nil {
|
||||
skuNameList = append(skuNameList, vendorSkuList2Jx(page1.List)...)
|
||||
if page1.Pages > 1 {
|
||||
pages := make([]int, page1.Pages-1)
|
||||
for i := 2; i <= page1.Pages; i++ {
|
||||
pages[i-2] = i
|
||||
}
|
||||
task := tasksch.NewParallelTask("ebai GetStoreAllSkus", nil, ctx,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
callParams := &ebaiapi.SkuListParams{
|
||||
PageSize: MaxPageSize,
|
||||
Page: batchItemList[0].(int),
|
||||
}
|
||||
pageSku, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), callParams)
|
||||
if err2 == nil {
|
||||
return pageSku.List, err2
|
||||
}
|
||||
return nil, err2
|
||||
}, pages)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
result, err2 := task.GetResult(0)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range result {
|
||||
skuNameList = append(skuNameList, vendorSku2Jx(v.(*ebaiapi.SkuInfo)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return skuNameList, err
|
||||
}
|
||||
|
||||
func vendorSku2Jx(vendorSku *ebaiapi.SkuInfo) (skuName *partner.SkuNameInfo) {
|
||||
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(vendorSku.Name)
|
||||
weight := vendorSku.Weight
|
||||
if weight <= 0 {
|
||||
weight = jxutils.FormatSkuWeight(specQuality, specUnit)
|
||||
}
|
||||
skuName = &partner.SkuNameInfo{
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Unit: unit,
|
||||
SkuList: []*partner.FullSkuInfo{
|
||||
&partner.FullSkuInfo{
|
||||
BareStoreSkuInfo: partner.BareStoreSkuInfo{
|
||||
VendorSkuID: utils.Int64ToStr(vendorSku.SkuID),
|
||||
SkuID: int(utils.Str2Int64WithDefault(vendorSku.CustomSkuID, 0)),
|
||||
|
||||
Stock: vendorSku.LeftNum,
|
||||
Price: vendorSku.SalePrice,
|
||||
Status: ebaiSkuStatus2Jx(vendorSku.Status),
|
||||
},
|
||||
SkuName: vendorSku.Name,
|
||||
Comment: comment,
|
||||
SpecQuality: float64(specQuality),
|
||||
SpecUnit: specUnit,
|
||||
Weight: weight,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, v := range vendorSku.Photos {
|
||||
skuName.PictureList = append(skuName.PictureList, v.URL)
|
||||
}
|
||||
// todo, 看起来饿百只返回了最底层的商家分类信息
|
||||
for _, v := range vendorSku.CustomCatList {
|
||||
skuName.VendorCatIDList = append(skuName.VendorCatIDList, v.CustomCatID)
|
||||
}
|
||||
return skuName
|
||||
}
|
||||
|
||||
func vendorSkuList2Jx(vendorSkuList []*ebaiapi.SkuInfo) (skuNameList []*partner.SkuNameInfo) {
|
||||
for _, vendorSku := range vendorSkuList {
|
||||
skuNameList = append(skuNameList, vendorSku2Jx(vendorSku))
|
||||
}
|
||||
return skuNameList
|
||||
}
|
||||
|
||||
17
business/partner/purchase/ebai/store_sku2_test.go
Normal file
17
business/partner/purchase/ebai/store_sku2_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package ebai
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
)
|
||||
|
||||
func TestGetStoreAllSkus(t *testing.T) {
|
||||
skuNameList, err := new(PurchaseHandler).GetStoreAllSkus(jxcontext.AdminCtx, testShopID, testShopBaiduID)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
t.Log(utils.Format4Output(skuNameList, false))
|
||||
t.Log(len(skuNameList))
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestReadStore(t *testing.T) {
|
||||
result, err := new(PurchaseHandler).ReadStore(utils.Int2Str(testShopBaiduID))
|
||||
result, err := new(PurchaseHandler).ReadStore(testShopBaiduID)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
@@ -265,9 +265,10 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
|
||||
for _, foodInfo := range vendorFoodList {
|
||||
vendorSku := foodInfo.SkuList[0]
|
||||
storeSku := storeSkuMap[vendorSku.SkuID]
|
||||
outStoreSkuList = append(outStoreSkuList, storeSku)
|
||||
storeSku.Stock = int(utils.Str2Int64WithDefault(vendorSku.Stock, 0))
|
||||
storeSku.Price = jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0))
|
||||
storeSku.Status = mtwmSkuStatus2Jx(foodInfo.IsSoldOut)
|
||||
outStoreSkuList = append(outStoreSkuList, storeSku)
|
||||
}
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
@@ -281,3 +282,63 @@ func mtwmSkuStatus2Jx(mtwmSkuStatus int) (jxSkuStatus int) {
|
||||
}
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreAllSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (skuNameList []*partner.SkuNameInfo, err error) {
|
||||
for {
|
||||
result, err := api.MtwmAPI.RetailList(vendorStoreID, len(skuNameList), mtwmapi.GeneralMaxLimit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
skuNameList = append(skuNameList, vendorSkuList2Jx(result)...)
|
||||
if len(result) < mtwmapi.GeneralMaxLimit {
|
||||
break
|
||||
}
|
||||
}
|
||||
return skuNameList, err
|
||||
}
|
||||
|
||||
func vendorSku2Jx(vendorSku *mtwmapi.AppFood) (skuName *partner.SkuNameInfo) {
|
||||
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(vendorSku.Name)
|
||||
mtwmSku := vendorSku.SkuList[0]
|
||||
weight := mtwmSku.Weight
|
||||
if weight <= 0 {
|
||||
weight = jxutils.FormatSkuWeight(specQuality, specUnit)
|
||||
}
|
||||
skuName = &partner.SkuNameInfo{
|
||||
Prefix: prefix,
|
||||
Name: name,
|
||||
Unit: unit,
|
||||
SkuList: []*partner.FullSkuInfo{
|
||||
&partner.FullSkuInfo{
|
||||
BareStoreSkuInfo: partner.BareStoreSkuInfo{
|
||||
VendorSkuID: mtwmSku.SkuID,
|
||||
SkuID: int(utils.Str2Int64WithDefault(mtwmSku.SkuID, 0)),
|
||||
|
||||
Stock: int(utils.Str2Int64WithDefault(mtwmSku.Stock, 0)),
|
||||
Price: jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(mtwmSku.Price, 0)),
|
||||
Status: mtwmSkuStatus2Jx(vendorSku.IsSoldOut),
|
||||
},
|
||||
SkuName: vendorSku.Name,
|
||||
Comment: comment,
|
||||
SpecQuality: float64(specQuality),
|
||||
SpecUnit: specUnit,
|
||||
Weight: weight,
|
||||
},
|
||||
},
|
||||
PictureList: vendorSku.PictureList,
|
||||
}
|
||||
if vendorSku.CategoryName != "" {
|
||||
skuName.VendorCatIDList = []string{vendorSku.CategoryName}
|
||||
if vendorSku.SecondaryCategoryName != "" {
|
||||
skuName.VendorCatIDList = append(skuName.VendorCatIDList, vendorSku.SecondaryCategoryName)
|
||||
}
|
||||
}
|
||||
return skuName
|
||||
}
|
||||
|
||||
func vendorSkuList2Jx(vendorSkuList []*mtwmapi.AppFood) (skuNameList []*partner.SkuNameInfo) {
|
||||
for _, vendorSku := range vendorSkuList {
|
||||
skuNameList = append(skuNameList, vendorSku2Jx(vendorSku))
|
||||
}
|
||||
return skuNameList
|
||||
}
|
||||
|
||||
18
business/partner/purchase/mtwm/store_sku2_test.go
Normal file
18
business/partner/purchase/mtwm/store_sku2_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package mtwm
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
// _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
)
|
||||
|
||||
func TestGetStoreAllSkus(t *testing.T) {
|
||||
skuNameList, err := new(PurchaseHandler).GetStoreAllSkus(jxcontext.AdminCtx, 2, "2523687")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(skuNameList, false))
|
||||
t.Log(len(skuNameList))
|
||||
}
|
||||
Reference in New Issue
Block a user