分类与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)
|
||||
}
|
||||
sql := "SELECT * FROM sku_category WHERE deleted_at = ?"
|
||||
if parentID != -1 {
|
||||
sql += " AND parent_id = ?"
|
||||
params = append(params, parentID)
|
||||
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 += " 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,7 +1373,8 @@ func BuildSkuFromEbaiStore(ctx *jxcontext.Context, baiduShopID int64, isAsync, i
|
||||
skuNameExt.Price = int(float32(skuNameExt.Price) * 500 / tmpSpecQuality)
|
||||
}
|
||||
}
|
||||
mySku := &model.Sku{
|
||||
mySku := &model.SkuWithVendor{
|
||||
Sku: &model.Sku{
|
||||
// CategoryID:
|
||||
// NameID:
|
||||
Comment: comment,
|
||||
@@ -1383,6 +1384,7 @@ func BuildSkuFromEbaiStore(ctx *jxcontext.Context, baiduShopID int64, isAsync, i
|
||||
Status: model.SkuStatusNormal,
|
||||
|
||||
LinkID: int(jxutils.StandardPrice2Int(utils.MustInterface2Float64(sku["sale_price"]))), // 临时传递价格用
|
||||
},
|
||||
}
|
||||
if sku["enabled"].(string) == "0" {
|
||||
mySku.Status = model.SkuStatusDontSale
|
||||
|
||||
@@ -13,6 +13,11 @@ type tStoreSkuSyncInfo2 struct {
|
||||
VendorPlaceCode string
|
||||
}
|
||||
|
||||
type SkuCategoryWithVendor struct {
|
||||
*model.SkuCategory
|
||||
MapList []*model.ThingMap `json:"mapList"`
|
||||
}
|
||||
|
||||
func GetSellCities(db *DaoDB, nameID int, vendorID int) (cities []*model.Place, err error) {
|
||||
cities = []*model.Place{}
|
||||
sql := `
|
||||
@@ -44,6 +49,26 @@ func DeleteSkuNamePlace(db *DaoDB, nameID int, placeCodes []int) (num int64, err
|
||||
return ExecuteSQL(db, sql, sqlParams...)
|
||||
}
|
||||
|
||||
func GetCategories(db *DaoDB, parentID int, catIDs []int) (cats []*model.SkuCategory, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM sku_category t1
|
||||
WHERE t1.deleted_at = ?`
|
||||
params := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if parentID != -1 {
|
||||
sql += " AND t1.parent_id = ?"
|
||||
params = append(params, parentID)
|
||||
}
|
||||
if len(catIDs) > 0 {
|
||||
sql += " AND t1.id (" + GenQuestionMarks(len(catIDs)) + ")"
|
||||
params = append(params, catIDs)
|
||||
}
|
||||
sql += " ORDER BY t1.level, t1.seq"
|
||||
return cats, GetRows(db, &cats, sql, params)
|
||||
}
|
||||
|
||||
func GetSkus(db *DaoDB, skuIDs, nameIDs, statuss, catIDs []int) (skuList []*model.SkuAndName, err error) {
|
||||
sql := `
|
||||
SELECT t1.*, t2.name, t2.unit, t2.prefix, t2.is_spu
|
||||
|
||||
34
business/model/dao/thing_map.go
Normal file
34
business/model/dao/thing_map.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package dao
|
||||
|
||||
import "git.rosy.net.cn/jx-callback/business/model"
|
||||
|
||||
import "git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
func GetThingMapList(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (cats []*model.ThingMap, err error) {
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM thing_map t1
|
||||
WHERE t1.deleted_at = ? AND t1.thing_type = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
thingType,
|
||||
}
|
||||
if len(thingIDs) > 0 { // 必须要指定ID
|
||||
sql += " AND t1.thing_id IN (" + GenQuestionMarks(len(thingIDs)) + ")"
|
||||
sqlParams = append(sqlParams, thingIDs)
|
||||
err = GetRows(db, &cats, sql, sqlParams...)
|
||||
}
|
||||
return cats, err
|
||||
}
|
||||
|
||||
func GetThingMapMap(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (thingMapMap map[int64][]*model.ThingMap, err error) {
|
||||
thingMapList, err := GetThingMapList(db, thingType, vendorIDs, thingIDs)
|
||||
if err == nil {
|
||||
thingMapMap = make(map[int64][]*model.ThingMap)
|
||||
for _, thingMap := range thingMapList {
|
||||
thingMapMap[thingMap.ThingID] = append(thingMapMap[thingMap.ThingID], thingMap)
|
||||
}
|
||||
}
|
||||
return thingMapMap, err
|
||||
}
|
||||
@@ -248,9 +248,14 @@ func (*SkuNamePlaceBind) TableUnique() [][]string {
|
||||
}
|
||||
}
|
||||
|
||||
type SkuWithVendor struct {
|
||||
*Sku
|
||||
MapList []*ThingMap `json:"mapList"`
|
||||
}
|
||||
|
||||
type SkuNameExt struct {
|
||||
SkuName
|
||||
Skus []*Sku `orm:"-" json:"skus"`
|
||||
Skus []*SkuWithVendor `orm:"-" json:"skus"`
|
||||
SkusStr string `json:"-"`
|
||||
|
||||
Places []int `orm:"-" json:"places"`
|
||||
|
||||
@@ -49,6 +49,8 @@ func (p *PurchaseHandler) CreateCategory(db *dao.DaoDB, cat *model.SkuCategory,
|
||||
cat.JdID = jdID
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cat.JdID = jxutils.GenFakeID()
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -168,6 +170,8 @@ func (p *PurchaseHandler) CreateSku(db *dao.DaoDB, sku *model.Sku, userName stri
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vendorSkuID = utils.Int64ToStr(jxutils.GenFakeID())
|
||||
}
|
||||
} else {
|
||||
vendorSkuID, err = p.syncSkuNameAsSpu(db, sku, skuExt, price, skuName, shopCategories, addParams)
|
||||
@@ -201,8 +205,9 @@ func (p *PurchaseHandler) ReadSku(ctx *jxcontext.Context, vendorOrgCode, vendorS
|
||||
skuNameExt.Name = name
|
||||
skuNameExt.Unit = unit
|
||||
skuNameExt.Price = sku.SkuPrice
|
||||
skuNameExt.Skus = []*model.Sku{
|
||||
&model.Sku{
|
||||
skuNameExt.Skus = []*model.SkuWithVendor{
|
||||
&model.SkuWithVendor{
|
||||
Sku: &model.Sku{
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Weight: jxutils.FloatWeight2Int(float32(sku.Weight)),
|
||||
@@ -210,6 +215,7 @@ func (p *PurchaseHandler) ReadSku(ctx *jxcontext.Context, vendorOrgCode, vendorS
|
||||
Status: jdStatus2jxStatus(sku.FixedStatus),
|
||||
Comment: comment,
|
||||
},
|
||||
},
|
||||
}
|
||||
skuNameExt.Skus[0].ID = int(utils.Str2Int64(sku.OutSkuID))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user