- 重构partner_store_sku

This commit is contained in:
gazebo
2019-07-13 10:37:08 +08:00
parent cde87bb667
commit 01c522b5b0
9 changed files with 102 additions and 68 deletions

View File

@@ -2065,25 +2065,25 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
return hint, err
}
func GetVendorStoreSkusInfo(ctx *jxcontext.Context, storeID int, vendorIDs, skuIDs []int, isContinueWhenError bool) (skuVendorMap map[int][]*partner.BareStoreSkuInfo, err error) {
func GetVendorStoreSkusInfo(ctx *jxcontext.Context, storeID int, vendorIDs, skuIDs []int, isContinueWhenError bool) (skuVendorMap map[int][]*partner.StoreSkuInfo, err error) {
globals.SugarLogger.Debugf("GetVendorStoreSkusInfo, storeID:%d, vendorIDs:%v, skuID:%v", storeID, vendorIDs, skuIDs)
db := dao.GetDB()
var locker sync.RWMutex
skuVendorMap = make(map[int][]*partner.BareStoreSkuInfo)
skuVendorMap = make(map[int][]*partner.StoreSkuInfo)
_, err = CurVendorSync.LoopStoresMap(ctx, db, fmt.Sprintf("GetVendorStoreSkusInfo storeID:%d", storeID), false, false, vendorIDs, []int{storeID},
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
if handler, _ := partner.GetPurchasePlatformFromVendorID(loopMapInfo.VendorID).(partner.IPurchasePlatformStoreSkuHandler); handler != nil {
storeSkuList, err2 := dao.GetStoreSkus2(db, loopMapInfo.VendorID, storeID, skuIDs, false)
if err = err2; err == nil && len(storeSkuList) > 0 {
bareStoreSkuInfoList := make([]*partner.BareStoreSkuInfo, len(skuIDs))
bareStoreSkuInfoList := make([]*partner.StoreSkuInfo, len(skuIDs))
for k, v := range storeSkuList {
bareStoreSkuInfoList[k] = &partner.BareStoreSkuInfo{
bareStoreSkuInfoList[k] = &partner.StoreSkuInfo{
SkuID: v.SkuID,
VendorSkuID: v.VendorSkuID,
}
}
outBareStoreSkuInfoList, err2 := handler.GetStoreSkusInfo(ctx, t, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, bareStoreSkuInfoList)
outBareStoreSkuInfoList, err2 := handler.GetStoreSkusBareInfo(ctx, t, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, bareStoreSkuInfoList)
if err = err2; err == nil && outBareStoreSkuInfoList != nil {
locker.Lock()
defer locker.Unlock()

View File

@@ -14,7 +14,7 @@ func SyncStoreSkuNew(ctx *jxcontext.Context, vendorIDs, storeIDs, nameIDs, skuID
}
func DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, handler partner.ISingleStoreStoreSkuHandler, storeID int, vendorStoreID string, isContinueWhenError bool) (err error) {
skuNameList, err := handler.GetStoreAllSkus(ctx, storeID, vendorStoreID)
skuNameList, err := handler.GetStoreSkusFullInfo(ctx, parentTask, storeID, vendorStoreID, nil)
if err != nil {
return err
}
@@ -22,10 +22,10 @@ func DeleteStoreAllSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, handle
task := tasksch.NewParallelTask(fmt.Sprintf("DeleteStoreAllSkus, vendorStoreID:%s", vendorStoreID),
tasksch.NewParallelConfig().SetBatchSize(batchSize).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
var skuList []*partner.BareStoreSkuInfo
var skuList []*partner.StoreSkuInfo
for _, v := range batchItemList {
skuName := v.(*partner.SkuNameInfo)
skuList = append(skuList, &partner.BareStoreSkuInfo{
skuList = append(skuList, &partner.StoreSkuInfo{
VendorSkuID: skuName.SkuList[0].VendorSkuID,
})
}

View File

@@ -8,16 +8,18 @@ import (
)
const (
FuncUpdateStoreSkusStock = 1
FuncUpdateStoreSkusStatus = 2
FuncUpdateStoreSkusPrice = 3
FuncGetStoreSkusBareInfo = 1
FuncUpdateStoreSkusStock = 2
FuncUpdateStoreSkusStatus = 3
FuncUpdateStoreSkusPrice = 4
FuncCreateStoreSkus = 6
FuncUpdateStoreSkus = 7
FuncDeleteStoreSkus = 8
FuncGetStoreSkusFullInfo = 6
FuncCreateStoreSkus = 7
FuncUpdateStoreSkus = 8
FuncDeleteStoreSkus = 9
)
type BareStoreSkuInfo struct {
type StoreSkuInfo struct {
SkuID int `json:"skuID,omitempty"`
VendorSkuID string `json:"vendorSkuID,omitempty"`
NameID int `json:"nameID,omitempty"`
@@ -28,8 +30,8 @@ type BareStoreSkuInfo struct {
Status int `json:"status,omitempty"`
}
type FullSkuInfo struct {
BareStoreSkuInfo
type SkuInfo struct {
StoreSkuInfo
SkuName string
Comment string
SpecQuality float64
@@ -49,10 +51,10 @@ type SkuNameInfo struct {
VendorCatIDList []string
PictureList []string
Status int `json:"status,omitempty"`
SkuList []*FullSkuInfo
SkuList []*SkuInfo
}
type BareStoreSkuInfoList []*BareStoreSkuInfo
type BareStoreSkuInfoList []*StoreSkuInfo
func (l BareStoreSkuInfoList) GetVendorSkuIDList() (vendorSkuIDList []string) {
for _, v := range l {
@@ -93,23 +95,35 @@ type BareCategoryInfo struct {
type IPurchasePlatformStoreSkuHandler interface {
GetStoreSkusBatchSize(funcID int) int
GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*BareStoreSkuInfo) (outStoreSkuList []*BareStoreSkuInfo, err error)
UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error)
UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error)
UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error)
GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*StoreSkuInfo) (outStoreSkuList []*StoreSkuInfo, err error)
UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (err error)
UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (err error)
UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (err error)
}
type ISingleStoreStoreSkuHandler interface {
IPurchasePlatformStoreSkuHandler
// 这个函数与GetStoreSkusInfo的区别是GetStoreAllSkus取的是全信息而GetStoreSkusInfo只含库存价格与可售信息
GetStoreAllSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string) (skuNameList []*SkuNameInfo, err error)
GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, skuIDs []int) (outSkuNameList []*SkuNameInfo, err error)
CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (err error)
DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*BareStoreSkuInfo) (err error)
DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*StoreSkuInfo) (err error)
GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*BareCategoryInfo, err error)
CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error)
DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string) (err error)
}
func BuildSkuName(skuID int, vendorSkuID string) (skuName *SkuNameInfo) {
return &SkuNameInfo{
SkuList: []*SkuInfo{
&SkuInfo{
StoreSkuInfo: StoreSkuInfo{
SkuID: skuID,
VendorSkuID: vendorSkuID,
},
},
},
}
}

View File

@@ -20,8 +20,12 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
switch funcID {
case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice, partner.FuncDeleteStoreSkus:
batchSize = ebaiapi.MaxStoreSkuBatchSize
case partner.FuncGetStoreSkusBareInfo:
batchSize = 1
case partner.FuncCreateStoreSkus, partner.FuncUpdateStoreSkus:
batchSize = 1
case partner.FuncGetStoreSkusFullInfo:
batchSize = 1
}
return batchSize
}
@@ -98,14 +102,14 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
return err
}
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
if globals.EnableEbaiStoreWrite {
err = api.EbaiAPI.SkuDelete(utils.Int2Str(storeID), strings.Join(partner.BareStoreSkuInfoList(storeSkuList).GetVendorSkuIDList(), ","))
}
return err
}
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var validSkus, invalidSkus []string
for _, storeSku := range storeSkuList {
if storeSku.Status == model.SkuStatusNormal {
@@ -131,7 +135,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
return err
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
skuPriceList := make([]string, len(storeSkuList))
for k, v := range storeSkuList {
skuPriceList[k] = fmt.Sprintf("%s:%d", v.VendorSkuID, v.Price)
@@ -146,7 +150,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
return err
}
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
skuStockList := make([]string, len(storeSkuList))
for k, v := range storeSkuList {
skuStockList[k] = fmt.Sprintf("%s:%d", v.VendorSkuID, v.Stock)
@@ -195,7 +199,7 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[s
return params
}
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
vendorSkuIDIntList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
var vendorSkuList []*ebaiapi.SkuInfo
if len(vendorSkuIDIntList) > 1 {
@@ -224,7 +228,7 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
return nil, nil
}
if err == nil {
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
storeSkuMap := make(map[int64]*partner.StoreSkuInfo)
for _, v := range inStoreSkuList {
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
}
@@ -252,10 +256,14 @@ 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{
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, skuIDs []int) (skuNameList []*partner.SkuNameInfo, err error) {
params := &ebaiapi.SkuListParams{
PageSize: MaxPageSize,
})
}
if len(skuIDs) == 1 {
params.CustomSkuID = utils.Int2Str(skuIDs[0])
}
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), params)
if err == nil {
skuNameList = append(skuNameList, vendorSkuList2Jx(page1.List)...)
if page1.Pages > 1 {
@@ -275,7 +283,7 @@ func (p *PurchaseHandler) GetStoreAllSkus(ctx *jxcontext.Context, storeID int, v
}
return nil, err2
}, pages)
tasksch.HandleTask(task, nil, true).Run()
tasksch.HandleTask(task, parentTask, true).Run()
result, err2 := task.GetResult(0)
if err = err2; err == nil {
for _, v := range result {
@@ -297,9 +305,9 @@ func vendorSku2Jx(vendorSku *ebaiapi.SkuInfo) (skuName *partner.SkuNameInfo) {
Prefix: prefix,
Name: name,
Unit: unit,
SkuList: []*partner.FullSkuInfo{
&partner.FullSkuInfo{
BareStoreSkuInfo: partner.BareStoreSkuInfo{
SkuList: []*partner.SkuInfo{
&partner.SkuInfo{
StoreSkuInfo: partner.StoreSkuInfo{
VendorSkuID: utils.Int64ToStr(vendorSku.SkuID),
SkuID: int(utils.Str2Int64WithDefault(vendorSku.CustomSkuID, 0)),
@@ -318,7 +326,7 @@ func vendorSku2Jx(vendorSku *ebaiapi.SkuInfo) (skuName *partner.SkuNameInfo) {
for _, v := range vendorSku.Photos {
skuName.PictureList = append(skuName.PictureList, v.URL)
}
// todo, 看起来饿百只返回了最底层的商家分类信息
// todo, 看起来饿百只返回了最低一级的商家分类信息
for _, v := range vendorSku.CustomCatList {
skuName.VendorCatIDList = append(skuName.VendorCatIDList, v.CustomCatID)
}

View File

@@ -8,7 +8,7 @@ import (
)
func TestGetStoreAllSkus(t *testing.T) {
skuNameList, err := new(PurchaseHandler).GetStoreAllSkus(jxcontext.AdminCtx, testShopID, testShopBaiduID)
skuNameList, err := new(PurchaseHandler).GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, testShopID, testShopBaiduID, []int{4256})
if err != nil {
t.Fatal(err.Error())
}

View File

@@ -14,13 +14,13 @@ import (
func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
switch funcID {
case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice:
case partner.FuncGetStoreSkusBareInfo, partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice:
batchSize = jdapi.MaxStoreSkuBatchSize
}
return batchSize
}
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
var batchSkuInfoList []*jdapi.BaseStockCenterRequest
batchSkuList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
for _, v := range inStoreSkuList {
@@ -48,7 +48,7 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
tasksch.HandleTask(task, parentTask, false).Run()
_, err = task.GetResult(0)
if err == nil {
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
storeSkuMap := make(map[int64]*partner.StoreSkuInfo)
for _, v := range inStoreSkuList {
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
}
@@ -77,7 +77,7 @@ func jxStoreSkuStatus2Jd(jxStoreSkuStatus int) (isSale bool) {
return jxStoreSkuStatus == model.SkuStatusNormal
}
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var skuVendibilityList []*jdapi.StockVendibility
for _, v := range storeSkuList {
skuVendibilityList = append(skuVendibilityList, &jdapi.StockVendibility{
@@ -91,7 +91,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
return err
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var skuPriceInfoList []*jdapi.SkuPriceInfo
for _, v := range storeSkuList {
skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{
@@ -105,7 +105,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
return err
}
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var skuStockList []*jdapi.SkuStock
for _, v := range storeSkuList {
skuStockList = append(skuStockList, &jdapi.SkuStock{

View File

@@ -17,10 +17,14 @@ func (p *PurchaseHandler) GetStoreSkusBatchSize(funcID int) (batchSize int) {
switch funcID {
case partner.FuncUpdateStoreSkusStock, partner.FuncUpdateStoreSkusStatus, partner.FuncUpdateStoreSkusPrice:
batchSize = mtwmapi.MaxStoreSkuBatchSize
case partner.FuncGetStoreSkusBareInfo:
batchSize = 1
case partner.FuncDeleteStoreSkus:
batchSize = 1 // 可考虑用批量操作
case partner.FuncCreateStoreSkus, partner.FuncUpdateStoreSkus:
batchSize = 1 // 可考虑用批量操作
case partner.FuncGetStoreSkusFullInfo:
batchSize = 1
}
return batchSize
}
@@ -151,7 +155,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
return err
}
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
if globals.EnableMtwmStoreWrite {
if len(storeSkuList) == 1 {
err = api.MtwmAPI.RetailDelete(vendorStoreID, storeSkuList[0].VendorSkuID)
@@ -165,7 +169,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v
return err
}
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var validSkus, invalidSkus []*mtwmapi.BareStoreFoodInfo
for _, storeSku := range storeSkuList {
skuInfo := &mtwmapi.BareStoreFoodInfo{
@@ -193,7 +197,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
return err
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var priceList []*mtwmapi.BareStoreFoodInfo
for _, storeSku := range storeSkuList {
skuInfo := &mtwmapi.BareStoreFoodInfo{
@@ -213,7 +217,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
return err
}
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var stockList []*mtwmapi.BareStoreFoodInfo
for _, storeSku := range storeSkuList {
skuInfo := &mtwmapi.BareStoreFoodInfo{
@@ -233,7 +237,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
return err
}
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
func (p *PurchaseHandler) GetStoreSkusBareInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
vendorSkuIDList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDList()
var vendorFoodList []*mtwmapi.AppFood
if len(vendorSkuIDList) > 1 {
@@ -258,7 +262,7 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
return nil, nil
}
if err == nil {
storeSkuMap := make(map[string]*partner.BareStoreSkuInfo)
storeSkuMap := make(map[string]*partner.StoreSkuInfo)
for _, v := range inStoreSkuList {
storeSkuMap[v.VendorSkuID] = v
}
@@ -283,16 +287,24 @@ 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)
func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, skuIDs []int) (skuNameList []*partner.SkuNameInfo, err error) {
if len(skuIDs) == 0 {
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
}
}
} else {
skuInfo, err := api.MtwmAPI.RetailGet(vendorStoreID, utils.Int2Str(skuIDs[0]))
if err != nil {
return nil, err
}
skuNameList = append(skuNameList, vendorSkuList2Jx(result)...)
if len(result) < mtwmapi.GeneralMaxLimit {
break
}
skuNameList = append(skuNameList, vendorSku2Jx(skuInfo))
}
return skuNameList, err
}
@@ -308,9 +320,9 @@ func vendorSku2Jx(vendorSku *mtwmapi.AppFood) (skuName *partner.SkuNameInfo) {
Prefix: prefix,
Name: name,
Unit: unit,
SkuList: []*partner.FullSkuInfo{
&partner.FullSkuInfo{
BareStoreSkuInfo: partner.BareStoreSkuInfo{
SkuList: []*partner.SkuInfo{
&partner.SkuInfo{
StoreSkuInfo: partner.StoreSkuInfo{
VendorSkuID: mtwmSku.SkuID,
SkuID: int(utils.Str2Int64WithDefault(mtwmSku.SkuID, 0)),

View File

@@ -9,7 +9,7 @@ import (
)
func TestGetStoreAllSkus(t *testing.T) {
skuNameList, err := new(PurchaseHandler).GetStoreAllSkus(jxcontext.AdminCtx, 2, "2523687")
skuNameList, err := new(PurchaseHandler).GetStoreSkusFullInfo(jxcontext.AdminCtx, nil, 2, "2523687", nil)
if err != nil {
t.Fatal(err)
}

View File

@@ -149,7 +149,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, vendorStoreID
return err
}
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
storeSku := storeSkuList[0]
goodsID := utils.Str2Int64(storeSku.VendorNameID)
if globals.EnableWscStoreWrite {
@@ -162,7 +162,7 @@ func (p *PurchaseHandler) DeleteStoreSkus(ctx *jxcontext.Context, storeID int, v
return err
}
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
var validGoodsIDList, invalidGoodsIDList []int64
for _, storeSku := range storeSkuList {
if storeSku.Status == model.SkuStatusNormal {
@@ -182,11 +182,11 @@ func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, storeID
return err
}
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.BareStoreSkuInfo) (err error) {
func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo) (err error) {
err = fmt.Errorf("内部错误微商城不支持UpdateStoreSkusPrice!")
return err
}
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.StoreSkuInfo) (outStoreSkuList []*partner.StoreSkuInfo, err error) {
return outStoreSkuList, err
}