- auth1与auth2以为是兼容
This commit is contained in:
@@ -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)
|
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
|
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
|
return loginInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"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/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// todo 是否需要将Store.MarketManPhone与OperatorPhone成角色?
|
// todo 是否需要将Store.MarketManPhone与OperatorPhone成角色?
|
||||||
|
|
||||||
func TransferLegacyWeixins() (err error) {
|
func TransferLegacyWeixins(mobile string) (err error) {
|
||||||
const remark4Transfer = "transfer"
|
if !globals.EnableWXAuth2 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
remark4Transfer := "transfer"
|
||||||
// DELETE t1
|
// DELETE t1
|
||||||
// FROM auth_bind t1
|
// FROM auth_bind t1
|
||||||
// WHERE t1.remark = 'transfer';
|
// WHERE t1.remark = 'transfer';
|
||||||
@@ -31,11 +35,19 @@ func TransferLegacyWeixins() (err error) {
|
|||||||
LEFT JOIN user t2 ON t2.mobile = t1.tel
|
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 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'
|
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)
|
WHERE`
|
||||||
ORDER BY t1.parentid;`
|
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
|
var weixinList []*legacymodel.WeiXins
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
err = dao.GetRows(db, &weixinList, sql)
|
err = dao.GetRows(db, &weixinList, sql, sqlParams...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -96,8 +108,14 @@ func TransferLegacyWeixins() (err error) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if v.JxStoreID > 0 && user.Type&model.UserTypeOperator == 0 { // 运营就不加到门店老板组里了
|
if v.JxStoreID > 0 { // 运营就不加到门店老板组里了
|
||||||
api2.RoleMan.AddRole4User(user.GetID(), autils.NewRole(authz.StoreRoleBoss, v.JxStoreID))
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestTransferLegacyWeixins(t *testing.T) {
|
func TestTransferLegacyWeixins(t *testing.T) {
|
||||||
err := TransferLegacyWeixins()
|
err := TransferLegacyWeixins("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
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 keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||||
if !globals.EnableWXAuth2 && jxutils.IsLegalMobileNumber(keywordInt64) {
|
if !globals.DisableWXAuth1 && jxutils.IsLegalMobileNumber(keywordInt64) {
|
||||||
sql += `
|
sql += `
|
||||||
LEFT JOIN weixins wx1 ON t1.id = wx1.jxstoreid AND wx1.parentid = -1 AND wx1.tel = ?
|
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
|
LEFT JOIN weixins wx2 ON t1.id = wx2.jxstoreid AND wx2.parentid = -1
|
||||||
|
|||||||
@@ -82,7 +82,10 @@ func UnbindMobile(ctx *jxcontext.Context, mobile string) (num int64, err error)
|
|||||||
}, map[string]interface{}{
|
}, map[string]interface{}{
|
||||||
"Tel": mobile,
|
"Tel": mobile,
|
||||||
})
|
})
|
||||||
jxutils.HandleUserWXRemark(db, mobile)
|
if err == nil {
|
||||||
|
jxutils.HandleUserWXRemark(db, mobile, false)
|
||||||
|
TransferLegacyWeixins(mobile)
|
||||||
|
}
|
||||||
return num, err
|
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
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,16 +153,24 @@ func AddMobile2Mobile(ctx *jxcontext.Context, parentMobile, mobile string) (num
|
|||||||
err = fmt.Errorf("%s本身是成员", parentMobile)
|
err = fmt.Errorf("%s本身是成员", parentMobile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jxutils.HandleUserWXRemark(db, mobile)
|
if err == nil {
|
||||||
|
jxutils.HandleUserWXRemark(db, mobile, false)
|
||||||
|
TransferLegacyWeixins(mobile)
|
||||||
|
}
|
||||||
return num, err
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChangeMobile(ctx *jxcontext.Context, curMobile, expectedMobile string) (num int64, err error) {
|
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,
|
"Tel": expectedMobile,
|
||||||
}, map[string]interface{}{
|
}, map[string]interface{}{
|
||||||
"Tel": curMobile,
|
"Tel": curMobile,
|
||||||
})
|
})
|
||||||
|
if err == nil {
|
||||||
|
TransferLegacyWeixins(curMobile)
|
||||||
|
TransferLegacyWeixins(expectedMobile)
|
||||||
|
}
|
||||||
|
return num, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *legacymodel.WeiXins, err error) {
|
func verifyMobileIsBlank(db *dao.DaoDB, mobile string) (user *legacymodel.WeiXins, err error) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
"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"
|
||||||
"git.rosy.net.cn/jx-callback/business/authz/autils"
|
"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/jsonerr"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"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"
|
||||||
@@ -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 = autils.ValidateRole(v.Name, v.StoreID); err == nil {
|
||||||
if err = api2.RoleMan.AddRole4User(userID, v); err != nil {
|
if err = api2.RoleMan.AddRole4User(userID, v); err != nil {
|
||||||
errList.AddErr(err)
|
errList.AddErr(err)
|
||||||
|
} else if v.StoreID > 0 {
|
||||||
|
jxutils.HandleUserWXRemark(dao.GetDB(), userID, true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errList.AddErr(err)
|
errList.AddErr(err)
|
||||||
@@ -242,6 +245,8 @@ func DeleteRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.Role
|
|||||||
for _, v := range rList {
|
for _, v := range rList {
|
||||||
if err = api2.RoleMan.DeleteRole4User(userID, v); err != nil {
|
if err = api2.RoleMan.DeleteRole4User(userID, v); err != nil {
|
||||||
errList.AddErr(err)
|
errList.AddErr(err)
|
||||||
|
} else if v.StoreID > 0 {
|
||||||
|
jxutils.HandleUserWXRemark(dao.GetDB(), userID, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errList.GetErrListAsOne()
|
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 {
|
if err = api2.RoleMan.AddRole4User(v, r); err != nil {
|
||||||
errList.AddErr(err)
|
errList.AddErr(err)
|
||||||
|
} else if r.StoreID > 0 {
|
||||||
|
jxutils.HandleUserWXRemark(dao.GetDB(), v, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errList.GetErrListAsOne()
|
return errList.GetErrListAsOne()
|
||||||
@@ -269,6 +276,8 @@ func DeleteUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []st
|
|||||||
for _, v := range userIDList {
|
for _, v := range userIDList {
|
||||||
if err = api2.RoleMan.DeleteRole4User(v, r); err != nil {
|
if err = api2.RoleMan.DeleteRole4User(v, r); err != nil {
|
||||||
errList.AddErr(err)
|
errList.AddErr(err)
|
||||||
|
} else if r.StoreID > 0 {
|
||||||
|
jxutils.HandleUserWXRemark(dao.GetDB(), v, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errList.GetErrListAsOne()
|
return errList.GetErrListAsOne()
|
||||||
|
|||||||
@@ -919,7 +919,7 @@ func UpdateAllWeiXinRemark(ctx *jxcontext.Context, isAsync, isContinueWhenError
|
|||||||
rootTask := tasksch.NewParallelTask("刷新微信备注", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
rootTask := tasksch.NewParallelTask("刷新微信备注", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
tel := batchItemList[0].(string)
|
tel := batchItemList[0].(string)
|
||||||
err = jxutils.HandleUserWXRemark(dao.GetDB(), tel)
|
err = jxutils.HandleUserWXRemark(dao.GetDB(), tel, false)
|
||||||
return nil, err
|
return nil, err
|
||||||
}, mobileList)
|
}, mobileList)
|
||||||
tasksch.ManageTask(rootTask).Run()
|
tasksch.ManageTask(rootTask).Run()
|
||||||
|
|||||||
@@ -423,7 +423,7 @@ func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
|||||||
return nil
|
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 {
|
if db == nil {
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
}
|
}
|
||||||
@@ -438,9 +438,16 @@ func HandleUserWXRemark(db *dao.DaoDB, mobile string) (err error) {
|
|||||||
storeID = wxinfo.JxStoreID
|
storeID = wxinfo.JxStoreID
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
userList, _, err2 := dao.GetUsers(db, model.UserTypeStoreBoss, "", nil, "", mobile, 0, -1)
|
userID := ""
|
||||||
if err = err2; len(userList) > 0 {
|
if mobileIsUerID {
|
||||||
userID := userList[0].GetID()
|
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, "")
|
authBind, err2 := dao.GetAuthBind(db, userID, weixin.AuthTypeMP, "")
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
openID = authBind.AuthID
|
openID = authBind.AuthID
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ var (
|
|||||||
|
|
||||||
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
|
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
if !globals.EnableWXAuth2 {
|
openIDMap := make(map[string]int)
|
||||||
|
if !globals.DisableWXAuth1 {
|
||||||
var openIDList []string
|
var openIDList []string
|
||||||
sql := `
|
sql := `
|
||||||
SELECT openid
|
SELECT openid
|
||||||
@@ -111,17 +112,20 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
|
|||||||
return retVal
|
return retVal
|
||||||
}
|
}
|
||||||
for _, v := range openIDList {
|
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 {
|
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewRole(authz.StoreRoleBoss, storeID)); err2 == nil {
|
||||||
for _, v := range userIDList {
|
for _, v := range userIDList {
|
||||||
if authInfo, err2 := dao.GetAuthBind(db, v, weixin.AuthTypeMP, ""); err2 == nil {
|
if authInfo, err2 := dao.GetAuthBind(db, v, weixin.AuthTypeMP, ""); err2 == nil {
|
||||||
retVal = append(retVal, authInfo.AuthID)
|
retVal = append(retVal, authInfo.AuthID)
|
||||||
|
openIDMap[authInfo.AuthID] = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
retVal = jxutils.StringMap2List(openIDMap)
|
||||||
if !globals.ReallyCallPlatformAPI {
|
if !globals.ReallyCallPlatformAPI {
|
||||||
// todo,调试,只发给我
|
// todo,调试,只发给我
|
||||||
globals.SugarLogger.Debugf("GetWeixinOpenIDsFromStoreID store:%d, openids:%v", storeID, retVal)
|
globals.SugarLogger.Debugf("GetWeixinOpenIDsFromStoreID store:%d, openids:%v", storeID, retVal)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func Init() {
|
|||||||
orm.RegisterModel(new(legacymodel.BlackClient))
|
orm.RegisterModel(new(legacymodel.BlackClient))
|
||||||
orm.RegisterModel(new(legacymodel.JxBadComments))
|
orm.RegisterModel(new(legacymodel.JxBadComments))
|
||||||
orm.RegisterModel(new(legacymodel.StoreBill))
|
orm.RegisterModel(new(legacymodel.StoreBill))
|
||||||
if !globals.EnableWXAuth2 {
|
if !globals.DisableWXAuth1 {
|
||||||
orm.RegisterModel(new(legacymodel.WeiXins))
|
orm.RegisterModel(new(legacymodel.WeiXins))
|
||||||
}
|
}
|
||||||
orm.RegisterModel(new(model.GoodsOrder))
|
orm.RegisterModel(new(model.GoodsOrder))
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ var (
|
|||||||
|
|
||||||
StoreName string
|
StoreName string
|
||||||
|
|
||||||
EnableWXAuth2 bool
|
EnableWXAuth2 bool
|
||||||
|
DisableWXAuth1 bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -88,6 +89,7 @@ func Init() {
|
|||||||
StoreName = beego.AppConfig.DefaultString("storeName", "京西菜市")
|
StoreName = beego.AppConfig.DefaultString("storeName", "京西菜市")
|
||||||
|
|
||||||
EnableWXAuth2 = beego.BConfig.RunMode == "beta"
|
EnableWXAuth2 = beego.BConfig.RunMode == "beta"
|
||||||
|
DisableWXAuth1 = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsCallbackAlwaysReturnSuccess() bool {
|
func IsCallbackAlwaysReturnSuccess() bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user