- 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) {
|
||||
storeHandler := CurVendorSync.GetStoreHandler(vendorID)
|
||||
if storeHandler == nil {
|
||||
return 0, ErrCanNotFindVendor
|
||||
}
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" {
|
||||
if handler := CurVendorSync.GetStoreHandler(vendorID); handler != nil {
|
||||
vendorStoreInfo, err2 := handler.ReadStore(vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
payload["deliveryType"] = vendorStoreInfo.DeliveryType
|
||||
}
|
||||
err = nil // todo 忽略读不到DeliveryType的错误
|
||||
} else {
|
||||
err = ErrCanNotFindVendor
|
||||
vendorStoreInfo, err2 := storeHandler.ReadStore(vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
payload["deliveryType"] = vendorStoreInfo.DeliveryType
|
||||
}
|
||||
err = nil // todo 忽略读不到DeliveryType的错误
|
||||
}
|
||||
if err == nil {
|
||||
dummyStoreMap := &model.StoreMap{}
|
||||
valid := dao.NormalMakeMapByStructObject(payload, dummyStoreMap, userName)
|
||||
storeMap := &model.StoreMap{
|
||||
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 {
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
dao.Rollback(db)
|
||||
}()
|
||||
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.FieldVendorID: vendorID,
|
||||
}, model.FieldSyncStatus)
|
||||
} 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.FieldVendorID: vendorID,
|
||||
})
|
||||
}
|
||||
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 {
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ func Struct2FlatMap(obj interface{}) map[string]interface{} {
|
||||
}
|
||||
|
||||
// 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)
|
||||
for _, v := range excludedFields {
|
||||
excludedMap[v] = 1
|
||||
@@ -310,7 +310,7 @@ func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, ex
|
||||
valid = make(map[string]interface{})
|
||||
invalid = make(map[string]interface{})
|
||||
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
|
||||
} else {
|
||||
invalid[k] = v
|
||||
|
||||
@@ -9,24 +9,23 @@ import (
|
||||
"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,是需要完全匹配的
|
||||
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{}) {
|
||||
retVal, _ = NormalFilterMapByStructObject(mapData, obj)
|
||||
// if len(retVal) > 0 {
|
||||
// WrapUpdateULEntity(retVal, userName)
|
||||
// }
|
||||
retVal, _ = IDCULDFilterMapByStructObject(mapData, obj, false)
|
||||
return retVal
|
||||
}
|
||||
|
||||
func StrictMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
||||
retVal, _ = IDCULDFilterMapByStructObject(mapData, obj, true)
|
||||
return retVal
|
||||
}
|
||||
|
||||
func NormalMakeMapByFieldList(mapData map[string]interface{}, fields []string, userName string) (retVal map[string]interface{}) {
|
||||
retVal, _ = jxutils.FilterMapByFieldList(mapData, fields)
|
||||
// if len(retVal) > 0 {
|
||||
// WrapUpdateULEntity(retVal, userName)
|
||||
// }
|
||||
return retVal
|
||||
}
|
||||
|
||||
|
||||
@@ -127,8 +127,9 @@ func (c *StoreController) GetStoreVendorMaps() {
|
||||
// @router /UpdateStoreVendorMap [put]
|
||||
func (c *StoreController) UpdateStoreVendorMap() {
|
||||
c.callUpdateStoreVendorMap(func(params *tStoreUpdateStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
||||
storeMap := make(map[string]interface{})
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &storeMap); err == nil {
|
||||
var storeMap map[string]interface{}
|
||||
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())
|
||||
}
|
||||
return retVal, "", err
|
||||
|
||||
Reference in New Issue
Block a user