+ GetStoresSkus添加平台同步参数条件
+ GetStoreAbnoramlSkuCount + GetVendorStoreSkusInfo
This commit is contained in:
@@ -236,6 +236,7 @@ type IPurchasePlatformHandler interface {
|
||||
GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error)
|
||||
|
||||
GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error)
|
||||
GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*BareStoreSkuInfo) (outStoreSkuList []*BareStoreSkuInfo, err error)
|
||||
}
|
||||
|
||||
// db *dao.DaoDB,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
@@ -19,8 +20,8 @@ type BareStoreSkuInfo struct {
|
||||
NameID int `json:"nameID,omitempty"`
|
||||
VendorNameID string `json:"vendorNameID,omitempty"`
|
||||
|
||||
Price int `json:"prrice,omitempty"`
|
||||
Status int `json:"status,omitempty"`
|
||||
Price int64 `json:"price,omitempty"`
|
||||
Status int `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
type BareStoreSkuInfoList []*BareStoreSkuInfo
|
||||
@@ -33,6 +34,22 @@ func (l BareStoreSkuInfoList) GetVendorSkuIDList() (vendorSkuIDList []string) {
|
||||
return vendorSkuIDList
|
||||
}
|
||||
|
||||
func (l BareStoreSkuInfoList) GetVendorSkuIDIntList() (vendorSkuIDIntList []int64) {
|
||||
vendorSkuIDIntList = make([]int64, len(l))
|
||||
for k, v := range l {
|
||||
vendorSkuIDIntList[k] = 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
|
||||
}
|
||||
return skuIDList
|
||||
}
|
||||
|
||||
type BareCategoryInfo struct {
|
||||
VendorCatID string `json:"vendorCatID"`
|
||||
|
||||
|
||||
@@ -335,9 +335,11 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
return rootTask.ID, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int, parentTask tasksch.ITask) (skus []map[string]interface{}, err error) {
|
||||
func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int, parentTask tasksch.ITask) (skus []*ebaiapi.SkuInfo, err error) {
|
||||
globals.SugarLogger.Debugf("ebai GetAllRemoteSkus storeID:%d, userName:%s", storeID, ctx.GetUserName())
|
||||
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), utils.Params2Map("pagesize", MaxPageSize))
|
||||
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||
PageSize: MaxPageSize,
|
||||
})
|
||||
if err == nil {
|
||||
skus = append(skus, page1.List...)
|
||||
if page1.Pages > 1 {
|
||||
@@ -347,9 +349,9 @@ func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int,
|
||||
}
|
||||
task := tasksch.NewParallelTask("GetAllRemoteSkus", nil, ctx,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
callParams := map[string]interface{}{
|
||||
"pagesize": MaxPageSize,
|
||||
"page": batchItemList[0],
|
||||
callParams := &ebaiapi.SkuListParams{
|
||||
PageSize: MaxPageSize,
|
||||
Page: batchItemList[0].(int),
|
||||
}
|
||||
pageSku, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), callParams)
|
||||
if err2 == nil {
|
||||
@@ -362,7 +364,7 @@ func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int,
|
||||
result, err2 := task.GetResult(0)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range result {
|
||||
skus = append(skus, v.(map[string]interface{}))
|
||||
skus = append(skus, v.(*ebaiapi.SkuInfo))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -378,7 +380,7 @@ func (p *PurchaseHandler) DeleteRemoteSkus(ctx *jxcontext.Context, parentTask ta
|
||||
if err = err2; err == nil {
|
||||
vendorSkuIDs = make([]string, len(result))
|
||||
for k, v := range result {
|
||||
vendorSkuIDs[k] = utils.Interface2String(v[ebaiapi.KeySkuID])
|
||||
vendorSkuIDs[k] = utils.Int64ToStr(v.SkuID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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"
|
||||
@@ -190,3 +191,55 @@ 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) {
|
||||
vendorSkuIDIntList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||
var vendorSkuList []*ebaiapi.SkuInfo
|
||||
if len(inStoreSkuList) > 1 {
|
||||
task := tasksch.NewParallelTask("获取饿百平台门店商品信息", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorSkuID := batchItemList[0].(int64)
|
||||
skuInfo, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||
SkuID: vendorSkuID,
|
||||
})
|
||||
if err == nil {
|
||||
vendorSkuList = skuInfo.List
|
||||
return skuInfo.List, nil
|
||||
}
|
||||
return nil, err
|
||||
}, vendorSkuIDIntList)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
skuInfo, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||
SkuID: utils.Str2Int64(inStoreSkuList[0].VendorSkuID),
|
||||
})
|
||||
if err = err2; err == nil {
|
||||
vendorSkuList = skuInfo.List
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
|
||||
for _, v := range inStoreSkuList {
|
||||
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
|
||||
}
|
||||
for _, skuInfo := range vendorSkuList {
|
||||
storeSku := storeSkuMap[skuInfo.SkuID]
|
||||
storeSku.Price = skuInfo.SalePrice
|
||||
storeSku.Status = ebaiSkuStatus2Jx(skuInfo.Status)
|
||||
}
|
||||
outStoreSkuList = inStoreSkuList
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func ebaiSkuStatus2Jx(ebaiSkuStatus int) (jxSkuStatus int) {
|
||||
if ebaiSkuStatus == ebaiapi.SkuStatusOnline {
|
||||
jxSkuStatus = model.SkuStatusNormal
|
||||
} else if ebaiSkuStatus == ebaiapi.SkuStatusOffline {
|
||||
jxSkuStatus = model.SkuStatusDontSale
|
||||
} else if ebaiSkuStatus == ebaiapi.SkuStatusOnline {
|
||||
jxSkuStatus = model.SkuStatusDeleted
|
||||
}
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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/partner"
|
||||
)
|
||||
|
||||
func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||
@@ -29,3 +30,7 @@ func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTa
|
||||
func (p *PurchaseHandler) GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error) {
|
||||
return storeSkuList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
61
business/partner/purchase/jd/store_sku2.go
Normal file
61
business/partner/purchase/jd/store_sku2.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"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/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))
|
||||
batchSkuList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||
for k, v := range inStoreSkuList {
|
||||
batchSkuInfoList[k] = &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))
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func jdStoreSkuStatus2Jx(jdStoreSkuStatus int) (jxSkuStatus int) {
|
||||
if jdStoreSkuStatus == 0 {
|
||||
jxSkuStatus = model.SkuStatusNormal
|
||||
} else {
|
||||
jxSkuStatus = model.SkuStatusDontSale
|
||||
}
|
||||
return jxSkuStatus
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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"
|
||||
@@ -191,7 +192,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
||||
Skus: []*mtwmapi.BareStoreSkuInfo{
|
||||
&mtwmapi.BareStoreSkuInfo{
|
||||
SkuID: storeSku.VendorSkuID,
|
||||
Price: utils.Int2Str(storeSku.Price),
|
||||
Price: utils.Int64ToStr(storeSku.Price),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -202,3 +203,50 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(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) {
|
||||
vendorSkuIDList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDList()
|
||||
var vendorFoodList []*mtwmapi.AppFood
|
||||
if len(inStoreSkuList) > 1 {
|
||||
task := tasksch.NewParallelTask("获取饿百平台门店商品信息", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorSkuID := batchItemList[0].(string)
|
||||
skuInfo, err := api.MtwmAPI.RetailGet(vendorStoreID, vendorSkuID)
|
||||
if err == nil {
|
||||
vendorFoodList = []*mtwmapi.AppFood{skuInfo}
|
||||
return vendorFoodList, nil
|
||||
}
|
||||
return nil, err
|
||||
}, vendorSkuIDList)
|
||||
tasksch.HandleTask(task, parentTask, false).Run()
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
skuInfo, err2 := api.MtwmAPI.RetailGet(vendorStoreID, inStoreSkuList[0].VendorSkuID)
|
||||
if err = err2; err == nil {
|
||||
vendorFoodList = []*mtwmapi.AppFood{skuInfo}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
storeSkuMap := make(map[string]*partner.BareStoreSkuInfo)
|
||||
for _, v := range inStoreSkuList {
|
||||
storeSkuMap[v.VendorSkuID] = v
|
||||
}
|
||||
for _, foodInfo := range vendorFoodList {
|
||||
vendorSku := foodInfo.SkuList[0]
|
||||
storeSku := storeSkuMap[vendorSku.SkuID]
|
||||
storeSku.Price = jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0))
|
||||
storeSku.Status = mtwmSkuStatus2Jx(foodInfo.IsSoldOut)
|
||||
}
|
||||
outStoreSkuList = inStoreSkuList
|
||||
}
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func mtwmSkuStatus2Jx(mtwmSkuStatus int) (jxSkuStatus int) {
|
||||
if mtwmSkuStatus == 0 {
|
||||
jxSkuStatus = model.SkuStatusNormal
|
||||
} else {
|
||||
jxSkuStatus = model.SkuStatusDontSale
|
||||
}
|
||||
return jxSkuStatus
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"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"
|
||||
@@ -185,3 +186,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
||||
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) {
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user