95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
package cms
|
|
|
|
import (
|
|
"git.rosy.net.cn/jx-callback/business/auth2"
|
|
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
|
"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/api2"
|
|
)
|
|
|
|
func TransferLegacyWeixins() (err error) {
|
|
// DELETE t1
|
|
// FROM auth_bind t1
|
|
// WHERE t1.created_at > '2019-08-05';
|
|
|
|
// DELETE t1
|
|
// FROM user t1
|
|
// WHERE t1.created_at > '2019-08-05';
|
|
|
|
// DELETE t1
|
|
// FROM casbin_rule t1;
|
|
|
|
sql := `
|
|
SELECT *
|
|
FROM weixins
|
|
ORDER BY parentid`
|
|
var weixinList []*legacymodel.WeiXins
|
|
db := dao.GetDB()
|
|
err = dao.GetRows(db, &weixinList, sql)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
parentMap := make(map[int]*legacymodel.WeiXins)
|
|
for _, v := range weixinList {
|
|
if v.ParentID == -1 {
|
|
parentMap[v.ID] = v
|
|
} else {
|
|
if parentMap[v.ParentID] != nil {
|
|
v.JxStoreID = parentMap[v.ParentID].JxStoreID
|
|
}
|
|
}
|
|
if v.Tel != "" {
|
|
user := &model.User{
|
|
UserID2: v.Tel,
|
|
Name: v.NickName,
|
|
Mobile: v.Tel,
|
|
Type: model.UserTypeStoreBoss,
|
|
}
|
|
if user.Name == "" {
|
|
user.Name = user.Mobile
|
|
}
|
|
userList, err2 := dao.GetUsers(db, 0, "", "", v.Tel, "")
|
|
if err = err2; err != nil {
|
|
return err
|
|
}
|
|
// globals.SugarLogger.Debug(utils.Format4Output(user, false))
|
|
if len(userList) == 0 {
|
|
err = CreateUser(user)
|
|
} else {
|
|
user = userList[0]
|
|
}
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if v.OpenID != "" {
|
|
auth2.AddAuthBind(user, &auth2.AuthInfo{
|
|
AuthBindInfo: &auth2.AuthBindEx{
|
|
AuthBind: model.AuthBind{
|
|
Type: weixin.AuthTypeMP,
|
|
AuthID: v.OpenID,
|
|
AuthID2: v.OpenIDUnion,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
if v.OpenIDMini != "" {
|
|
auth2.AddAuthBind(user, &auth2.AuthInfo{
|
|
AuthBindInfo: &auth2.AuthBindEx{
|
|
AuthBind: model.AuthBind{
|
|
Type: weixin.AuthTypeMini,
|
|
AuthID: v.OpenIDMini,
|
|
AuthID2: v.OpenIDUnion,
|
|
},
|
|
},
|
|
})
|
|
}
|
|
if v.JxStoreID > 0 {
|
|
api2.RoleMan.AddStoreRole4User(user.GetID(), v.JxStoreID)
|
|
}
|
|
}
|
|
}
|
|
return err
|
|
}
|