商品子分类下商品的重排序

This commit is contained in:
Rosy-zhudan
2019-08-30 08:58:37 +08:00
parent bfa6ca2b9e
commit e0bbfa0150
4 changed files with 95 additions and 13 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"strconv"
"strings"
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
@@ -468,7 +467,7 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
"}")), "]") skus_str,
CONCAT("[", GROUP_CONCAT(DISTINCT t3.place_code), "]") places_str
` + sql + `
ORDER BY t1.id DESC
ORDER BY MIN(t2.seq), t1.id DESC
LIMIT ? OFFSET ?`
pageSize = jxutils.FormalizePageSize(pageSize)
if offset < 0 {
@@ -1042,4 +1041,58 @@ func UploadImg2Platforms(ctx *jxcontext.Context, parentTask tasksch.ITask, imgUR
}
}
return imgHintMap, err
}
func SortCategorySku(ctx *jxcontext.Context, catID int, skuIDList []int) (err error) {
db := dao.GetDB()
userName := ctx.GetUserName()
var skuList []*model.Sku
if skuList, err = dao.GetSkuByCats(db, []int{catID}); err == nil && len(skuList) > 0 {
if len(skuList) == len(skuIDList) {
skuIDMap := make(map[int]int)
for index, id := range skuIDList {
skuIDMap[id] = index + 1
}
for _, value := range skuList {
if _, ok := skuIDMap[value.ID]; !ok {
err = errors.New("商品数据不匹配!")
break
}
}
dao.Begin(db)
defer func() {
if r := recover(); r != nil || err != nil {
dao.Rollback(db)
if r != nil {
panic(r)
}
}
}()
for _, value := range skuList {
seq := skuIDMap[value.ID]
kvs := map[string]interface{} {
"seq": seq,
}
dao.UpdateEntityLogically(db, value, kvs, userName, nil)
sku := &model.Sku{}
sku.ID = value.ID
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, sku, nil, ctx.GetUserName(), nil, model.FieldJdSyncStatus, model.SyncFlagModifiedMask)
nameID := value.NameID
skuIDs, err2 := dao.GetSkuIDByNames(db, []int{nameID})
if err = err2; err == nil && len(skuIDs) > 0 {
_, err = SetStoreSkuSyncStatus2(db, nil, partner.GetSingleStoreVendorIDs(), skuIDs, model.SyncFlagModifiedMask)
}
if err == nil {
dao.Commit(db)
_, err = CurVendorSync.SyncSku(ctx, db, nameID, -1, false, false, userName)
}
}
} else {
err = errors.New("商品数量不匹配!")
}
}
return err
}