|
@@ -368,52 +368,30 @@ func BindWxGzh(code string) (isBind bool, err error) {
|
|
|
// @return isBind bool
|
|
|
// @return err error
|
|
|
func BindWxGzhByOpenId(openId string) (isBind bool, err error) {
|
|
|
- logger.Info("openId:" + openId)
|
|
|
wxUserDetail, err := GetWxUserDetail(openId)
|
|
|
if err != nil {
|
|
|
logger.Error("获取微信公众号用户详细信息失败" + err.Error())
|
|
|
- err = exception.New(exception.TemplateUserNotFound)
|
|
|
+ err = exception.New(exception.WeChatResponseError)
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
unionId := wxUserDetail.UnionID
|
|
|
followingGzh := int(wxUserDetail.Subscribe)
|
|
|
-
|
|
|
- logger.Info("unionId:" + unionId)
|
|
|
- var isAdd bool
|
|
|
user, err := userService.GetTemplateUserByGzhOpenId(openId)
|
|
|
- if err != nil {
|
|
|
- if err == gorm.ErrRecordNotFound {
|
|
|
- isAdd = true
|
|
|
- } else {
|
|
|
- err = exception.New(exception.TemplateUserNotFound)
|
|
|
- return
|
|
|
- }
|
|
|
+ if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
+ err = exception.New(exception.TemplateUserFoundFailed)
|
|
|
+ return
|
|
|
}
|
|
|
-
|
|
|
- logger.Info("IsAdd", isAdd)
|
|
|
-
|
|
|
- if isAdd {
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
user.GzhOpenId = openId
|
|
|
user.UnionId = unionId
|
|
|
user.FollowingGzh = followingGzh
|
|
|
- var isRegister bool
|
|
|
-
|
|
|
//判断unionid是否存在
|
|
|
wxUser, unionErr := userService.GetTemplateUserByUnionId(unionId)
|
|
|
-
|
|
|
- if unionErr != nil {
|
|
|
- if unionErr == gorm.ErrRecordNotFound { //注册用户
|
|
|
- isRegister = true
|
|
|
- } else {
|
|
|
- err = exception.New(exception.TemplateUserNotFound)
|
|
|
- return
|
|
|
- }
|
|
|
+ if unionErr != nil && !errors.Is(unionErr, gorm.ErrRecordNotFound) {
|
|
|
+ err = exception.New(exception.TemplateUserFoundFailed)
|
|
|
+ return
|
|
|
}
|
|
|
-
|
|
|
- logger.Info("isRegister", isRegister)
|
|
|
-
|
|
|
- if isRegister {
|
|
|
+ if errors.Is(unionErr, gorm.ErrRecordNotFound) {
|
|
|
err = userService.RegisterTemplateUser(&user)
|
|
|
if err != nil {
|
|
|
logger.Info("RegisterTemplateUser,Err" + err.Error())
|
|
@@ -432,7 +410,6 @@ func BindWxGzhByOpenId(openId string) (isBind bool, err error) {
|
|
|
logger.Info("BindUserGzhOpenId,Err" + err.Error())
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -463,12 +440,10 @@ func UnSubscribeWxGzhByOpenId(openId string) {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 解绑用户
|
|
|
err = userService.BindUserGzhOpenId(user.Id, openId, 0)
|
|
|
if err != nil {
|
|
|
logger.Info("UnBindWxGzhByOpenId,Err" + err.Error())
|
|
|
}
|
|
|
-
|
|
|
return
|
|
|
}
|