- sync store after bind vendor store.
This commit is contained in:
@@ -3,6 +3,7 @@ package cms
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
@@ -50,3 +51,27 @@ func (v *VendorSync) SyncCategory(categoryID int, isForce bool, userName string)
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *VendorSync) SyncStore(db *dao.DaoDB, vendorID int, store *model.Store, isForce bool, userName string) (err error) {
|
||||||
|
var (
|
||||||
|
storeMaps []*model.StoreMap
|
||||||
|
)
|
||||||
|
if db == nil {
|
||||||
|
db = dao.GetDB()
|
||||||
|
}
|
||||||
|
err = dao.GetEntities(db, &storeMaps, utils.Params2Map(model.FieldStoreID, store.ID), true)
|
||||||
|
if err == nil {
|
||||||
|
// globals.SugarLogger.Debug(utils.Format4Output(store, false))
|
||||||
|
copiedStore := *store
|
||||||
|
for _, storeMap := range storeMaps {
|
||||||
|
if (vendorID == -1 || storeMap.VendorID == vendorID) && (isForce || storeMap.SyncStatus != 0) {
|
||||||
|
copiedStore.Status = mergeStoreStatus(store.Status, storeMap.Status)
|
||||||
|
if err = GetPurchaseHandler(storeMap.VendorID).UpdateStore(storeMap.VendorStoreID, &copiedStore, userName); err == nil {
|
||||||
|
storeMap.SyncStatus = 0
|
||||||
|
dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ func UpdateStore(storeID int, payload map[string]interface{}, userName string) (
|
|||||||
_, err2 := dao.UpdateEntityByKV(db, dummy, utils.Params2Map(model.FieldSyncStatus, model.SyncFlagModifiedMask), utils.Params2Map(model.FieldStoreID, store.ID))
|
_, err2 := dao.UpdateEntityByKV(db, dummy, utils.Params2Map(model.FieldSyncStatus, model.SyncFlagModifiedMask), utils.Params2Map(model.FieldStoreID, store.ID))
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
if err = dao.GetEntity(db, store); err == nil {
|
if err = dao.GetEntity(db, store); err == nil {
|
||||||
err = SyncStore2Vendor(db, -1, store, false, userName)
|
err = CurVendorSync.SyncStore(db, -1, store, false, userName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,30 +230,6 @@ func CreateStore(store *model.Store, userName string) (id int, err error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SyncStore2Vendor(db *dao.DaoDB, vendorID int, store *model.Store, isForce bool, userName string) (err error) {
|
|
||||||
var (
|
|
||||||
storeMaps []*model.StoreMap
|
|
||||||
)
|
|
||||||
if db == nil {
|
|
||||||
db = dao.GetDB()
|
|
||||||
}
|
|
||||||
err = dao.GetEntities(db, &storeMaps, utils.Params2Map(model.FieldStoreID, store.ID), true)
|
|
||||||
if err == nil {
|
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(store, false))
|
|
||||||
copiedStore := *store
|
|
||||||
for _, storeMap := range storeMaps {
|
|
||||||
if (vendorID == -1 || storeMap.VendorID == vendorID) && (isForce || storeMap.SyncStatus != 0) {
|
|
||||||
copiedStore.Status = mergeStoreStatus(store.Status, storeMap.Status)
|
|
||||||
if err = GetPurchaseHandler(storeMap.VendorID).UpdateStore(storeMap.VendorStoreID, &copiedStore, userName); err == nil {
|
|
||||||
storeMap.SyncStatus = 0
|
|
||||||
dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetStoreVendorMaps(db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*model.StoreMap, err error) {
|
func GetStoreVendorMaps(db *dao.DaoDB, storeID int, vendorID int) (storeMaps []*model.StoreMap, err error) {
|
||||||
cond := map[string]interface{}{
|
cond := map[string]interface{}{
|
||||||
model.FieldStoreID: storeID,
|
model.FieldStoreID: storeID,
|
||||||
@@ -269,9 +245,10 @@ func AddStoreVendorMap(db *dao.DaoDB, storeMap *model.StoreMap, userName string)
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
storeMap.DeliveryType = store.DeliveryType
|
storeMap.DeliveryType = store.DeliveryType
|
||||||
storeMap.Status = store.Status
|
storeMap.Status = store.Status
|
||||||
outStoreMap = storeMap
|
storeMap.SyncStatus = model.SyncFlagModifiedMask
|
||||||
if err = dao.CreateEntity(db, storeMap); err == nil {
|
if err = dao.CreateEntity(db, storeMap); err == nil {
|
||||||
|
outStoreMap = storeMap
|
||||||
|
err = CurVendorSync.SyncStore(db, storeMap.VendorID, store, true, userName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outStoreMap, err
|
return outStoreMap, err
|
||||||
@@ -304,7 +281,7 @@ func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[stri
|
|||||||
store := &model.Store{}
|
store := &model.Store{}
|
||||||
store.ID = storeID
|
store.ID = storeID
|
||||||
if err = dao.GetEntity(db, store); err == nil {
|
if err = dao.GetEntity(db, store); err == nil {
|
||||||
err = SyncStore2Vendor(db, vendorID, store, true, userName)
|
err = CurVendorSync.SyncStore(db, vendorID, store, true, userName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user