- mark store sku bind as modified when change storevendor price percentage

This commit is contained in:
gazebo
2018-11-19 20:49:18 +08:00
parent aa75705d95
commit bc9f801d2d
4 changed files with 44 additions and 25 deletions

View File

@@ -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)
}