根据名字查询upc码,获取京东等级修改

This commit is contained in:
苏尹岚
2019-12-16 16:12:56 +08:00
parent 1b4de9a762
commit 245e793ce3
2 changed files with 52 additions and 1 deletions

View File

@@ -1302,6 +1302,9 @@ func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productIn
pageSize = 30 pageSize = 30
pageNoList []int pageNoList []int
) )
if name == "" && upcCode == "" {
return nil, fmt.Errorf("至少输入一个条件查询商品名或者upc码")
}
for i := 1; i < pageNo+1; i++ { for i := 1; i < pageNo+1; i++ {
pageNoList = append(pageNoList, i) pageNoList = append(pageNoList, i)
} }
@@ -1312,6 +1315,16 @@ func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productIn
if err != nil { if err != nil {
return retVal, err return retVal, err
} }
if len(productInfo) > 0 {
for _, v := range productInfo {
productInfo2, _ := api.ShowAPI.GetProductInfoByBarCode(v.UpcCode)
if productInfo2 != nil {
v.Name = productInfo2.Name
v.SpecQuality = productInfo2.SpecQuality
v.SpecUnit = productInfo2.SpecUnit
}
}
}
retVal = productInfo retVal = productInfo
return retVal, err return retVal, err
}, pageNoList) }, pageNoList)

View File

@@ -36,6 +36,8 @@ type tJdStoreInfo struct {
VendorStoreID string `orm:"column(vendor_store_id)"` VendorStoreID string `orm:"column(vendor_store_id)"`
RealLastOperator string RealLastOperator string
SyncStatus int SyncStatus int
Level string
PageNo int
} }
var ( var (
@@ -91,7 +93,7 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendo
} }
} }
} }
if level, err := a.GetJdStoreLevel(vendorOrgCode, vendorStoreID); err == nil { if level, err := GetJdStoreLevel(ctx, vendorOrgCode, vendorStoreID); err == nil {
retVal.JdStoreLevel = level retVal.JdStoreLevel = level
} }
if retVal.DistrictCode == 0 { if retVal.DistrictCode == 0 {
@@ -118,6 +120,42 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendo
return nil, err return nil, err
} }
func GetJdStoreLevel(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID string) (level string, err error) {
var (
pageNoList []int
storeMap = make(map[int]string)
pageNo int
)
a := getAPI(vendorOrgCode)
for i := 1; i < 6; i++ {
pageNoList = append(pageNoList, i)
}
task := tasksch.NewParallelTask("获取京东商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
currentPage := batchItemList[0].(int)
level, err = a.GetJdStoreLevel(vendorOrgCode, vendorStoreID, currentPage)
if err != nil {
return retVal, err
}
tJdStoreInfo1 := &tJdStoreInfo{
Level: level,
PageNo: currentPage,
}
retVal = []*tJdStoreInfo{tJdStoreInfo1}
return retVal, err
}, pageNoList)
tasksch.HandleTask(task, nil, true).Run()
tJdStoreInfoInterface, err := task.GetResult(0)
for _, v := range tJdStoreInfoInterface {
store := v.(*tJdStoreInfo)
if store.PageNo > pageNo {
pageNo = store.PageNo
}
storeMap[store.PageNo] = store.Level
}
return storeMap[pageNo], err
}
// stoerIDs为nil表示所有 // stoerIDs为nil表示所有
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) { func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
var stores []*tJdStoreInfo var stores []*tJdStoreInfo