- GetVendorStoreSkusInfo处理skuID与平台绑定不正常的情况
This commit is contained in:
@@ -1508,7 +1508,7 @@ func GetVendorStoreSkusInfo(ctx *jxcontext.Context, storeID int, vendorIDs, skuI
|
||||
db := dao.GetDB()
|
||||
var locker sync.RWMutex
|
||||
skuVendorMap = make(map[int][]*partner.BareStoreSkuInfo)
|
||||
_, err = CurVendorSync.LoopStoresMap(ctx, db, fmt.Sprintf("GetVendorStoreSkusInfo:%d", storeID), false, false, vendorIDs, []int{storeID},
|
||||
_, 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 := CurVendorSync.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||
@@ -1521,10 +1521,11 @@ func GetVendorStoreSkusInfo(ctx *jxcontext.Context, storeID int, vendorIDs, skuI
|
||||
VendorSkuID: v.VendorSkuID,
|
||||
}
|
||||
}
|
||||
if _, err = handler.GetStoreSkusInfo(ctx, t, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, bareStoreSkuInfoList); err == nil {
|
||||
outBareStoreSkuInfoList, err2 := handler.GetStoreSkusInfo(ctx, t, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, bareStoreSkuInfoList)
|
||||
if err = err2; err == nil && outBareStoreSkuInfoList != nil {
|
||||
locker.Lock()
|
||||
defer locker.Unlock()
|
||||
skuVendorMap[loopMapInfo.VendorID] = bareStoreSkuInfoList
|
||||
skuVendorMap[loopMapInfo.VendorID] = outBareStoreSkuInfoList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,25 +27,28 @@ type BareStoreSkuInfo struct {
|
||||
type BareStoreSkuInfoList []*BareStoreSkuInfo
|
||||
|
||||
func (l BareStoreSkuInfoList) GetVendorSkuIDList() (vendorSkuIDList []string) {
|
||||
vendorSkuIDList = make([]string, len(l))
|
||||
for k, v := range l {
|
||||
vendorSkuIDList[k] = v.VendorSkuID
|
||||
for _, v := range l {
|
||||
if !dao.IsVendorThingIDEmpty(v.VendorSkuID) {
|
||||
vendorSkuIDList = append(vendorSkuIDList, v.VendorSkuID)
|
||||
}
|
||||
}
|
||||
return vendorSkuIDList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) GetVendorSkuIDIntList() (vendorSkuIDIntList []int64) {
|
||||
vendorSkuIDIntList = make([]int64, len(l))
|
||||
for k, v := range l {
|
||||
vendorSkuIDIntList[k] = utils.Str2Int64(v.VendorSkuID)
|
||||
for _, v := range l {
|
||||
if !dao.IsVendorThingIDEmpty(v.VendorSkuID) {
|
||||
vendorSkuIDIntList = append(vendorSkuIDIntList, utils.Str2Int64(v.VendorSkuID))
|
||||
}
|
||||
}
|
||||
return vendorSkuIDIntList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) GetSkuIDList() (skuIDList []int) {
|
||||
skuIDList = make([]int, len(l))
|
||||
for k, v := range l {
|
||||
skuIDList[k] = v.SkuID
|
||||
if v.SkuID > 0 {
|
||||
skuIDList[k] = v.SkuID
|
||||
}
|
||||
}
|
||||
return skuIDList
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[s
|
||||
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||
vendorSkuIDIntList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||
var vendorSkuList []*ebaiapi.SkuInfo
|
||||
if len(inStoreSkuList) > 1 {
|
||||
if len(vendorSkuIDIntList) > 1 {
|
||||
task := tasksch.NewParallelTask("获取饿百平台门店商品信息", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorSkuID := batchItemList[0].(int64)
|
||||
@@ -210,13 +210,15 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
|
||||
}, vendorSkuIDIntList)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
} else if len(vendorSkuIDIntList) == 1 {
|
||||
skuInfo, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||
SkuID: utils.Str2Int64(inStoreSkuList[0].VendorSkuID),
|
||||
SkuID: vendorSkuIDIntList[0],
|
||||
})
|
||||
if err = err2; err == nil {
|
||||
vendorSkuList = skuInfo.List
|
||||
}
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
if err == nil {
|
||||
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
|
||||
@@ -225,10 +227,11 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
|
||||
}
|
||||
for _, skuInfo := range vendorSkuList {
|
||||
storeSku := storeSkuMap[skuInfo.SkuID]
|
||||
globals.SugarLogger.Debug(utils.Format4Output(storeSku, false))
|
||||
outStoreSkuList = append(outStoreSkuList, storeSku)
|
||||
storeSku.Price = skuInfo.SalePrice
|
||||
storeSku.Status = ebaiSkuStatus2Jx(skuInfo.Status)
|
||||
}
|
||||
outStoreSkuList = inStoreSkuList
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
@@ -6,47 +6,52 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||
batchSkuInfoList := make([]*jdapi.BaseStockCenterRequest, len(inStoreSkuList))
|
||||
var batchSkuInfoList []*jdapi.BaseStockCenterRequest
|
||||
batchSkuList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||
for k, v := range inStoreSkuList {
|
||||
batchSkuInfoList[k] = &jdapi.BaseStockCenterRequest{
|
||||
StationNo: vendorStoreID,
|
||||
SkuId: utils.Str2Int64(v.VendorSkuID),
|
||||
for _, v := range inStoreSkuList {
|
||||
if !dao.IsVendorThingIDEmpty(v.VendorSkuID) {
|
||||
batchSkuInfoList = append(batchSkuInfoList, &jdapi.BaseStockCenterRequest{
|
||||
StationNo: vendorStoreID,
|
||||
SkuId: utils.Str2Int64(v.VendorSkuID),
|
||||
})
|
||||
}
|
||||
}
|
||||
var stockInfo []*jdapi.QueryStockResponse
|
||||
var priceInfo []*jdapi.StorePriceInfo
|
||||
task := tasksch.NewParallelTask("获取京东到家平台门店商品信息", tasksch.NewParallelConfig().SetParallelCount(2), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
subTaskID := batchItemList[0].(int)
|
||||
if subTaskID == 0 {
|
||||
stockInfo, err = api.JdAPI.QueryOpenUseable(batchSkuInfoList)
|
||||
} else {
|
||||
priceInfo, err = api.JdAPI.GetStationInfoList(vendorStoreID, batchSkuList)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(priceInfo, false))
|
||||
if len(batchSkuInfoList) > 0 {
|
||||
var stockInfo []*jdapi.QueryStockResponse
|
||||
var priceInfo []*jdapi.StorePriceInfo
|
||||
task := tasksch.NewParallelTask("获取京东到家平台门店商品信息", tasksch.NewParallelConfig().SetParallelCount(2), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
subTaskID := batchItemList[0].(int)
|
||||
if subTaskID == 0 {
|
||||
stockInfo, err = api.JdAPI.QueryOpenUseable(batchSkuInfoList)
|
||||
} else {
|
||||
priceInfo, err = api.JdAPI.GetStationInfoList(vendorStoreID, batchSkuList)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(priceInfo, false))
|
||||
}
|
||||
return nil, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
if err == nil {
|
||||
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
|
||||
for _, v := range inStoreSkuList {
|
||||
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
|
||||
}
|
||||
for _, v := range stockInfo {
|
||||
outStoreSkuList = append(outStoreSkuList, storeSkuMap[v.SkuID])
|
||||
storeSkuMap[v.SkuID].Status = jdStoreSkuStatus2Jx(v.Vendibility)
|
||||
}
|
||||
for _, v := range priceInfo {
|
||||
storeSkuMap[v.SkuID].Price = v.Price
|
||||
}
|
||||
return nil, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
if err == nil {
|
||||
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
|
||||
for _, v := range inStoreSkuList {
|
||||
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
|
||||
}
|
||||
for _, v := range stockInfo {
|
||||
storeSkuMap[v.SkuID].Status = jdStoreSkuStatus2Jx(v.Vendibility)
|
||||
}
|
||||
for _, v := range priceInfo {
|
||||
storeSkuMap[v.SkuID].Price = v.Price
|
||||
}
|
||||
outStoreSkuList = inStoreSkuList
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
||||
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||
vendorSkuIDList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDList()
|
||||
var vendorFoodList []*mtwmapi.AppFood
|
||||
if len(inStoreSkuList) > 1 {
|
||||
if len(vendorSkuIDList) > 1 {
|
||||
task := tasksch.NewParallelTask("获取饿百平台门店商品信息", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorSkuID := batchItemList[0].(string)
|
||||
@@ -220,11 +220,13 @@ func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask ta
|
||||
}, vendorSkuIDList)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
skuInfo, err2 := api.MtwmAPI.RetailGet(vendorStoreID, inStoreSkuList[0].VendorSkuID)
|
||||
} else if len(vendorSkuIDList) == 1 {
|
||||
skuInfo, err2 := api.MtwmAPI.RetailGet(vendorStoreID, vendorSkuIDList[0])
|
||||
if err = err2; err == nil {
|
||||
vendorFoodList = []*mtwmapi.AppFood{skuInfo}
|
||||
}
|
||||
} else {
|
||||
return nil, nil
|
||||
}
|
||||
if err == nil {
|
||||
storeSkuMap := make(map[string]*partner.BareStoreSkuInfo)
|
||||
@@ -234,10 +236,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.Price = jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0))
|
||||
storeSku.Status = mtwmSkuStatus2Jx(foodInfo.IsSoldOut)
|
||||
}
|
||||
outStoreSkuList = inStoreSkuList
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
@@ -76,6 +76,9 @@ func (c *StoreSkuController) GetStoreSkus() {
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||
// @Param isBySku query bool false "是否按SKU分拆"
|
||||
// @Param jdSyncStatus query int false "京东同步标识"
|
||||
// @Param ebaiSyncStatus query int false "饿百同步标识"
|
||||
// @Param mtwmSyncStatus query int false "美团外卖同步标识"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetStoresSkus [get]
|
||||
|
||||
Reference in New Issue
Block a user