Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark
This commit is contained in:
@@ -7,6 +7,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -1292,16 +1296,42 @@ func SortCategorySkus(ctx *jxcontext.Context, catID int, skuIDList []int) (err e
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetJdUpcCodeByName(ctx *jxcontext.Context, name string) (pagedInfo *model.PagedInfo, err error) {
|
func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) {
|
||||||
pageNo := 1
|
var (
|
||||||
pageSize := 30
|
pageNo = 5
|
||||||
jdSkus, totalCount, err := api.JdAPI.GetJdUpcCodeByName(name, pageNo, pageSize)
|
pageSize = 30
|
||||||
for _, v := range jdSkus {
|
pageNoList []int
|
||||||
fmt.Println(v)
|
)
|
||||||
|
if name == "" && upcCode == "" {
|
||||||
|
return nil, fmt.Errorf("至少输入一个条件查询,商品名或者upc码!")
|
||||||
}
|
}
|
||||||
pagedInfo = &model.PagedInfo{
|
for i := 1; i < pageNo+1; i++ {
|
||||||
Data: jdSkus,
|
pageNoList = append(pageNoList, i)
|
||||||
TotalCount: totalCount,
|
|
||||||
}
|
}
|
||||||
return pagedInfo, err
|
task := tasksch.NewParallelTask("获取京东商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
pageNum := batchItemList[0].(int)
|
||||||
|
productInfo, err := api.JdAPI.GetJdUpcCodeByName(name, upcCode, pageNum, pageSize)
|
||||||
|
if err != nil {
|
||||||
|
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
|
||||||
|
return retVal, err
|
||||||
|
}, pageNoList)
|
||||||
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
productInfoInterface, err := task.GetResult(0)
|
||||||
|
for _, v := range productInfoInterface {
|
||||||
|
productInfos = append(productInfos, v.(*jdapi.ProductInfo))
|
||||||
|
}
|
||||||
|
return productInfos, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2140,17 +2140,38 @@ func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameE
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
|
func GetTopCategorysByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
|
||||||
var skuCategory2 []*model.SkuCategory
|
var (
|
||||||
|
skuCategory2 []*model.SkuCategory
|
||||||
|
skuCategoryMap = make(map[int]*model.SkuCategory)
|
||||||
|
limit = 10
|
||||||
|
)
|
||||||
if len(storeIDs) == 0 {
|
if len(storeIDs) == 0 {
|
||||||
return skuCategory, err
|
return skuCategory, err
|
||||||
}
|
}
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
skuCategory, err = dao.GetTopCategorysByStoreIDs(db, storeIDs)
|
skuCategory, err = dao.GetTopCategorysByStoreIDs(db, storeIDs, limit)
|
||||||
if len(skuCategory) < 10 {
|
//若大于等于10个就不用做下面的操作
|
||||||
|
if len(skuCategory) >= limit {
|
||||||
|
return skuCategory, err
|
||||||
|
}
|
||||||
|
if len(skuCategory) > 0 {
|
||||||
|
for _, v := range skuCategory {
|
||||||
|
skuCategoryMap[v.ID] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//推荐分类,若不满10个,则填满10个
|
||||||
|
if (len(skuCategory) < limit && len(skuCategory) > 0) || len(skuCategory) == 0 {
|
||||||
skuCategory2, err = dao.GetCategories(db, -1, 1, nil)
|
skuCategory2, err = dao.GetCategories(db, -1, 1, nil)
|
||||||
if len(skuCategory2) > 0 {
|
if len(skuCategory2) > 0 {
|
||||||
for i := 0; i < 10-len(skuCategory); i++ {
|
for _, v := range skuCategory2 {
|
||||||
skuCategory = append(skuCategory, skuCategory2[i])
|
if skuCategoryMap[v.ID] == nil {
|
||||||
|
if !strings.Contains(v.Name, "赠品") {
|
||||||
|
skuCategory = append(skuCategory, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(skuCategory) >= limit {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,3 +83,20 @@ type OrderFinancialSkuExt struct {
|
|||||||
OrderSkuFinancial
|
OrderSkuFinancial
|
||||||
Image string `json:"image"`
|
Image string `json:"image"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProductInfo struct {
|
||||||
|
OriginalName string `json:"originalName"`
|
||||||
|
OriginalSpec string `json:"originalSpec"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Img string `json:"img"`
|
||||||
|
ImgList []string `json:"imgList"`
|
||||||
|
SpecQuality int `json:"specQuality"`
|
||||||
|
SpecUnit string `json:"specUnit"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
Weight float32 `json:"weight"`
|
||||||
|
Price int `json:"price"`
|
||||||
|
Categories []string `json:"categories"`
|
||||||
|
ManName string `json:"manName"` // 生产商
|
||||||
|
BrandName string `json:"brandName"`
|
||||||
|
UpcCode string `json:"upcCode"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -984,7 +984,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk
|
|||||||
return storeSkuNameExt, err
|
return storeSkuNameExt, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
|
func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int, limit int) (skuCategory []*model.SkuCategory, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT DISTINCT t5.* FROM(
|
SELECT DISTINCT t5.* FROM(
|
||||||
SELECT d.*
|
SELECT d.*
|
||||||
@@ -1023,7 +1023,7 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.
|
|||||||
Order by t4.count DESC)t5
|
Order by t4.count DESC)t5
|
||||||
LIMIT ?
|
LIMIT ?
|
||||||
`
|
`
|
||||||
sqlParams = append(sqlParams, time.Now().AddDate(0, -1, 0), 100, 2, utils.DefaultTimeValue, 1, 10)
|
sqlParams = append(sqlParams, time.Now().AddDate(0, -1, 0), 100, 2, utils.DefaultTimeValue, 1, limit)
|
||||||
err = GetRows(db, &skuCategory, sql, sqlParams...)
|
err = GetRows(db, &skuCategory, sql, sqlParams...)
|
||||||
return skuCategory, err
|
return skuCategory, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -379,13 +379,14 @@ func (c *SkuController) GetStoreSkuSalesInfo() {
|
|||||||
// @Title 根据名字查询京东商品UPC信息
|
// @Title 根据名字查询京东商品UPC信息
|
||||||
// @Description 根据名字查询京东商品UPC信息
|
// @Description 根据名字查询京东商品UPC信息
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
// @Param name formData string true "商品名"
|
// @Param name query string false "商品名"
|
||||||
|
// @Param upcCode query string false "upcCode,不支持模糊"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /GetJdUpcCodeByName [post]
|
// @router /GetJdUpcCodeByName [get]
|
||||||
func (c *SkuController) GetJdUpcCodeByName() {
|
func (c *SkuController) GetJdUpcCodeByName() {
|
||||||
c.callGetJdUpcCodeByName(func(params *tSkuGetJdUpcCodeByNameParams) (retVal interface{}, errCode string, err error) {
|
c.callGetJdUpcCodeByName(func(params *tSkuGetJdUpcCodeByNameParams) (retVal interface{}, errCode string, err error) {
|
||||||
retVal, err = cms.GetJdUpcCodeByName(params.Ctx, params.Name)
|
retVal, err = cms.GetJdUpcCodeByName(params.Ctx, params.Name, params.UpcCode)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1174,7 +1174,7 @@ func init() {
|
|||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetJdUpcCodeByName",
|
Method: "GetJdUpcCodeByName",
|
||||||
Router: `/GetJdUpcCodeByName`,
|
Router: `/GetJdUpcCodeByName`,
|
||||||
AllowHTTPMethods: []string{"post"},
|
AllowHTTPMethods: []string{"get"},
|
||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|||||||
Reference in New Issue
Block a user