- auth1与auth2以为是兼容

This commit is contained in:
gazebo
2019-08-26 15:16:05 +08:00
parent fcc87c34af
commit 20c63e7f59
11 changed files with 79 additions and 25 deletions

View File

@@ -136,7 +136,7 @@ func BindMobile(token, mobileNum, code, nickname string) (err error) {
err = auth.ConvertErr2NoUser(dao.UpdateWeiXinUser(dao.GetDB(), mobileNum, nickname, wxUserinfo.UnionID, wxUserinfo.OpenID, ""), mobileNum)
}
}
jxutils.HandleUserWXRemark(nil, mobileNum)
jxutils.HandleUserWXRemark(nil, mobileNum, false)
return err
}
@@ -165,7 +165,7 @@ func BindMobile2(openid, secret, mobileNum, verifyCode, nickname string) (loginI
}
}
}
jxutils.HandleUserWXRemark(nil, mobileNum)
jxutils.HandleUserWXRemark(nil, mobileNum, false)
return loginInfo, err
}

View File

@@ -8,13 +8,17 @@ 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/model/legacymodel"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api2"
)
// todo 是否需要将Store.MarketManPhone与OperatorPhone成角色
func TransferLegacyWeixins() (err error) {
const remark4Transfer = "transfer"
func TransferLegacyWeixins(mobile string) (err error) {
if !globals.EnableWXAuth2 {
return nil
}
remark4Transfer := "transfer"
// DELETE t1
// FROM auth_bind t1
// WHERE t1.remark = 'transfer';
@@ -31,11 +35,19 @@ func TransferLegacyWeixins() (err error) {
LEFT JOIN user t2 ON t2.mobile = t1.tel
LEFT JOIN auth_bind t3 ON t3.auth_id = t1.openid AND t3.type = 'weixinsns'
LEFT JOIN auth_bind t4 ON t4.auth_id = t1.openid_mini AND t4.type = 'weixinmini'
WHERE t2.id IS NULL OR (t1.openid <> '' AND t3.id IS NULL) OR (t1.openid_mini <> '' AND t4.id IS NULL)
ORDER BY t1.parentid;`
WHERE`
sqlParams := []interface{}{}
if mobile != "" {
remark4Transfer = "transfer2"
sql += " t1.tel = ?"
sqlParams = append(sqlParams, mobile)
} else {
sql += " t2.id IS NULL OR (t1.openid <> '' AND t3.id IS NULL) OR (t1.openid_mini <> '' AND t4.id IS NULL)"
}
sql += `ORDER BY t1.parentid;`
var weixinList []*legacymodel.WeiXins
db := dao.GetDB()
err = dao.GetRows(db, &weixinList, sql)
err = dao.GetRows(db, &weixinList, sql, sqlParams...)
if err != nil {
return err
}
@@ -96,8 +108,14 @@ func TransferLegacyWeixins() (err error) {
},
})
}
if v.JxStoreID > 0 && user.Type&model.UserTypeOperator == 0 { // 运营就不加到门店老板组里了
api2.RoleMan.AddRole4User(user.GetID(), autils.NewRole(authz.StoreRoleBoss, v.JxStoreID))
if v.JxStoreID > 0 { // 运营就不加到门店老板组里了
if user.Type&model.UserTypeOperator == 0 {
api2.RoleMan.AddRole4User(user.GetID(), autils.NewRole(authz.StoreRoleBoss, v.JxStoreID))
}
} else {
if mobile != "" {
api2.RoleMan.DeleteRole4User(user.GetID(), autils.NewRole(authz.StoreRoleBoss, v.JxStoreID))
}
}
}
}

View File

