|
@@ -170,6 +170,62 @@ func GetWxUserItemByUnionId(unionId string, platform int) (userInfo UserInfo, er
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if userRecord == nil {
|
|
|
+ err = ERR_NO_USER_RECORD
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+
|
|
|
+ if wxUserErr == utils.ErrNoRow {
|
|
|
+
|
|
|
+ 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
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
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)
|
|
|
+
|
|
|
+ platformUser, platformErr := GetFirstWxUserItemByUnionId(unionId)
|
|
|
if platformErr == nil {
|
|
|
|
|
|
if platformUser.Mobile != "" || platformUser.Email != "" {
|