128 lines
4.3 KiB
Go
128 lines
4.3 KiB
Go
package cms
|
||
|
||
import (
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||
"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 {
|
||
}
|
||
|
||
var (
|
||
FixedStoreManager *StoreManager
|
||
)
|
||
|
||
func init() {
|
||
FixedStoreManager = &StoreManager{}
|
||
partner.InitStoreManager(FixedStoreManager)
|
||
}
|
||
|
||
func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error) {
|
||
return err
|
||
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeStatus:%d", vendorStoreID, storeStatus)
|
||
db := dao.GetDB()
|
||
storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, vendorStoreID, vendorID)
|
||
if err == nil {
|
||
var storeKV, storeMapKV map[string]interface{}
|
||
if storeStatus == model.StoreStatusOpened {
|
||
if storeDetail.Status != model.StoreStatusOpened {
|
||
storeKV = map[string]interface{}{
|
||
"Status": model.StoreStatusOpened,
|
||
}
|
||
}
|
||
if storeDetail.VendorStatus != model.StoreStatusOpened {
|
||
storeMapKV = map[string]interface{}{
|
||
"Status": model.StoreStatusOpened,
|
||
}
|
||
}
|
||
} else {
|
||
if storeDetail.Status == model.StoreStatusOpened {
|
||
if storeDetail.VendorStatus != storeStatus {
|
||
storeMapKV = map[string]interface{}{
|
||
"Status": storeStatus,
|
||
}
|
||
}
|
||
} else if storeDetail.Status <= storeStatus {
|
||
if storeDetail.VendorStatus != model.StoreStatusOpened {
|
||
storeMapKV = map[string]interface{}{
|
||
"Status": model.StoreStatusOpened,
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if err == nil && (storeKV != nil || storeMapKV != nil) {
|
||
dao.Begin(db)
|
||
defer func() {
|
||
if r := recover(); r != nil || err != nil {
|
||
dao.Rollback(db)
|
||
if r != nil {
|
||
panic(r)
|
||
}
|
||
}
|
||
}()
|
||
if storeKV != nil {
|
||
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeKV:%s", vendorStoreID, utils.Format4Output(storeKV, true))
|
||
store := &model.Store{}
|
||
store.ID = storeDetail.Store.ID
|
||
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 {
|
||
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeMapKV:%s", 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 = utils.CallFuncLogError(func() error {
|
||
return dao.FormalizeStoreStatus(db, storeDetail.Store.ID, storeDetail.Status)
|
||
}, "OnStoreStatusChanged FormalizeStoreStatus venvendorStoreID:%s", vendorStoreID); err != nil {
|
||
return err
|
||
}
|
||
}
|
||
dao.Commit(db)
|
||
}
|
||
}
|
||
return err
|
||
}
|
||
|
||
func (s *StoreManager) OnCourierStoreStatusChanged(ctx *jxcontext.Context, vendorStoreID string, vendorID int, auditStatus int) (err error) {
|
||
if vendorStoreID != "" {
|
||
db := dao.GetDB()
|
||
_, err2 := dao.GetStoreDetail2(db, 0, vendorStoreID, vendorID)
|
||
if err = err2; err == nil {
|
||
status := model.StoreStatusOpened
|
||
if auditStatus != model.StoreAuditStatusOnline {
|
||
status = model.StoreStatusDisabled
|
||
}
|
||
_, err = dao.UpdateEntityLogically(db, &model.StoreCourierMap{}, map[string]interface{}{
|
||
model.FieldStatus: status,
|
||
"AuditStatus": auditStatus,
|
||
}, ctx.GetUserName(), map[string]interface{}{
|
||
model.FieldVendorStoreID: vendorStoreID,
|
||
model.FieldVendorID: vendorID,
|
||
})
|
||
} else if dao.IsNoRowsError(err) {
|
||
err = nil
|
||
}
|
||
}
|
||
globals.SugarLogger.Debugf("OnCourierStoreStatusChanged vendorStoreID:%s, auditStatus:%d, err:%v", vendorStoreID, auditStatus, err)
|
||
return err
|
||
}
|