- UpdateStoresSkusByBind
This commit is contained in:
@@ -64,6 +64,7 @@ type StoreSkuBindSkuInfo struct {
|
|||||||
|
|
||||||
// UpdateStoreSku用,API调用时
|
// UpdateStoreSku用,API调用时
|
||||||
type StoreSkuBindInfo struct {
|
type StoreSkuBindInfo struct {
|
||||||
|
StoreID int `json:"storeID"`
|
||||||
NameID int `json:"nameID"`
|
NameID int `json:"nameID"`
|
||||||
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
||||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||||
@@ -97,6 +98,11 @@ type StoreOpRequestInfo struct {
|
|||||||
UnitPrice int `json:"unitPrice"`
|
UnitPrice int `json:"unitPrice"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxStoreNameBind = 3000 // 最大门店SkuName bind个数
|
||||||
|
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||||
|
)
|
||||||
|
|
||||||
func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword string, isBySku bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *StoreSkuNamesInfo, err error) {
|
||||||
return GetStoresSkus(ctx, []int{storeID}, isFocus, keyword, isBySku, params, offset, pageSize)
|
return GetStoresSkus(ctx, []int{storeID}, isFocus, keyword, isBySku, params, offset, pageSize)
|
||||||
}
|
}
|
||||||
@@ -540,23 +546,64 @@ func UpdateStoreSku(ctx *jxcontext.Context, storeID int, skuBindInfo *StoreSkuBi
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func UpdateStoreSkus(ctx *jxcontext.Context, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
// skuIDs, err := updateStoresSkusWithoutSync(ctx, []int{storeID}, skuBindInfos)
|
|
||||||
// num = int64(len(skuIDs))
|
|
||||||
// if err == nil && num > 0 {
|
|
||||||
// db := dao.GetDB()
|
|
||||||
// _, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, []int{storeID}, skuIDs, false, false)
|
|
||||||
// return int64(len(skuIDs)), err
|
|
||||||
// }
|
|
||||||
// return 0, err
|
|
||||||
return UpdateStoresSkus(ctx, []int{storeID}, skuBindInfos, isAsync, isContinueWhenError)
|
return UpdateStoresSkus(ctx, []int{storeID}, skuBindInfos, isAsync, isContinueWhenError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func UpdateStoresSkus(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
var num int64
|
var num int64
|
||||||
skuIDs, err := updateStoresSkusWithoutSync(ctx, storeIDs, skuBindInfos)
|
db := dao.GetDB()
|
||||||
|
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
num = int64(len(skuIDs))
|
num = int64(len(skuIDs))
|
||||||
if num > 0 {
|
if num > 0 {
|
||||||
db := dao.GetDB()
|
hint, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||||
|
}
|
||||||
|
if num == 0 || !isAsync || hint == "" {
|
||||||
|
hint = utils.Int64ToStr(num)
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateStoresSkusByBind(ctx *jxcontext.Context, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
if len(skuBindInfos) > maxStoreNameBind {
|
||||||
|
return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind)
|
||||||
|
}
|
||||||
|
skuBindInfosMap := make(map[int][]*StoreSkuBindInfo)
|
||||||
|
storeIDMap := make(map[int]int)
|
||||||
|
for _, v := range skuBindInfos {
|
||||||
|
if v.StoreID > 9 {
|
||||||
|
skuBindInfosMap[v.StoreID] = append(skuBindInfosMap[v.StoreID], v)
|
||||||
|
storeIDMap[v.StoreID] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storeIDs := jxutils.IntMap2List(storeIDMap)
|
||||||
|
sort.Ints(storeIDs)
|
||||||
|
var num int64
|
||||||
|
skuIDMap := make(map[int]int)
|
||||||
|
db := dao.GetDB()
|
||||||
|
dao.Begin(db)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
for _, storeID := range storeIDs {
|
||||||
|
skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID])
|
||||||
|
if err = err2; err != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
for _, v := range skuIDs {
|
||||||
|
skuIDMap[v] = 1
|
||||||
|
}
|
||||||
|
num += int64(len(skuIDs))
|
||||||
|
}
|
||||||
|
dao.Commit(db)
|
||||||
|
if num > 0 {
|
||||||
|
skuIDs := jxutils.IntMap2List(skuIDMap)
|
||||||
hint, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
hint, err = CurVendorSync.SyncStoresSkus(ctx, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||||
}
|
}
|
||||||
if num == 0 || !isAsync || hint == "" {
|
if num == 0 || !isAsync || hint == "" {
|
||||||
@@ -627,13 +674,19 @@ func uniqueStoreNameBind(skuBindInfos []*StoreSkuBindInfo) (outSkuBindInfos []*S
|
|||||||
return outSkuBindInfos
|
return outSkuBindInfos
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo) (needSyncSkus []int, err error) {
|
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo) (needSyncSkus []int, err error) {
|
||||||
|
if len(storeIDs)*len(skuBindInfos) > maxStoreNameBind2 {
|
||||||
|
return nil, fmt.Errorf("门店商品信息大于%d", maxStoreNameBind2)
|
||||||
|
}
|
||||||
|
|
||||||
storeIDs = uniqueStoreIDs(storeIDs)
|
storeIDs = uniqueStoreIDs(storeIDs)
|
||||||
skuBindInfos = uniqueStoreNameBind(skuBindInfos)
|
skuBindInfos = uniqueStoreNameBind(skuBindInfos)
|
||||||
|
|
||||||
sort.Ints(storeIDs)
|
sort.Ints(storeIDs)
|
||||||
globals.SugarLogger.Debugf("updateStoresSkusWithoutSync, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false))
|
globals.SugarLogger.Debugf("updateStoresSkusWithoutSync, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false))
|
||||||
db := dao.GetDB()
|
if db == nil {
|
||||||
|
db = dao.GetDB()
|
||||||
|
}
|
||||||
// if err = checkStoresSkusSaleCity(ctx, db, storeIDs, skuBindInfos); err != nil {
|
// if err = checkStoresSkusSaleCity(ctx, db, storeIDs, skuBindInfos); err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
// }
|
// }
|
||||||
@@ -644,14 +697,14 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBind
|
|||||||
|
|
||||||
userName := ctx.GetUserName()
|
userName := ctx.GetUserName()
|
||||||
needSyncIDMap := make(map[int]int)
|
needSyncIDMap := make(map[int]int)
|
||||||
|
dao.Begin(db)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
for _, storeID := range storeIDs {
|
for _, storeID := range storeIDs {
|
||||||
dao.Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
dao.Rollback(db)
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for _, skuBindInfo := range skuBindInfos {
|
for _, skuBindInfo := range skuBindInfos {
|
||||||
inSkuBinds := skuBindInfo.Skus
|
inSkuBinds := skuBindInfo.Skus
|
||||||
var allBinds []*tStoreSkuBindAndSpec
|
var allBinds []*tStoreSkuBindAndSpec
|
||||||
@@ -799,8 +852,8 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBind
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dao.Commit(db)
|
|
||||||
}
|
}
|
||||||
|
dao.Commit(db)
|
||||||
skuIDs := jxutils.IntMap2List(needSyncIDMap)
|
skuIDs := jxutils.IntMap2List(needSyncIDMap)
|
||||||
return skuIDs, err
|
return skuIDs, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,6 +217,26 @@ func (c *StoreSkuController) UpdateStoresSkus() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 按门店商品维度批量修改多商家商品绑定
|
||||||
|
// @Description 按门店商品维度批量修改多商家商品绑定
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param payload formData string true "json数据,StoreSkuBindInfo对象数组"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Param isAsync formData bool false "是否异步操作"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /UpdateStoresSkusByBind [put]
|
||||||
|
func (c *StoreSkuController) UpdateStoresSkusByBind() {
|
||||||
|
c.callUpdateStoresSkusByBind(func(params *tStoreSkuUpdateStoresSkusByBindParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var skuBindInfos []*cms.StoreSkuBindInfo
|
||||||
|
if err = jxutils.Strings2Objs(params.Payload, &skuBindInfos); err != nil {
|
||||||
|
return retVal, "", err
|
||||||
|
}
|
||||||
|
retVal, err = cms.UpdateStoresSkusByBind(params.Ctx, skuBindInfos, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @Title 拷贝门店SKU信息
|
// @Title 拷贝门店SKU信息
|
||||||
// @Description 拷贝门店SKU信息(此函数当前只是本地数据操作,要同步到远端需要调用SyncStoresSkus)
|
// @Description 拷贝门店SKU信息(此函数当前只是本地数据操作,要同步到远端需要调用SyncStoresSkus)
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
|
|||||||
@@ -1330,6 +1330,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "UpdateStoresSkusByBind",
|
||||||
|
Router: `/UpdateStoresSkusByBind`,
|
||||||
|
AllowHTTPMethods: []string{"put"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "UpdateStoresSkusSale",
|
Method: "UpdateStoresSkusSale",
|
||||||
|
|||||||
Reference in New Issue
Block a user