From 8ab0443293c6f537c4e995db1d4fff2fcc630529 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 23 Jul 2019 17:13:30 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E6=96=B0=E5=A2=9E=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E9=97=A8=E5=BA=97=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=97=A8=E5=BA=97=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 4 ++++ business/jxstore/cms/user.go | 16 +++++++++++++++- business/jxutils/jxutils_cms.go | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 18afb4234..777780975 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -615,6 +615,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa if err2 := updateCourierStores(ctx, storeID); err2 != nil && err == nil { err = err2 } + if valid["tel1"] != nil { + BindMobile2Store(ctx, utils.Interface2String(valid["tel1"]), storeID) + } } } else { dao.Commit(db) @@ -695,6 +698,7 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i store.ID = existingID if err = dao.CreateEntity(nil, store); err == nil { UpdateOrCreateCourierStores(ctx, store.ID, false, false, false) + BindMobile2Store(ctx, storeExt.Tel1, storeExt.ID) return store.ID, err } return 0, err diff --git a/business/jxstore/cms/user.go b/business/jxstore/cms/user.go index 15c993990..0ed83f02a 100644 --- a/business/jxstore/cms/user.go +++ b/business/jxstore/cms/user.go @@ -83,10 +83,21 @@ func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num i if err = err2; err == nil || err == orm.ErrNoRows { user.JxStoreID = storeID if err == nil { - // todo transaction + dao.Begin(db) + defer func() { + if r := recover(); r != nil { + dao.Rollback(db) + panic(r) + } + }() if num, err = dao.UpdateEntity(db, user, "JxStoreID"); err == nil { err = dao.SetWeiXinsEmpty2Null(db, user) } + if err != nil { + dao.Rollback(db) + } else { + dao.Commit(db) + } } else { dao.WrapAddIDCULEntity(user, ctx.GetUserName()) user.ParentID = -1 @@ -140,6 +151,9 @@ func ChangeMobile(ctx *jxcontext.Context, curMobile, expectedMobile string) (num } func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *legacymodel.WeiXins, err error) { + if !jxutils.IsStringLikeMobile(mobile) { + return nil, fmt.Errorf("%s看起来不像是一个手机号", mobile) + } user = &legacymodel.WeiXins{ Tel: mobile, } diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 285a0bfa2..28c83832e 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -21,6 +21,7 @@ import ( var ( storeNamePat = regexp.MustCompile(`([^(\[(【)\])】\-\s]*)[(\[(【\-\s]+([^(\[(【)\])】\-]*)[)\])】]*`) + mobilePat = regexp.MustCompile(`^1\d{10}$`) ) // 合并得到最终的门店状态 @@ -344,6 +345,10 @@ func FormalizeMobile(mobile string) string { return strings.Replace(strings.Replace(mobile, "-", ",", -1), "_", ",", -1) } +func IsStringLikeMobile(mobile string) bool { + return mobilePat.FindStringIndex(mobile) != nil +} + func IsLegalStoreID(id int) bool { return id >= 100000 && id < 200000 }