- mark store sku bind as modified when change storevendor price percentage
This commit is contained in:
@@ -381,36 +381,55 @@ func DeleteStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
|||||||
}
|
}
|
||||||
|
|
||||||
func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||||
|
storeHandler := CurVendorSync.GetStoreHandler(vendorID)
|
||||||
|
if storeHandler == nil {
|
||||||
|
return 0, ErrCanNotFindVendor
|
||||||
|
}
|
||||||
if db == nil {
|
if db == nil {
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
}
|
}
|
||||||
if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" {
|
if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" {
|
||||||
if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil {
|
vendorStoreInfo, err2 := storeHandler.ReadStore(vendorStoreID)
|
||||||
vendorStoreInfo, err2 := handler.ReadStore(vendorStoreID)
|
if err = err2; err == nil {
|
||||||
if err = err2; err == nil {
|
payload["deliveryType"] = vendorStoreInfo.DeliveryType
|
||||||
payload["deliveryType"] = vendorStoreInfo.DeliveryType
|
|
||||||
}
|
|
||||||
err = nil // todo 忽略读不到DeliveryType的错误
|
|
||||||
} else {
|
|
||||||
err = ErrCanNotFindVendor
|
|
||||||
}
|
}
|
||||||
|
err = nil // todo 忽略读不到DeliveryType的错误
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dummyStoreMap := &model.StoreMap{}
|
storeMap := &model.StoreMap{
|
||||||
valid := dao.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
|
StoreID: storeID,
|
||||||
|
VendorID: vendorID,
|
||||||
|
}
|
||||||
|
storeMap.DeletedAt = utils.DefaultTimeValue
|
||||||
|
if err = dao.GetEntity(db, storeMap, model.FieldStoreID, model.FieldVendorID, model.FieldDeletedAt); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
valid := dao.StrictMakeMapByStructObject(payload, storeMap, userName)
|
||||||
|
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||||
if len(valid) > 0 {
|
if len(valid) > 0 {
|
||||||
|
dao.Begin(db)
|
||||||
|
defer func() {
|
||||||
|
dao.Rollback(db)
|
||||||
|
}()
|
||||||
if valid["status"] != nil { // 对于store vendor map,只有Status改变才需要同步到厂商
|
if valid["status"] != nil { // 对于store vendor map,只有Status改变才需要同步到厂商
|
||||||
num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, dummyStoreMap, valid, userName, map[string]interface{}{
|
num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeMap, valid, userName, map[string]interface{}{
|
||||||
model.FieldStoreID: storeID,
|
model.FieldStoreID: storeID,
|
||||||
model.FieldVendorID: vendorID,
|
model.FieldVendorID: vendorID,
|
||||||
}, model.FieldSyncStatus)
|
}, model.FieldSyncStatus)
|
||||||
} else {
|
} else {
|
||||||
num, err = dao.UpdateEntityLogically(db, dummyStoreMap, valid, userName, map[string]interface{}{
|
num, err = dao.UpdateEntityLogically(db, storeMap, valid, userName, map[string]interface{}{
|
||||||
model.FieldStoreID: storeID,
|
model.FieldStoreID: storeID,
|
||||||
model.FieldVendorID: vendorID,
|
model.FieldVendorID: vendorID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if err == nil && num > 0 {
|
if err == nil && num > 0 {
|
||||||
|
storeSkuBind := &model.StoreSkuBind{}
|
||||||
|
if num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeSkuBind, nil, userName, map[string]interface{}{
|
||||||
|
model.FieldStoreID: storeID,
|
||||||
|
}, storeHandler.GetFieldSyncStatusName()); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
dao.Commit(db)
|
||||||
if valid["status"] != nil {
|
if valid["status"] != nil {
|
||||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ func Struct2FlatMap(obj interface{}) map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以
|
// todo 这里看是否需要将key值转换成标准格式(即字母大写),因为beego orm不区分,不转换也可以
|
||||||
func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string) (valid map[string]interface{}, invalid map[string]interface{}) {
|
func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, excludedFields []string, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||||
excludedMap := make(map[string]int)
|
excludedMap := make(map[string]int)
|
||||||
for _, v := range excludedFields {
|
for _, v := range excludedFields {
|
||||||
excludedMap[v] = 1
|
excludedMap[v] = 1
|
||||||
@@ -310,7 +310,7 @@ func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, ex
|
|||||||
valid = make(map[string]interface{})
|
valid = make(map[string]interface{})
|
||||||
invalid = make(map[string]interface{})
|
invalid = make(map[string]interface{})
|
||||||
for k, v := range mapData {
|
for k, v := range mapData {
|
||||||
if m[k] != nil && excludedMap[k] == 0 && v != nil {
|
if m[k] != nil && excludedMap[k] == 0 && v != nil && (!isCheckValue || m[k] != v) {
|
||||||
valid[k] = v
|
valid[k] = v
|
||||||
} else {
|
} else {
|
||||||
invalid[k] = v
|
invalid[k] = v
|
||||||
|
|||||||
@@ -9,24 +9,23 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NormalFilterMapByStructObject(mapData map[string]interface{}, obj interface{}) (valid map[string]interface{}, invalid map[string]interface{}) {
|
func IDCULDFilterMapByStructObject(mapData map[string]interface{}, obj interface{}, isCheckValue bool) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||||
// 这里必须用首字母小写,因为是用于访问map,是用于访问map,是需要完全匹配的
|
// 这里必须用首字母小写,因为是用于访问map,是用于访问map,是需要完全匹配的
|
||||||
return jxutils.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"})
|
return jxutils.FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "updatedAt", "finishedAt", "deletedAt", "syncStatus", "lastOperator"}, isCheckValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NormalMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
func NormalMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
||||||
retVal, _ = NormalFilterMapByStructObject(mapData, obj)
|
retVal, _ = IDCULDFilterMapByStructObject(mapData, obj, false)
|
||||||
// if len(retVal) > 0 {
|
return retVal
|
||||||
// WrapUpdateULEntity(retVal, userName)
|
}
|
||||||
// }
|
|
||||||
|
func StrictMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
||||||
|
retVal, _ = IDCULDFilterMapByStructObject(mapData, obj, true)
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
func NormalMakeMapByFieldList(mapData map[string]interface{}, fields []string, userName string) (retVal map[string]interface{}) {
|
func NormalMakeMapByFieldList(mapData map[string]interface{}, fields []string, userName string) (retVal map[string]interface{}) {
|
||||||
retVal, _ = jxutils.FilterMapByFieldList(mapData, fields)
|
retVal, _ = jxutils.FilterMapByFieldList(mapData, fields)
|
||||||
// if len(retVal) > 0 {
|
|
||||||
// WrapUpdateULEntity(retVal, userName)
|
|
||||||
// }
|
|
||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -127,8 +127,9 @@ func (c *StoreController) GetStoreVendorMaps() {
|
|||||||
// @router /UpdateStoreVendorMap [put]
|
// @router /UpdateStoreVendorMap [put]
|
||||||
func (c *StoreController) UpdateStoreVendorMap() {
|
func (c *StoreController) UpdateStoreVendorMap() {
|
||||||
c.callUpdateStoreVendorMap(func(params *tStoreUpdateStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
c.callUpdateStoreVendorMap(func(params *tStoreUpdateStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
||||||
storeMap := make(map[string]interface{})
|
var storeMap map[string]interface{}
|
||||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &storeMap); err == nil {
|
var storeMapStruct model.StoreMap
|
||||||
|
if storeMap, err = utils.Unmarshal2Map([]byte(params.Payload), &storeMapStruct); err == nil {
|
||||||
retVal, err = cms.UpdateStoreVendorMap(params.Ctx, nil, params.StoreID, params.VendorID, storeMap, params.Ctx.GetUserName())
|
retVal, err = cms.UpdateStoreVendorMap(params.Ctx, nil, params.StoreID, params.VendorID, storeMap, params.Ctx.GetUserName())
|
||||||
}
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user