This commit is contained in:
gazebo
2019-04-14 12:38:11 +08:00
parent caabbb4a66
commit 06c54755b0

View File

@@ -5,6 +5,7 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
)
type StoreManager struct {
@@ -20,6 +21,7 @@ func init() {
}
func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error) {
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeStatus:%d", vendorStoreID, storeStatus)
db := dao.GetDB()
storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, vendorStoreID, vendorID)
if err == nil {
@@ -36,11 +38,11 @@ func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int,
}
}
} else {
if storeDetail.Status == model.StoreStatusOpened && storeDetail.VendorStatus == model.StoreStatusOpened {
if storeDetail.Status == model.StoreStatusOpened {
storeMapKV = map[string]interface{}{
"Status": storeStatus,
}
} else if storeDetail.Status == model.StoreStatusClosed && storeStatus == model.StoreStatusClosed {
} else if storeDetail.Status <= storeStatus {
storeMapKV = map[string]interface{}{
"Status": model.StoreStatusOpened,
}
@@ -57,24 +59,34 @@ func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int,
}
}()
if storeKV != nil {
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeKV:%d", vendorStoreID, utils.Format4Output(storeKV, true))
store := &model.Store{}
store.ID = storeDetail.Store.ID
if _, err = dao.UpdateEntityLogically(db, store, storeKV, model.AdminName, nil); err != nil {
if err = utils.CallFuncLogError(func() error {
_, err = dao.UpdateEntityLogically(db, store, storeKV, model.AdminName, nil)
return err
}, "OnStoreStatusChanged Update Store venvendorStoreID:%s", vendorStoreID); err != nil {
return err
}
}
if storeMapKV != nil {
if _, err = dao.UpdateEntityLogically(db, &model.StoreMap{}, storeMapKV, model.AdminName, map[string]interface{}{
model.FieldStoreID: storeDetail.Store.ID,
model.FieldVendorID: vendorID,
model.FieldDeletedAt: utils.DefaultTimeValue,
}); err != nil {
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeMapKV:%d", vendorStoreID, utils.Format4Output(storeMapKV, true))
if err = utils.CallFuncLogError(func() error {
_, err = dao.UpdateEntityLogically(db, &model.StoreMap{}, storeMapKV, model.AdminName, map[string]interface{}{
model.FieldStoreID: storeDetail.Store.ID,
model.FieldVendorID: vendorID,
model.FieldDeletedAt: utils.DefaultTimeValue,
})
return err
}, "OnStoreStatusChanged Update StoreMap venvendorStoreID:%s", vendorStoreID); err != nil {
return err
}
}
if storeStatus != model.StoreStatusOpened {
// 因为storeStatus != model.StoreStatusOpened不会修改京西门店的状态所以直接用storeDetail.Status是合适的
if err = dao.FormalizeStoreStatus(db, storeDetail.Store.ID, storeDetail.Status); err != nil {
if err = utils.CallFuncLogError(func() error {
return dao.FormalizeStoreStatus(db, storeDetail.Store.ID, storeDetail.Status)
}, "OnStoreStatusChanged FormalizeStoreStatus venvendorStoreID:%s", vendorStoreID); err != nil {
return err
}
}