|
@@ -203,7 +203,7 @@ type LoginResp struct {
|
|
|
}
|
|
|
|
|
|
func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err error) {
|
|
|
- mobile=strings.Trim(mobile," ")
|
|
|
+ mobile = strings.Trim(mobile, " ")
|
|
|
//loginType 登录方式:1:手机,2:邮箱
|
|
|
sql := ``
|
|
|
if loginType == 1 {
|
|
@@ -233,7 +233,7 @@ func BindMobile(openId, mobile string, userId, loginType int) (wxUserId int, err
|
|
|
wxUserId = userId
|
|
|
} else {
|
|
|
fmt.Println("line 223")
|
|
|
- if user.OpenId == "" {
|
|
|
+ if openId != "" {
|
|
|
wxUserId = user.UserId
|
|
|
dsql := ` DELETE FROM wx_user WHERE open_id = ? `
|
|
|
_, err = o.Raw(dsql, openId).Exec()
|
|
@@ -306,98 +306,40 @@ func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int,
|
|
|
maxRegisterTime = userInfo.RegisterTime
|
|
|
utils.FileLog.Info("not after")
|
|
|
}
|
|
|
- var realName string
|
|
|
- if user.RealName != "" {
|
|
|
- realName = user.RealName
|
|
|
- } else {
|
|
|
- realName = userInfo.RealName
|
|
|
- }
|
|
|
utils.FileLog.Info("maxRegisterTime %s", maxRegisterTime.Format(utils.FormatDateTime))
|
|
|
wxUserId = user.UserId
|
|
|
- dsql := ` DELETE FROM wx_user WHERE user_id = ? `
|
|
|
- _, err = o.Raw(dsql, wxUserId).Exec()
|
|
|
+ dsql := ` DELETE FROM wx_user WHERE union_id = ? `
|
|
|
+ _, err = o.Raw(dsql, unionId).Exec()
|
|
|
if err != nil {
|
|
|
return wxUserId, err
|
|
|
}
|
|
|
- msql := ``
|
|
|
- if loginType == 1 {
|
|
|
- msql = ` UPDATE wx_user SET mobile=?,bind_account = ?,created_time=NOW(),register_time=?,real_name=? `
|
|
|
- if user.CompanyId > 0 {
|
|
|
- msql += ` ,company_id = ? `
|
|
|
- }
|
|
|
- msql += ` WHERE union_id = ? `
|
|
|
- } else {
|
|
|
- msql = ` UPDATE wx_user SET email=?,bind_account = ?,created_time=NOW(),register_time=?,real_name=? `
|
|
|
- if user.CompanyId > 0 {
|
|
|
- msql += ` ,company_id = ? `
|
|
|
- }
|
|
|
- msql += ` WHERE union_id = ? `
|
|
|
- }
|
|
|
- if user.CompanyId > 0 {
|
|
|
- _, err = o.Raw(msql, mobile, mobile, maxRegisterTime, realName, user.CompanyId, unionId).Exec()
|
|
|
- } else {
|
|
|
- _, err = o.Raw(msql, mobile, mobile, maxRegisterTime, realName, unionId).Exec()
|
|
|
- }
|
|
|
- wxUserId = userInfo.UserId
|
|
|
+ msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
|
|
|
+ _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
|
|
|
+ wxUserId = user.UserId
|
|
|
} else {
|
|
|
- sql = `SELECT * FROM wx_user WHERE union_id = ? `
|
|
|
+ sql = `SELECT * FROM wx_user WHERE user_id = ? `
|
|
|
userInfo := new(WxUser)
|
|
|
o := orm.NewOrm()
|
|
|
- err = o.Raw(sql, unionId).QueryRow(&userInfo)
|
|
|
+ err = o.Raw(sql, userId).QueryRow(&userInfo)
|
|
|
if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
return
|
|
|
}
|
|
|
- if userInfo.UserId != user.UserId {
|
|
|
- isDelete := 0
|
|
|
- if userInfo.CompanyId <= 1 {
|
|
|
- dsql := ` DELETE FROM wx_user WHERE user_id = ? `
|
|
|
- _, err = o.Raw(dsql, userInfo.UserId).Exec()
|
|
|
- if err != nil {
|
|
|
- return userInfo.UserId, err
|
|
|
- }
|
|
|
- isDelete = 1
|
|
|
- }
|
|
|
-
|
|
|
- if user.CompanyId <= 1 {
|
|
|
- dsql := ` DELETE FROM wx_user WHERE user_id = ? `
|
|
|
- _, err = o.Raw(dsql, user.UserId).Exec()
|
|
|
- if err != nil {
|
|
|
- return userInfo.UserId, err
|
|
|
- }
|
|
|
- isDelete = 2
|
|
|
- }
|
|
|
-
|
|
|
- if userInfo.CompanyId > 1 && user.CompanyId > 1 {
|
|
|
- dsql := ` DELETE FROM wx_user WHERE user_id = ? `
|
|
|
- _, err = o.Raw(dsql, user.UserId).Exec()
|
|
|
- if err != nil {
|
|
|
- return userInfo.UserId, err
|
|
|
- }
|
|
|
- isDelete = 2
|
|
|
- }
|
|
|
- if isDelete == 1 {
|
|
|
- msql := ` UPDATE wx_user SET union_id = ?,unionid=?,bind_account = ?,created_time=NOW(),register_time=NOW() `
|
|
|
- if loginType == 1 {
|
|
|
- msql += ` ,mobile = ? `
|
|
|
- } else {
|
|
|
- msql += ` ,email = ? `
|
|
|
- }
|
|
|
- msql += ` WHERE user_id = ? `
|
|
|
- _, err = o.Raw(msql, user.Unionid, user.Unionid, mobile, mobile, user.UserId).Exec()
|
|
|
- wxUserId = user.UserId
|
|
|
- } else {
|
|
|
- msql := ` UPDATE wx_user SET union_id = ?,unionid=?,bind_account = ?,created_time=NOW(),register_time=NOW() `
|
|
|
- if loginType == 1 {
|
|
|
- msql += ` ,mobile = ? `
|
|
|
- } else {
|
|
|
- msql += ` ,email = ? `
|
|
|
- }
|
|
|
- msql += ` WHERE user_id = ? `
|
|
|
- _, err = o.Raw(msql, unionId, unionId, mobile, mobile, userInfo.UserId).Exec()
|
|
|
- wxUserId = userInfo.UserId
|
|
|
- }
|
|
|
+ dsql := ` DELETE FROM wx_user WHERE user_id = ? `
|
|
|
+ _, err = o.Raw(dsql, userId).Exec()
|
|
|
+ if err != nil {
|
|
|
+ return user.UserId, err
|
|
|
+ }
|
|
|
+ if user.Mobile == "" && loginType == 1 {
|
|
|
+ msql := ` UPDATE wx_user SET mobile = ?,bind_account = ? WHERE user_id = ?`
|
|
|
+ _, err = o.Raw(msql, mobile, mobile, user.UserId).Exec()
|
|
|
+ wxUserId = user.UserId
|
|
|
+ }
|
|
|
+ if user.Email == "" && loginType == 2 {
|
|
|
+ msql := ` UPDATE wx_user SET email = ?,bind_account = ? WHERE user_id = ?`
|
|
|
+ _, err = o.Raw(msql, mobile, mobile, user.UserId).Exec()
|
|
|
+ wxUserId = user.UserId
|
|
|
}
|
|
|
- utils.FileLog.Info("用户存在,bind:%s,%d", unionId, wxUserId)
|
|
|
+ utils.FileLog.Info("用户存在,bind:%s,%d,%s", unionId, wxUserId)
|
|
|
wxUserId = userId
|
|
|
}
|
|
|
}
|