分类与sku返回mapList信息
This commit is contained in:
@@ -52,17 +52,26 @@ func GetVendorCategories(ctx *jxcontext.Context, vendorID int, parentID string)
|
||||
}
|
||||
|
||||
// parentID 为-1表示所有
|
||||
func GetCategories(ctx *jxcontext.Context, parentID int) (cats []*model.SkuCategory, err error) {
|
||||
params := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
func GetCategories(ctx *jxcontext.Context, parentID int) (catList []*dao.SkuCategoryWithVendor, err error) {
|
||||
db := dao.GetDB()
|
||||
cats, err := dao.GetCategories(db, parentID, nil)
|
||||
if err == nil {
|
||||
var ids []int
|
||||
for _, v := range cats {
|
||||
ids = append(ids, v.ID)
|
||||
}
|
||||
thingMapMap, err2 := dao.GetThingMapMap(db, model.ThingTypeCategory, nil, ids)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(thingMapMap, false))
|
||||
if err = err2; err == nil {
|
||||
for _, v := range cats {
|
||||
catList = append(catList, &dao.SkuCategoryWithVendor{
|
||||
SkuCategory: v,
|
||||
MapList: thingMapMap[int64(v.ID)],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
sql := "SELECT * FROM sku_category WHERE deleted_at = ?"
|
||||
if parentID != -1 {
|
||||
sql += " AND parent_id = ?"
|
||||
params = append(params, parentID)
|
||||
}
|
||||
sql += " ORDER BY level, seq"
|
||||
return cats, dao.GetRows(nil, &cats, sql, params)
|
||||
return catList, err
|
||||
}
|
||||
|
||||
func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string) (outCat *model.SkuCategory, err error) {
|
||||
@@ -532,12 +541,17 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
|
||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
dao.Commit(db)
|
||||
|
||||
var skuIDs []int
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
if skuName.SkusStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range skuName.Skus {
|
||||
skuIDs = append(skuIDs, v.ID)
|
||||
}
|
||||
}
|
||||
if skuName.PlacesStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(skuName.PlacesStr), &skuName.Places); err != nil {
|
||||
@@ -546,6 +560,16 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
thingMapMap, err2 := dao.GetThingMapMap(db, model.ThingTypeSku, nil, skuIDs)
|
||||
if err = err2; err == nil {
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
for _, v := range skuName.Skus {
|
||||
v.MapList = thingMapMap[int64(v.ID)]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
|
||||
@@ -1373,16 +1373,18 @@ func BuildSkuFromEbaiStore(ctx *jxcontext.Context, baiduShopID int64, isAsync, i
|
||||
skuNameExt.Price = int(float32(skuNameExt.Price) * 500 / tmpSpecQuality)
|
||||
}
|
||||
}
|
||||
mySku := &model.Sku{
|
||||
// CategoryID:
|
||||
// NameID:
|
||||
Comment: comment,
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Weight: int(utils.Str2Int64(utils.Interface2String(sku["weight"]))),
|
||||
Status: model.SkuStatusNormal,
|
||||
mySku := &model.SkuWithVendor{
|
||||
Sku: &model.Sku{
|
||||
// CategoryID:
|
||||
// NameID:
|
||||
Comment: comment,
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Weight: int(utils.Str2Int64(utils.Interface2String(sku["weight"]))),
|
||||
Status: model.SkuStatusNormal,
|
||||
|
||||
LinkID: int(jxutils.StandardPrice2Int(utils.MustInterface2Float64(sku["sale_price"]))), // 临时传递价格用
|
||||
LinkID: int(jxutils.StandardPrice2Int(utils.MustInterface2Float64(sku["sale_price"]))), // 临时传递价格用
|
||||
},
|
||||
}
|
||||
if sku["enabled"].(string) == "0" {
|
||||
mySku.Status = model.SkuStatusDontSale
|
||||
|
||||
Reference in New Issue
Block a user