调用账号服务报错as/sk验证错误,换回原先的方法

This commit is contained in:
徐俊杰 2023-03-16 13:18:57 +08:00
parent 06e63b96b3
commit 4e5d45685d
6 changed files with 112 additions and 101 deletions

View File

@ -151,24 +151,25 @@ type InviteService struct {
func CheckInvitedCodes(invitedCode string) (uint, error) {
// 变更为通过账号服务验证邀请码
// var user model.User
// //找到用户
// if err := db.DB.Where("invited_code =?", invitedCode).Find(&user).Error; err != nil {
// return 0, err
// }
// if user.ID == 0 {
// return 0, errors.New("邀请码无效")
// }
// return uint(user.ID), nil
if res, err := service.AccountProvider.ListByIDs(context.Background(), &account.ListByIDsRequest{
Page: 1,
PageSize: 1,
InvitationCode: []string{invitedCode},
}); err != nil && res != nil && len(res.Data) > 0 {
return uint(res.Data[0].ID), nil
var user model.User
//找到用户
if err := db.DB.Where("invited_code =?", invitedCode).Find(&user).Error; err != nil {
return 0, err
}
if user.ID == 0 {
return 0, errors.New("邀请码无效")
}
return uint(user.ID), nil
// todo 无法通过账号服务获取邀请码信息
// if res, err := service.AccountProvider.ListByIDs(context.Background(), &account.ListByIDsRequest{
// Page: 1,
// PageSize: 1,
// InvitationCode: []string{invitedCode},
// }); err != nil && res != nil && len(res.Data) > 0 {
// return uint(res.Data[0].ID), nil
// }
// return 0, errors.New("邀请码无效")
}
func GetUser(req *artistInfoUser.GetUserRequest) (rep *artistInfoUser.GetUserRespond, err error) {
rep = &artistInfoUser.GetUserRespond{}
@ -438,7 +439,7 @@ func FindUser(req *artistInfoUser.FindUserRequest) (rep *artistInfoUser.UserInfo
fmt.Println("FindUser 11111111111")
rep = &artistInfoUser.UserInfo{}
var data = model.User{}
var tx = db.DB.Model(model.User{}).Preload("RealNameInfo") //.Preload("InvitedBy.UserInfo.RealNameInfo")
var tx = db.DB.Model(model.User{}).Preload("RealNameInfo").Preload("InvitedBy.UserInfo.RealNameInfo")
if req.MgmtAccId != 0 {
tx = tx.Where("mgmt_acc_id = ?", req.MgmtAccId)
}
@ -459,32 +460,36 @@ func FindUser(req *artistInfoUser.FindUserRequest) (rep *artistInfoUser.UserInfo
data.RealNameInfo = &model.RealName{}
}
// 邀请人的查询变更为通过账号服务查询
// if data.InvitedBy == nil {
// data.InvitedBy = &model.Invite{}
// }
// var invitedName string
// if data.InvitedBy != nil && data.InvitedBy.UserInfo != nil && data.InvitedBy.UserInfo.RealNameInfo != nil {
// invitedName = data.InvitedBy.UserInfo.RealNameInfo.Name
// }
//查询邀请人
var inviterCode = model.Invite{}
var inviterAccount = &account.ListResponse{Data: []*account.AccountInfo{}}
if data.InvitedBy == nil {
data.InvitedBy = &model.Invite{}
}
var inviterName string
db.DB.Model(model.Invite{}).Where("invited_code = ?", data.InviteCode).First(&inviterCode)
if inviterCode.InviteCode != "" {
inviterAccount, err = service.AccountProvider.ListByIDs(context.Background(), &account.ListByIDsRequest{
Page: 1,
PageSize: 1,
InvitationCode: []string{inviterCode.InviteCode},
})
if err != nil {
fmt.Println("AccountProvider.ListByID error", err.Error())
return nil, err
}
if len(inviterAccount.Data) > 0 {
inviterName = inviterAccount.Data[0].RealName
var inviterCode string
if data.InvitedBy != nil {
inviterCode = data.InvitedBy.InviteCode
}
if data.InvitedBy != nil && data.InvitedBy.UserInfo != nil && data.InvitedBy.UserInfo.RealNameInfo != nil {
inviterName = data.InvitedBy.UserInfo.RealNameInfo.Name
}
//查询邀请人 无法通过账号服务进行查询,密码验证错误
// var inviterCode = model.Invite{}
// var inviterAccount = &account.ListResponse{Data: []*account.AccountInfo{}}
// var inviterName string
// db.DB.Model(model.Invite{}).Where("invited_code = ?", data.InviteCode).First(&inviterCode)
// if inviterCode.InviteCode != "" {
// inviterAccount, err = service.AccountProvider.ListByIDs(context.Background(), &account.ListByIDsRequest{
// Page: 1,
// PageSize: 1,
// InvitationCode: []string{inviterCode.InviteCode},
// })
// if err != nil {
// fmt.Println("AccountProvider.ListByID error", err.Error())
// return nil, err
// }
// if len(inviterAccount.Data) > 0 {
// inviterName = inviterAccount.Data[0].RealName
// }
// }
service.AccountProvider.Info(context.Background(), &account.InfoRequest{})
rep = &artistInfoUser.UserInfo{
Id: data.ID,
@ -495,7 +500,7 @@ func FindUser(req *artistInfoUser.FindUserRequest) (rep *artistInfoUser.UserInfo
MgmtArtistId: data.MgmtArtistId,
MgmtArtistUid: data.MgmtArtistUid,
TelNum: data.TelNum,
InviterCode: inviterCode.InviteCode, //邀请人的邀请码,不是用户个人邀请码
InviterCode: inviterCode, //邀请人的邀请码,不是用户个人邀请码
InviterName: inviterName, //邀请人的姓名
IsRealName: data.IsRealName,
RealNameId: data.RealNameId,
@ -586,10 +591,13 @@ func FindUserList(req *artistInfoUser.FindUsersRequest) (rep []*artistInfoUser.U
// invitedName = "无"
// }
var inviterName, inviterCode string
// 查询邀请人信息
inviterInfo := GetInviterInfo(v.InviteCode)
// 查询邀请人信息,调用账号服务接口报错 as/sk 错误,换原先的方法
// inviterInfo := GetInviterInfo(v.InviteCode)
// inviterName = inviterInfo.RealName
if v.RealNameInfo != nil {
inviterName = v.RealNameInfo.Name
}
inviterCode = v.InviteCode
inviterName = inviterInfo.RealName
rep = append(rep, &artistInfoUser.UserInfo{
Id: v.ID,
DeletedAt: int64(v.DeletedAt),
@ -894,47 +902,48 @@ func GetInviterInfo(inviterCode string) (result account.AccountInfo) {
fmt.Println("\n GetInviterInfo 查询邀请人信息出错", err.Error())
return
}
// todo 接口调用报错 as/ak错误
//查询邀请人信息
res, err := service.AccountProvider.ListByIDs(context.Background(), &account.ListByIDsRequest{
Page: 1,
PageSize: 1,
InvitationCode: []string{inviteRelation.InviteCode},
})
if err != nil {
fmt.Println("\n GetInviterInfo 查询邀请人信息出错 service.AccountProvider.ListByIDs Error", err.Error())
return
}
if res != nil && len(res.Data) > 0 {
result = account.AccountInfo{
ID: res.Data[0].ID,
Account: res.Data[0].Account,
NickName: res.Data[0].NickName,
Type: res.Data[0].Type,
TelNum: res.Data[0].TelNum,
Status: res.Data[0].Status,
Avatar: res.Data[0].Avatar,
CreateAt: res.Data[0].CreateAt,
RealNameID: res.Data[0].RealNameID,
RealName: res.Data[0].RealName,
IDNum: res.Data[0].IDNum,
MnemonicWords: res.Data[0].MnemonicWords,
IsNeedChange: res.Data[0].IsNeedChange,
EnterDate: res.Data[0].EnterDate,
WorkYear: res.Data[0].WorkYear,
Domain: res.Data[0].Domain,
Extend: res.Data[0].Extend,
JobNum: res.Data[0].JobNum,
BirthDate: res.Data[0].BirthDate,
Age: res.Data[0].Age,
Sex: res.Data[0].Sex,
Title: res.Data[0].Title,
Departments: res.Data[0].Departments,
Ip: res.Data[0].Ip,
LoginDate: res.Data[0].LoginDate,
InvitationCode: res.Data[0].InvitationCode,
}
return
}
// res, err := service.AccountProvider.ListByIDs(context.Background(), &account.ListByIDsRequest{
// Page: 1,
// PageSize: 1,
// InvitationCode: []string{inviteRelation.InviteCode},
// })
// if err != nil {
// fmt.Println("\n GetInviterInfo 查询邀请人信息出错 service.AccountProvider.ListByIDs Error", err.Error())
// return
// }
// if res != nil && len(res.Data) > 0 {
// result = account.AccountInfo{
// ID: res.Data[0].ID,
// Account: res.Data[0].Account,
// NickName: res.Data[0].NickName,
// Type: res.Data[0].Type,
// TelNum: res.Data[0].TelNum,
// Status: res.Data[0].Status,
// Avatar: res.Data[0].Avatar,
// CreateAt: res.Data[0].CreateAt,
// RealNameID: res.Data[0].RealNameID,
// RealName: res.Data[0].RealName,
// IDNum: res.Data[0].IDNum,
// MnemonicWords: res.Data[0].MnemonicWords,
// IsNeedChange: res.Data[0].IsNeedChange,
// EnterDate: res.Data[0].EnterDate,
// WorkYear: res.Data[0].WorkYear,
// Domain: res.Data[0].Domain,
// Extend: res.Data[0].Extend,
// JobNum: res.Data[0].JobNum,
// BirthDate: res.Data[0].BirthDate,
// Age: res.Data[0].Age,
// Sex: res.Data[0].Sex,
// Title: res.Data[0].Title,
// Departments: res.Data[0].Departments,
// Ip: res.Data[0].Ip,
// LoginDate: res.Data[0].LoginDate,
// InvitationCode: res.Data[0].InvitationCode,
// }
// return
// }
return
}

View File

@ -9,6 +9,7 @@ package dao
import (
"errors"
"fmt"
"github.com/fonchain/fonchain-artistinfo/cmd/model"
"github.com/fonchain/fonchain-artistinfo/pb/artistinfoArtshow"
db "github.com/fonchain/fonchain-artistinfo/pkg/db"

View File

@ -9,6 +9,7 @@ package dao
import (
"errors"
"fmt"
"github.com/fonchain/fonchain-artistinfo/cmd/model"
"github.com/fonchain/fonchain-artistinfo/pb/artistinfoArtshow"
db "github.com/fonchain/fonchain-artistinfo/pkg/db"

View File

@ -3,8 +3,8 @@ package model
// User 用户模型
type Invite struct {
Model
// UserId int32 `gorm:"column:user_id;comment:邀请人账号id"`
// UserInfo *User `gorm:"foreignKey:id;reference:UserId"`
UserId int32 `gorm:"column:user_id;comment:邀请人账号id"`
UserInfo *User `gorm:"foreignKey:id;reference:UserId"`
InvitedId int32 `gorm:"column:invited_id;default:0;comment:受邀请画家宝用户id"`
InviteCode string `gorm:"column:invite_code;type:varchar(191);comment:邀请人的邀请码"`
InvitedCode string `gorm:"column:invited_code;type:varchar(191);comment:受邀请人的邀请码"`

View File

@ -8,7 +8,7 @@ type User struct {
MgmtArtistUid string `gorm:"column:mgmt_artist_uid;type:varchar(256);comment:艺术家uid"`
TelNum string `gorm:"column:tel_num;type:varchar(20);not null;电话号码"`
InviteCode string `gorm:"column:invited_code;type:varchar(16);default:'';comment:个人邀请码"`
// InvitedBy *Invite `gorm:"foreignKey:InvitedId"` //邀请者的相关信息,弃用,因为此处不存储经纪人数据
InvitedBy *Invite `gorm:"foreignKey:InvitedId"` //邀请者的相关信息
Account string `gorm:"column:account;varchar(191);comment:账号"`
CertificateNum string `gorm:"column:certificate_num;type:varchar(16);comment:中美协会证书编号"`
CertificateImg string `gorm:"column:certificate_img;type:varchar(512);comment:中美协会证书url"`

View File

@ -3,7 +3,7 @@ package model
// User 用户模型
type UserInvited struct {
Model
// UserId int32 `gorm:"column:user_id;type:int;not null;comment:邀请人id"`
UserId int32 `gorm:"column:user_id;type:int;not null;comment:邀请人id"`
InviteCode string `gorm:"column:invite_code;comment:邀请人的邀请码"`
InvitedCode string `gorm:"column:invited_code;comment:受邀请人的邀请码"`
InvitedUserId int32 `gorm:"column:invited_user_id;type:int;not null;comment:受邀请人画家宝用户id"`