商品子分类下商品的重排序
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -221,17 +221,17 @@ func (*SkuName) TableUnique() [][]string {
|
||||
type Sku struct {
|
||||
ModelIDCULD
|
||||
|
||||
CategoryID int `orm:"column(category_id)" json:"categoryID"` // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
||||
NameID int `orm:"column(name_id)" json:"nameID"` // todo 这个索引应该要求唯一
|
||||
SkuIndex int `json:"-"`
|
||||
Comment string `orm:"size(255)" json:"comment"`
|
||||
SpecQuality float32 `json:"specQuality"`
|
||||
SpecUnit string `orm:"size(8)" json:"specUnit"` // 质量或容量
|
||||
Weight int `json:"weight"` // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
Status int `json:"status"`
|
||||
|
||||
JdID int64 `orm:"column(jd_id);null;index" json:"jdID"`
|
||||
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
|
||||
CategoryID int `orm:"column(category_id)" json:"categoryID"` // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
||||
NameID int `orm:"column(name_id)" json:"nameID"` // todo 这个索引应该要求唯一
|
||||
SkuIndex int `json:"-"`
|
||||
Comment string `orm:"size(255)" json:"comment"`
|
||||
SpecQuality float32 `json:"specQuality"`
|
||||
SpecUnit string `orm:"size(8)" json:"specUnit"` // 质量或容量
|
||||
Weight int `json:"weight"` // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
Status int `json:"status"`
|
||||
Seq int `json:"seq"`
|
||||
JdID int64 `orm:"column(jd_id);null;index" json:"jdID"`
|
||||
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
|
||||
|
||||
LinkID int `orm:"column(link_id);null;index" json:"linkID"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -339,3 +340,22 @@ func (c *SkuController) GetSensitiveWordList() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 子分类下商品的重排序
|
||||
// @Description 子分类下商品的重排序
|
||||
// @Param token header string true "认证token"
|
||||
// @Param catID formData int true "商品子分类"
|
||||
// @Param skuIDs formData string true "商品子分类下商品列表"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SortCategorySku [post]
|
||||
func (c *SkuController) SortCategorySku() {
|
||||
c.callSortCategorySku(func(params *tSkuSortCategorySkuParams) (retVal interface{}, errCode string, err error) {
|
||||
var skuIDList []int
|
||||
if err = jxutils.Strings2Objs(params.SkuIDs, &skuIDList); err == nil {
|
||||
err = cms.SortCategorySku(params.Ctx, params.CatID, skuIDList)
|
||||
}
|
||||
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1105,6 +1105,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SortCategorySku",
|
||||
Router: `/SortCategorySku`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "SyncCategory",
|
||||
|
||||
Reference in New Issue
Block a user