|
@@ -38,16 +38,6 @@ func GetWxUserItemByOpenId(openid string) (item *models.WxUserItem, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- //如果查研观向小程序登录过,那么买方研选小程序就做静默登录
|
|
|
- if userRecord.UserId <= 0 {
|
|
|
- userRecordCygx, userRecordErrCygx := models.GetUserRecordByUnionId(userRecord.UnionId, 4)
|
|
|
- //fmt.Println("userRecordErr", userRecordErr)
|
|
|
- if userRecordErrCygx != nil && userRecordErrCygx.Error() != utils.ErrNoRow() {
|
|
|
- err = userRecordErrCygx
|
|
|
- }
|
|
|
- userRecord = userRecordCygx
|
|
|
- }
|
|
|
-
|
|
|
//该openid没有绑定用户
|
|
|
if userRecord.UserId <= 0 {
|
|
|
err = ERR_USER_NOT_BIND
|
|
@@ -292,13 +282,29 @@ QUERY_WX_USER:
|
|
|
wxUser, wxUserErr := GetWxUserItemByOpenId(openId)
|
|
|
fmt.Println("wxUserErr", wxUserErr)
|
|
|
if wxUserErr == ERR_NO_USER_RECORD { //没有用户openid记录
|
|
|
- //先添加第三方信息(openid等信息)
|
|
|
- _, recordErr := AddUserRecord(openId, unionId, wxUserInfo.Nickname, "", wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0)
|
|
|
- //如果插入失败,那么直接将错误信息返回
|
|
|
- if recordErr != nil {
|
|
|
- err = recordErr
|
|
|
+ // 如果查研观向小程序已经绑定过相关信息了,那么拿过来复用
|
|
|
+ userRecordCygx, userRecordErrCygx := models.GetUserRecordByUnionId(unionId, 4)
|
|
|
+ if userRecordErrCygx != nil && userRecordErrCygx.Error() != utils.ErrNoRow() {
|
|
|
+ err = userRecordErrCygx
|
|
|
return
|
|
|
}
|
|
|
+ if userRecordCygx != nil {
|
|
|
+ _, recordErr := AddUserRecordByCygx(openId, unionId, wxUserInfo.Nickname, userRecordCygx.RealName, wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0, userRecordCygx.UserId)
|
|
|
+ //如果插入失败,那么直接将错误信息返回
|
|
|
+ if recordErr != nil {
|
|
|
+ err = recordErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ //先添加第三方信息(openid等信息)
|
|
|
+ _, recordErr := AddUserRecord(openId, unionId, wxUserInfo.Nickname, "", wxUserInfo.Province, wxUserInfo.City, wxUserInfo.Country, wxUserInfo.Headimgurl, wxUserInfo.SessionKey, utils.WxPlatform, wxUserInfo.Sex, 0)
|
|
|
+ //如果插入失败,那么直接将错误信息返回
|
|
|
+ if recordErr != nil {
|
|
|
+ err = recordErr
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
//插入成功后,需要重新查询该用户,并进入下面的逻辑
|
|
|
goto QUERY_WX_USER
|
|
|
} else if wxUserErr == ERR_USER_NOT_BIND {
|
|
@@ -374,7 +380,7 @@ QUERY_WX_USER:
|
|
|
loginLog.OpenId = openId
|
|
|
loginLog.UnionId = unionId
|
|
|
loginLog.CreateTime = time.Now()
|
|
|
- loginLog.Handle = "wechat_login_cygx"
|
|
|
+ loginLog.Handle = "wechat_login_mfyx"
|
|
|
loginLog.Remark = token
|
|
|
go models.AddWxUserLog(loginLog)
|
|
|
}
|
|
@@ -418,6 +424,40 @@ func AddUserRecord(openId, unionId, nickName, realName, province, city, country,
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// 添加第三方用户(微信)记录
|
|
|
+func AddUserRecordByCygx(openId, unionId, nickName, realName, province, city, country, headimgurl, sessionKey string, platform, sex, subscribe, userId int) (userRecord *models.UserRecord, err error) {
|
|
|
+ find, err := models.GetUserRecordByOpenId(openId)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if find != nil {
|
|
|
+ userRecord = find
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userRecord = &models.UserRecord{
|
|
|
+ OpenId: openId, //用户open_id
|
|
|
+ UnionId: unionId, //用户union_id
|
|
|
+ Subscribe: subscribe,
|
|
|
+ NickName: nickName, //用户昵称,最大长度:32
|
|
|
+ RealName: realName, //用户实际名称,最大长度:32
|
|
|
+ Sex: sex, //普通用户性别,1为男性,2为女性
|
|
|
+ Province: province, //普通用户个人资料填写的省份,最大长度:30
|
|
|
+ City: city, //普通用户个人资料填写的城市,最大长度:30
|
|
|
+ Country: country, //国家,如中国为CN,最大长度:30
|
|
|
+ Headimgurl: headimgurl, //用户第三方(微信)头像,最大长度:512
|
|
|
+ CreateTime: time.Now(), //创建时间,关系添加时间、用户授权时间
|
|
|
+ CreatePlatform: platform, //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
|
|
|
+ SessionKey: sessionKey, //微信小程序会话密钥,最大长度:255
|
|
|
+ UserId: userId, //微信小程序会话密钥,最大长度:255
|
|
|
+ }
|
|
|
+ recordId, err := models.AddUserRecord(userRecord)
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ userRecord.UserRecordId = int(recordId)
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// 每天新增,删除的白名单
|
|
|
func SendEmailUserWhiteListChange(cont context.Context) (err error) {
|
|
|
var msg string
|