|
@@ -170,6 +170,62 @@ func GetWxUserItemByUnionId(unionId string, platform int) (userInfo UserInfo, er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetFirstWxUserItemByUnionId 根据用户unionid获取最小平台的用户信息
|
|
|
+func GetFirstWxUserItemByUnionId(unionId string) (userInfo UserInfo, err error) {
|
|
|
+ // 获取用户信息
|
|
|
+ userRecord, userRecordErr := user_record.GetFirstByUnionID(unionId)
|
|
|
+ if userRecordErr != nil {
|
|
|
+ if userRecordErr == utils.ErrNoRow {
|
|
|
+ err = ERR_NO_USER_RECORD
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ err = userRecordErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 该union在系统中没有关联关系
|
|
|
+ if userRecord == nil {
|
|
|
+ err = ERR_NO_USER_RECORD
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 该openid没有绑定用户
|
|
|
+ if userRecord.UserID <= 0 {
|
|
|
+ err = ERR_USER_NOT_BIND
|
|
|
+ item := new(wx_user.WxUser)
|
|
|
+ //格式化返回用户数据
|
|
|
+ userInfo = formatWxUserAndUserRecord(item, userRecord)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, wxUserErr := wx_user.GetByUserId(userRecord.UserID)
|
|
|
+ if wxUserErr != nil {
|
|
|
+ err = wxUserErr
|
|
|
+
|
|
|
+ // 如果是找不到数据,那么可能是该用户被删除了,但是user_record没有删除对应的关系
|
|
|
+ if wxUserErr == utils.ErrNoRow {
|
|
|
+ // 用户被删除了,但是user_record没有删除对应的关系,那么去解除绑定
|
|
|
+ userUnbindErr := user_record.UnBindUserRecordByUnionId(unionId, int(userRecord.CreatePlatform))
|
|
|
+ if userUnbindErr != nil {
|
|
|
+ err = userUnbindErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 返回状态为用户未绑定
|
|
|
+ err = ERR_USER_NOT_BIND
|
|
|
+ item := new(wx_user.WxUser)
|
|
|
+ // 格式化返回用户数据
|
|
|
+ userInfo = formatWxUserAndUserRecord(item, userRecord)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 格式化返回用户数据
|
|
|
+ userInfo = formatWxUserAndUserRecord(item, userRecord)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// formatWxUserAndUserRecord 通过用户 关系表记录 和 用户记录 格式化返回 用户数据
|
|
|
func formatWxUserAndUserRecord(wxUser *wx_user.WxUser, userRecord *user_record.UserRecord) (userInfo UserInfo) {
|
|
|
wxUser.OpenID = userRecord.OpenID
|
|
@@ -228,8 +284,8 @@ QUERY_WX_USER:
|
|
|
//插入成功后,需要重新查询该用户,并进入下面的逻辑
|
|
|
goto QUERY_WX_USER
|
|
|
} else if wxUserErr == ERR_USER_NOT_BIND {
|
|
|
- // 未绑定则去查询是否为弘则研究公众号用户,有相应的手机号邮箱信息则自动绑定
|
|
|
- platformUser, platformErr := GetWxUserItemByUnionId(unionId, 1)
|
|
|
+ // 未绑定则去查询unionId是否已经绑定了用户(其他平台,不区分平台),有相应的手机号邮箱信息则自动绑定
|
|
|
+ platformUser, platformErr := GetFirstWxUserItemByUnionId(unionId)
|
|
|
if platformErr == nil {
|
|
|
// 当公众号用户存在时
|
|
|
if platformUser.Mobile != "" || platformUser.Email != "" {
|