|
@@ -203,6 +203,7 @@ type LoginResp struct {
|
|
|
}
|
|
|
|
|
|
func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err error) {
|
|
|
+ utils.FileLog.Info("BindMobile: openId: %s,mobile: %s,userId: %d,loginType:%d ", openId, mobile, userId, loginType)
|
|
|
mobile = strings.Trim(mobile, " ")
|
|
|
//loginType 登录方式:1:手机,2:邮箱
|
|
|
sql := ``
|
|
@@ -220,6 +221,7 @@ func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err
|
|
|
}
|
|
|
fmt.Println(user)
|
|
|
if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
|
|
|
+ utils.FileLog.Info("user is nil ")
|
|
|
fmt.Println("line 210")
|
|
|
msql := ``
|
|
|
if loginType == 1 {
|
|
@@ -232,21 +234,40 @@ func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err
|
|
|
_, err = o.Raw(msql, mobile, mobile, openId).Exec()
|
|
|
wxUserId = userId
|
|
|
} else {
|
|
|
+ utils.FileLog.Info("user is not nil ")
|
|
|
fmt.Println("line 223")
|
|
|
if openId != "" {
|
|
|
- wxUserId = user.UserId
|
|
|
- dsql := ` DELETE FROM wx_user WHERE open_id = ? `
|
|
|
- _, err = o.Raw(dsql, openId).Exec()
|
|
|
- if err != nil {
|
|
|
- return wxUserId, err
|
|
|
+ sql = `SELECT * FROM wx_user WHERE open_id = ? `
|
|
|
+ openIdUser := new(WxUser)
|
|
|
+ o := orm.NewOrm()
|
|
|
+ err = o.Raw(sql, openId).QueryRow(&openIdUser)
|
|
|
+ if openIdUser != nil {
|
|
|
+ if openIdUser.UserId != user.UserId {
|
|
|
+ utils.FileLog.Info("user id is not eq %d , %d",openIdUser.UserId,user.UserId)
|
|
|
+ wxUserId = user.UserId
|
|
|
+ dsql := ` DELETE FROM wx_user WHERE open_id = ? `
|
|
|
+ _, err = o.Raw(dsql, openId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return wxUserId, err
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
msql := ``
|
|
|
+ ssql := ``
|
|
|
if loginType == 1 {
|
|
|
msql = ` UPDATE wx_user SET open_id = ?,bind_account = ?,created_time=NOW(),register_time=NOW() WHERE mobile = ? `
|
|
|
+ ssql = `SELECT * FROM wx_user WHERE mobile = ? `
|
|
|
} else {
|
|
|
msql = ` UPDATE wx_user SET open_id = ?,bind_account = ?,created_time=NOW(),register_time=NOW() WHERE email = ? `
|
|
|
+ ssql = `SELECT * FROM wx_user WHERE email = ? `
|
|
|
}
|
|
|
_, err = o.Raw(msql, openId, mobile, mobile).Exec()
|
|
|
+
|
|
|
+ bindUser := new(WxUser)
|
|
|
+ err = o.Raw(ssql, mobile).QueryRow(&bindUser)
|
|
|
+ if bindUser != nil && bindUser.UserId > 0 {
|
|
|
+ wxUserId = bindUser.UserId
|
|
|
+ }
|
|
|
} else {
|
|
|
fmt.Println("line 239")
|
|
|
wxUserId = userId
|