@@ -16,7 +16,7 @@ import (
)
func TestTransferLegacyWeixins(t *testing.T) {
err := TransferLegacyWeixins()
err := TransferLegacyWeixins("")
if err != nil {
t.Fatal(err)
}

View File

@@ -259,7 +259,7 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
sqlWhereParams = append(sqlWhereParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
if !globals.EnableWXAuth2 && jxutils.IsLegalMobileNumber(keywordInt64) {
if !globals.DisableWXAuth1 && jxutils.IsLegalMobileNumber(keywordInt64) {
sql += `
LEFT JOIN weixins wx1 ON t1.id = wx1.jxstoreid AND wx1.parentid = -1 AND wx1.tel = ?
LEFT JOIN weixins wx2 ON t1.id = wx2.jxstoreid AND wx2.parentid = -1

View File

@@ -82,7 +82,10 @@ func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error)
}, map[string]interface{}{
"Tel": mobile,
})
jxutils.HandleUserWXRemark(db, mobile)
if err == nil {
jxutils.HandleUserWXRemark(db, mobile, false)
TransferLegacyWeixins(mobile)
}
return num, err
}
@@ -115,7 +118,10 @@ func BindMobile2Store(ctx *jxcontext.Context, mobile string, storeID int) (num i
}
}
}
jxutils.HandleUserWXRemark(db, mobile)
if err == nil {
jxutils.HandleUserWXRemark(db, mobile, false)
TransferLegacyWeixins(mobile)
}
return num, err
}
@@ -147,16 +153,24 @@ func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num
err = fmt.Errorf("%s本身是成员", parentMobile)
}
}
jxutils.HandleUserWXRemark(db, mobile)
if err == nil {
jxutils.HandleUserWXRemark(db, mobile, false)
TransferLegacyWeixins(mobile)
}
return num, err
}
func ChangeMobile(ctx *jxcontext.Context, curMobile, expectedMobile string) (num int64, err error) {
return dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
num, err = dao.UpdateEntityByKV(nil, &legacymodel.WeiXins{}, map[string]interface{}{
"Tel": expectedMobile,
}, map[string]interface{}{
"Tel": curMobile,
})
if err == nil {
TransferLegacyWeixins(curMobile)
TransferLegacyWeixins(expectedMobile)
}
return num, err
}
func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *legacymodel.WeiXins, err error) {

View File

@@ -12,6 +12,7 @@ import (
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
"git.rosy.net.cn/jx-callback/business/authz"
"git.rosy.net.cn/jx-callback/business/authz/autils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jsonerr"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
@@ -229,6 +230,8 @@ func AddRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.RoleInf
if err = autils.ValidateRole(v.Name, v.StoreID); err == nil {
if err = api2.RoleMan.AddRole4User(userID, v); err != nil {
errList.AddErr(err)
} else if v.StoreID > 0 {
jxutils.HandleUserWXRemark(dao.GetDB(), userID, true)
}
} else {
errList.AddErr(err)
@@ -242,6 +245,8 @@ func DeleteRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.Role
for _, v := range rList {
if err = api2.RoleMan.DeleteRole4User(userID, v); err != nil {
errList.AddErr(err)
} else if v.StoreID > 0 {
jxutils.HandleUserWXRemark(dao.GetDB(), userID, true)
}
}
return errList.GetErrListAsOne()
@@ -259,6 +264,8 @@ func AddUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []strin
}
if err = api2.RoleMan.AddRole4User(v, r); err != nil {
errList.AddErr(err)
} else if r.StoreID > 0 {
jxutils.HandleUserWXRemark(dao.GetDB(), v, true)
}
}
return errList.GetErrListAsOne()
@@ -269,6 +276,8 @@ func DeleteUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []st
for _, v := range userIDList {
if err = api2.RoleMan.DeleteRole4User(v, r); err != nil {
errList.AddErr(err)
} else if r.StoreID > 0 {
jxutils.HandleUserWXRemark(dao.GetDB(), v, true)
}
}
return errList.GetErrListAsOne()

View File

@@ -919,7 +919,7 @@ func UpdateAllWeiXinRemark(ctx *jxcontext.Context, isAsync, isContinueWhenError
rootTask := tasksch.NewParallelTask("刷新微信备注", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
tel := batchItemList[0].(string)
err = jxutils.HandleUserWXRemark(dao.GetDB(), tel)
err = jxutils.HandleUserWXRemark(dao.GetDB(), tel, false)
return nil, err
}, mobileList)
tasksch.ManageTask(rootTask).Run()

View File

@@ -423,7 +423,7 @@ func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
return nil
}
func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
func HandleUserWXRemark(db *dao.DaoDB, mobile string, mobileIsUerID bool) (err error) {
if db == nil {
db = dao.GetDB()
}
@@ -438,9 +438,16 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
storeID = wxinfo.JxStoreID
}
} else {
userList, _, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile, 0, -1)
if err = err2; len(userList) > 0 {
userID := userList[0].GetID()
userID := ""
if mobileIsUerID {
userID = mobile
} else {
userList, _, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile, 0, -1)
if err = err2; len(userList) > 0 {
userID = userList[0].GetID()
}
}
if userID != "" {
authBind, err2 := dao.GetAuthBind(db, userID, weixin.AuthTypeMP, "")
if err = err2; err == nil {
openID = authBind.AuthID

View File

@@ -87,7 +87,8 @@ var (
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
db := dao.GetDB()
if !globals.EnableWXAuth2 {
openIDMap := make(map[string]int)
if !globals.DisableWXAuth1 {
var openIDList []string
sql := `
SELECT openid
@@ -111,17 +112,20 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
return retVal
}
for _, v := range openIDList {
retVal = append(retVal, v)
openIDMap[v] = 1
}
} else {
}
if globals.EnableWXAuth2 {
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(authz.StoreRoleBoss, storeID)); err2 == nil {
for _, v := range userIDList {
if authInfo, err2 := dao.GetAuthBind(db, v, weixin.AuthTypeMP, ""); err2 == nil {
retVal = append(retVal, authInfo.AuthID)
openIDMap[authInfo.AuthID] = 1
}
}
}
}
retVal = jxutils.StringMap2List(openIDMap)
if !globals.ReallyCallPlatformAPI {
// todo调试只发给我
globals.SugarLogger.Debugf("GetWeixinOpenIDsFromStoreID store:%d, openids:%v", storeID, retVal)

View File

@@ -15,7 +15,7 @@ func Init() {
orm.RegisterModel(new(legacymodel.BlackClient))
orm.RegisterModel(new(legacymodel.JxBadComments))
orm.RegisterModel(new(legacymodel.StoreBill))
if !globals.EnableWXAuth2 {
if !globals.DisableWXAuth1 {
orm.RegisterModel(new(legacymodel.WeiXins))
}
orm.RegisterModel(new(model.GoodsOrder))

View File

@@ -44,7 +44,8 @@ var (
StoreName string
EnableWXAuth2 bool
EnableWXAuth2 bool
DisableWXAuth1 bool
)
func init() {
@@ -88,6 +89,7 @@ func Init() {
StoreName = beego.AppConfig.DefaultString("storeName", "京西菜市")
EnableWXAuth2 = beego.BConfig.RunMode == "beta"
DisableWXAuth1 = false
}
func IsCallbackAlwaysReturnSuccess() bool {