Merge branch 'mark' of e.coding.net:rosydev/jx-callback into mark

This commit is contained in:
gazebo
2019-12-16 16:17:50 +08:00
7 changed files with 129 additions and 22 deletions

View File

@@ -7,6 +7,10 @@ import (
"strings"
"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/baseapi/utils"
@@ -1292,16 +1296,42 @@ func SortCategorySkus(ctx *jxcontext.Context, catID int, skuIDList []int) (err e
return err
}
func GetJdUpcCodeByName(ctx *jxcontext.Context, name string) (pagedInfo *model.PagedInfo, err error) {
pageNo := 1
pageSize := 30
jdSkus, totalCount, err := api.JdAPI.GetJdUpcCodeByName(name, pageNo, pageSize)
for _, v := range jdSkus {
fmt.Println(v)
func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) {
var (
pageNo = 5
pageSize = 30
pageNoList []int
)
if name == "" && upcCode == "" {
return nil, fmt.Errorf("至少输入一个条件查询商品名或者upc码")
}
pagedInfo = &model.PagedInfo{
Data: jdSkus,
TotalCount: totalCount,
for i := 1; i < pageNo+1; i++ {
pageNoList = append(pageNoList, i)
}
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
}

View File

@@ -2140,17 +2140,38 @@ func GetTopSkusByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (storeSkuNameE
}
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 {
return skuCategory, err
}
db := dao.GetDB()
skuCategory, err = dao.GetTopCategorysByStoreIDs(db, storeIDs)
if len(skuCategory) < 10 {
skuCategory, err = dao.GetTopCategorysByStoreIDs(db, storeIDs, limit)
//若大于等于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)
if len(skuCategory2) > 0 {
for i := 0; i < 10-len(skuCategory); i++ {
skuCategory = append(skuCategory, skuCategory2[i])
for _, v := range skuCategory2 {
if skuCategoryMap[v.ID] == nil {
if !strings.Contains(v.Name, "赠品") {
skuCategory = append(skuCategory, v)
}
}
if len(skuCategory) >= limit {
break
}
}
}
}

View File

@@ -83,3 +83,20 @@ type OrderFinancialSkuExt struct {
OrderSkuFinancial
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"`
}

View File

@@ -984,7 +984,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSk
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 := `
SELECT DISTINCT t5.* FROM(
SELECT d.*
@@ -1023,7 +1023,7 @@ func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.
Order by t4.count DESC)t5
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...)
return skuCategory, err
}

View File

@@ -36,6 +36,8 @@ type tJdStoreInfo struct {
VendorStoreID string `orm:"column(vendor_store_id)"`
RealLastOperator string
SyncStatus int
Level string
PageNo int
}
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
}
if retVal.DistrictCode == 0 {
@@ -118,6 +120,42 @@ func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendo
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表示所有
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
var stores []*tJdStoreInfo

View File

@@ -379,13 +379,14 @@ func (c *SkuController) GetStoreSkuSalesInfo() {
// @Title 根据名字查询京东商品UPC信息
// @Description 根据名字查询京东商品UPC信息
// @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
// @Failure 200 {object} controllers.CallResult
// @router /GetJdUpcCodeByName [post]
// @router /GetJdUpcCodeByName [get]
func (c *SkuController) GetJdUpcCodeByName() {
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
})
}

View File

@@ -1174,7 +1174,7 @@ func init() {
beego.ControllerComments{
Method: "GetJdUpcCodeByName",
Router: `/GetJdUpcCodeByName`,
AllowHTTPMethods: []string{"post"},
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})