- auth1与auth2以为是兼容
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTransferLegacyWeixins(t *testing.T) {
|
||||
err := TransferLegacyWeixins()
|
||||
err := TransferLegacyWeixins("")
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user