checkStoreHaveLinkedStore
This commit is contained in:
@@ -777,14 +777,20 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
|||||||
handler.UnregisterPrinter(ctx, store.PrinterSN, store.PrinterKey)
|
handler.UnregisterPrinter(ctx, store.PrinterSN, store.PrinterKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if linkStoreID, ok := valid["linkStoreID"].(int); ok {
|
if valid["linkStoreID"] != nil {
|
||||||
|
linkStoreID := int(utils.Interface2Int64WithDefault(valid["linkStoreID"], 0))
|
||||||
linkStoreID, err = getRealLinkStoreID(linkStoreID)
|
linkStoreID, err = getRealLinkStoreID(linkStoreID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
if err = checkStoreHaveLinkedStore(storeID); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
valid["linkStoreID"] = linkStoreID
|
valid["linkStoreID"] = linkStoreID
|
||||||
|
// globals.SugarLogger.Debug(linkStoreID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||||
for _, v := range []string{
|
for _, v := range []string{
|
||||||
"lng",
|
"lng",
|
||||||
"lat",
|
"lat",
|
||||||
@@ -1004,6 +1010,22 @@ func EnableHaveRestStores(ctx *jxcontext.Context, isAsync, isContinueWhenError b
|
|||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkStoreHaveLinkedStore(storeID int) (err error) {
|
||||||
|
if storeID != 0 {
|
||||||
|
storeList, err := dao.GetStoreLinkStores(dao.GetDB(), storeID)
|
||||||
|
if err == nil {
|
||||||
|
if len(storeList) > 0 {
|
||||||
|
var storeInfo []string
|
||||||
|
for _, v := range storeList {
|
||||||
|
storeInfo = append(storeInfo, utils.Int2Str(v.ID))
|
||||||
|
}
|
||||||
|
err = fmt.Errorf("门店%d已经被其它门店(%s)关联,不能再关联至其它门店", storeID, strings.Join(storeInfo, ","))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (id int, err error) {
|
func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (id int, err error) {
|
||||||
globals.SugarLogger.Debugf("CreateStore storeExt:%s", utils.Format4Output(storeExt, false))
|
globals.SugarLogger.Debugf("CreateStore storeExt:%s", utils.Format4Output(storeExt, false))
|
||||||
if err = checkBankBranch(storeExt.PayeeBankBranchName); err != nil {
|
if err = checkBankBranch(storeExt.PayeeBankBranchName); err != nil {
|
||||||
@@ -1023,6 +1045,9 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
if err = checkStoreHaveLinkedStore(storeExt.ID); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
storeExt.LinkStoreID = realLinkStoreID
|
storeExt.LinkStoreID = realLinkStoreID
|
||||||
|
|
||||||
existingID := store.ID
|
existingID := store.ID
|
||||||
|
|||||||
@@ -682,3 +682,17 @@ func GetOrderNotifyPhones(db *DaoDB, storeID int) (phoneList []string) {
|
|||||||
}
|
}
|
||||||
return phoneList
|
return phoneList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetStoreLinkStores(db *DaoDB, storeID int) (storeList []*model.Store, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT t1.*
|
||||||
|
FROM store t1
|
||||||
|
WHERE t1.link_store_id = ? AND t1.deleted_at = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
storeID,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
}
|
||||||
|
err = GetRows(db, &storeList, sql, sqlParams...)
|
||||||
|
return storeList, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user