2023-01-18 09:03:15 +00:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-14 07:09:13 +00:00
|
|
|
"errors"
|
2023-01-18 09:03:15 +00:00
|
|
|
"fmt"
|
2023-03-14 07:09:13 +00:00
|
|
|
|
2023-02-15 14:35:28 +00:00
|
|
|
"github.com/fonchain/fonchain-artistinfo/cmd/model"
|
2023-02-25 00:44:50 +00:00
|
|
|
"github.com/fonchain/fonchain-artistinfo/pb/artistInfoUser"
|
2023-02-15 14:35:28 +00:00
|
|
|
db "github.com/fonchain/fonchain-artistinfo/pkg/db"
|
2023-02-20 04:51:50 +00:00
|
|
|
"gorm.io/gorm"
|
2023-03-30 06:30:25 +00:00
|
|
|
"gorm.io/gorm/clause"
|
2023-01-18 09:03:15 +00:00
|
|
|
|
2023-02-06 01:33:09 +00:00
|
|
|
"github.com/fonchain/fonchain-artistinfo/cmd/internal/logic"
|
2023-01-18 09:03:15 +00:00
|
|
|
)
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
var _ artistInfoUser.ArtistInfoUserServer = new(ArtistInfoUserProvider)
|
2023-02-17 03:33:56 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
type ArtistInfoUserProvider struct {
|
|
|
|
artistInfoUser.UnimplementedArtistInfoUserServer
|
|
|
|
artistInfoLogic *logic.ArtistInfoUser
|
2023-01-18 09:03:15 +00:00
|
|
|
}
|
|
|
|
|
2023-03-14 10:45:35 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetInviteStaticList(ctx context.Context, request *artistInfoUser.GetInviteStaticListRequest) (*artistInfoUser.GetInviteStaticListResponse, error) {
|
|
|
|
return a.artistInfoLogic.GetInviteStaticList(request)
|
|
|
|
}
|
2023-03-16 03:13:25 +00:00
|
|
|
|
2023-03-14 10:45:35 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetInviterUserList(ctx context.Context, request *artistInfoUser.GetInviterUserListRequest) (*artistInfoUser.GetInvitedUserListResponse, error) {
|
|
|
|
return a.artistInfoLogic.GetInviterUserList(request)
|
|
|
|
}
|
|
|
|
|
2023-03-07 00:48:58 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetInvitedUserList(ctx context.Context, request *artistInfoUser.GetInvitedUserListRequest) (*artistInfoUser.GetInvitedUserListResponse, error) {
|
|
|
|
return a.artistInfoLogic.GetInvitedUserList(request)
|
|
|
|
}
|
|
|
|
|
2023-02-27 07:51:04 +00:00
|
|
|
func (a *ArtistInfoUserProvider) FindUsersUserView(ctx context.Context, request *artistInfoUser.FindUsersRequest) (*artistInfoUser.FindUsersUserViewResponse, error) {
|
|
|
|
return a.artistInfoLogic.FindUsersUserView(request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *ArtistInfoUserProvider) FindUsers(ctx context.Context, request *artistInfoUser.FindUsersRequest) (*artistInfoUser.FindUsersResponse, error) {
|
|
|
|
return a.artistInfoLogic.FindUserList(request)
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) RegisterUser(ctx context.Context, req *artistInfoUser.RegisterUserRequest) (rep *artistInfoUser.RegisterUserRespond, err error) {
|
2023-01-18 09:03:15 +00:00
|
|
|
fmt.Println("第一处")
|
2023-03-07 00:48:58 +00:00
|
|
|
//新增邀请码判断 by JJXu 2023-03-07
|
2023-03-08 07:26:38 +00:00
|
|
|
//if req.UserInviteCode == "" {
|
|
|
|
// return nil, errors.New("邀请码不能为空")
|
|
|
|
//}
|
2023-01-18 09:03:15 +00:00
|
|
|
if rep, err = a.artistInfoLogic.RegisterUser(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) UpdateIdCard(ctx context.Context, in *artistInfoUser.UpdateIdCardRequest) (rep *artistInfoUser.CommonNoParams, err error) {
|
2023-02-20 04:51:50 +00:00
|
|
|
var thisUser model.User
|
2023-03-30 06:38:11 +00:00
|
|
|
db.DB.Unscoped().Where("mgmt_acc_id = ?", in.MgmtAccId).Preload("RealNameInfo").Find(&thisUser)
|
|
|
|
thisUser.DeletedAt = 0
|
2023-02-20 04:51:50 +00:00
|
|
|
if thisUser.RealNameInfo == nil {
|
|
|
|
thisUser.RealNameInfo = &model.RealName{}
|
|
|
|
}
|
|
|
|
if in.Name != "" {
|
|
|
|
thisUser.RealNameInfo.Name = in.Name
|
|
|
|
}
|
|
|
|
if in.IdNum != "" {
|
|
|
|
thisUser.RealNameInfo.IdNum = in.IdNum
|
|
|
|
}
|
|
|
|
if in.Age != 0 {
|
|
|
|
thisUser.RealNameInfo.Age = int(in.Age)
|
|
|
|
}
|
|
|
|
if in.Sex != "" {
|
|
|
|
thisUser.RealNameInfo.Sex = model.SexType(in.Sex)
|
|
|
|
}
|
|
|
|
if in.Address != "" {
|
|
|
|
thisUser.RealNameInfo.Address = in.Address
|
|
|
|
}
|
|
|
|
if in.IdCardFront != "" {
|
|
|
|
thisUser.RealNameInfo.IdCardFront = in.IdCardFront
|
|
|
|
}
|
|
|
|
if in.IdCardBack != "" {
|
|
|
|
thisUser.RealNameInfo.IdCardBack = in.IdCardBack
|
|
|
|
}
|
|
|
|
if in.Birthday != "" {
|
|
|
|
thisUser.RealNameInfo.Birthday = in.Birthday
|
|
|
|
}
|
2023-03-30 06:30:25 +00:00
|
|
|
err = db.DB.Session(&gorm.Session{FullSaveAssociations: true}).Clauses(clause.OnConflict{UpdateAll: true}).Save(&thisUser).Error
|
2023-02-20 04:51:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetUser(ctx context.Context, req *artistInfoUser.GetUserRequest) (rep *artistInfoUser.GetUserRespond, err error) {
|
2023-01-18 09:03:15 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.GetUserInfoRespond{}
|
2023-01-18 09:03:15 +00:00
|
|
|
if rep, err = a.artistInfoLogic.GetUser(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetUserById(ctx context.Context, req *artistInfoUser.GetUserByIdRequest) (rep *artistInfoUser.GetUserByIdRespond, err error) {
|
2023-02-20 04:51:50 +00:00
|
|
|
return a.artistInfoLogic.GetUserById(req)
|
2023-01-18 09:03:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
//func (a *ArtistInfoUserProvider ) UpdateRealName(ctx context.Context, req *artistinfoUser.UpdateRealNameRequest) (rep *artistinfoUser.UpdateRealNameRespond, err error) {
|
2023-02-20 04:51:50 +00:00
|
|
|
// fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// // backup := &artistinfoUser.GetUserInfoRespond{}
|
2023-02-20 04:51:50 +00:00
|
|
|
// if rep, err = a.artistInfoLogic.UpdateRealName(req); err != nil {
|
|
|
|
// return nil, err
|
|
|
|
// }
|
|
|
|
// return rep, nil
|
|
|
|
//}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) FinishVerify(ctx context.Context, req *artistInfoUser.FinishVerifyRequest) (rep *artistInfoUser.FinishVerifyRespond, err error) {
|
2023-01-18 09:03:15 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.GetUserInfoRespond{}
|
2023-01-18 09:03:15 +00:00
|
|
|
if rep, err = a.artistInfoLogic.FinishVerify(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) UserLock(ctx context.Context, req *artistInfoUser.UserLockRequest) (rep *artistInfoUser.UserLockRespond, err error) {
|
2023-02-23 13:45:59 +00:00
|
|
|
return a.artistInfoLogic.UserLock(req)
|
|
|
|
}
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) CheckUserLock(ctx context.Context, req *artistInfoUser.CheckUserLockRequest) (rep *artistInfoUser.CheckUserLockRespond, err error) {
|
2023-01-18 09:03:15 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.GetUserInfoRespond{}
|
2023-01-18 09:03:15 +00:00
|
|
|
if rep, err = a.artistInfoLogic.CheckUserLock(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
2023-02-02 06:10:24 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) ArtistSupplyList(ctx context.Context, req *artistInfoUser.ArtistSupplyListRequest) (rep *artistInfoUser.ArtistSupplyListRespond, err error) {
|
2023-02-02 06:10:24 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.GetUserInfoRespond{}
|
2023-02-02 06:10:24 +00:00
|
|
|
if rep, err = a.artistInfoLogic.ArtistSupplyList(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
2023-02-15 01:10:11 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) CheckInvitedCode(ctx context.Context, req *artistInfoUser.CheckInvitedCodeRequest) (rep *artistInfoUser.GetUserRespond, err error) {
|
2023-02-15 01:39:14 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.CheckInvitedCodeInfoRespond{}
|
2023-02-15 01:39:14 +00:00
|
|
|
if rep, err = a.artistInfoLogic.CheckInvitedCode(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) UnFinishList(ctx context.Context, req *artistInfoUser.UnFinishListRequest) (rep *artistInfoUser.UnFinishListRespond, err error) {
|
2023-02-15 01:39:14 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.UnFinishListInfoRespond{}
|
2023-02-15 01:39:14 +00:00
|
|
|
if rep, err = a.artistInfoLogic.UnFinishList(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetUserMsg(ctx context.Context, req *artistInfoUser.GetUserMsgRequest) (rep *artistInfoUser.GetUserMsgRespond, err error) {
|
2023-02-15 01:39:14 +00:00
|
|
|
fmt.Println("第一处")
|
2023-02-24 16:30:57 +00:00
|
|
|
// backup := &artistinfoUser.GetUserMsgInfoRespond{}
|
2023-02-15 01:39:14 +00:00
|
|
|
if rep, err = a.artistInfoLogic.GetUserMsg(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return rep, nil
|
|
|
|
}
|
2023-02-15 02:14:53 +00:00
|
|
|
|
2023-02-15 01:10:11 +00:00
|
|
|
// 绑定邀请人和受邀请人的账号,并加入到次数统计
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) BindInviteInvitedAccount(ctx context.Context, in *artistInfoUser.BindInviteInvitedAccountRequest) (res *artistInfoUser.BindInviteInvitedAccountRespond, err error) {
|
2023-03-31 03:18:56 +00:00
|
|
|
// 查询邀请人是否存在
|
2023-03-31 01:27:49 +00:00
|
|
|
var thisUser model.User
|
2023-03-14 07:09:13 +00:00
|
|
|
if in.InvitedUserId == 0 {
|
2023-03-31 03:18:56 +00:00
|
|
|
if err = db.DB.Where("invited_code = ?", in.InviteCode).First(&thisUser).Error; err != nil {
|
2023-03-14 07:09:13 +00:00
|
|
|
if err == gorm.ErrRecordNotFound {
|
2023-03-31 03:18:56 +00:00
|
|
|
return nil, errors.New("邀请人不存在")
|
2023-03-14 07:09:13 +00:00
|
|
|
} else {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2023-02-15 02:03:22 +00:00
|
|
|
}
|
2023-03-31 03:35:03 +00:00
|
|
|
fmt.Println("邀请人userId:", thisUser.ID)
|
2023-02-15 01:10:11 +00:00
|
|
|
var data model.Invite
|
2023-03-14 07:09:13 +00:00
|
|
|
// 受邀请者只能绑定一个邀请人
|
2023-03-31 03:31:03 +00:00
|
|
|
if err = db.DB.Where("invite_code = ? AND invited_code = ?", in.InviteCode, in.InvitedCode).Find(&data).Error; err != nil {
|
2023-02-15 01:10:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2023-03-31 01:40:29 +00:00
|
|
|
data.UserId = int32(thisUser.ID)
|
|
|
|
data.InvitedId = in.InvitedUserId
|
|
|
|
data.InvitedCode = in.InvitedCode
|
|
|
|
data.InviteCode = in.InviteCode
|
|
|
|
//如果数据存更新刷新时间
|
2023-03-31 02:07:39 +00:00
|
|
|
if err = db.DB.Debug().Save(&data).Error; err != nil {
|
2023-03-31 01:40:29 +00:00
|
|
|
return nil, err
|
2023-02-15 01:10:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 添加到次数统计
|
|
|
|
var countData model.UserInvited
|
2023-03-14 07:09:13 +00:00
|
|
|
if err = db.DB.Where("invite_code = ? AND invited_code =?", in.InviteCode, in.InvitedCode).Find(&countData).Error; err != nil {
|
2023-02-15 01:10:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2023-03-14 07:09:13 +00:00
|
|
|
if countData.ID == 0 {
|
2023-02-15 01:10:11 +00:00
|
|
|
countData = model.UserInvited{
|
2023-03-31 01:27:49 +00:00
|
|
|
UserId: int32(thisUser.ID),
|
2023-03-14 07:09:13 +00:00
|
|
|
InvitedUserId: in.InvitedUserId, //受邀请人的画家宝用户id
|
2023-02-15 01:10:11 +00:00
|
|
|
Count: 1,
|
2023-02-16 00:15:44 +00:00
|
|
|
InvitedCode: in.InvitedCode,
|
|
|
|
InviteCode: in.InviteCode,
|
2023-02-15 01:10:11 +00:00
|
|
|
}
|
|
|
|
if err = db.DB.Create(&countData).Error; err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
countData.Count += 1
|
2023-03-14 07:09:13 +00:00
|
|
|
if err = db.DB.Model(model.UserInvited{}).Where("id = ?", countData.ID).Update("count", countData.Count).Error; err != nil {
|
2023-02-15 01:10:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-02-15 14:35:28 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) BindArtistId(ctx context.Context, in *artistInfoUser.BindArtistIdRequest) (*artistInfoUser.BindArtistIdResp, error) {
|
2023-02-20 04:51:50 +00:00
|
|
|
var updateData = map[string]any{
|
2023-02-22 14:13:50 +00:00
|
|
|
"mgmt_artist_id": in.ArtistId,
|
|
|
|
"mgmt_artist_uid": in.ArtistUid,
|
2023-03-08 07:26:38 +00:00
|
|
|
//"fdd_state": 2,
|
2023-02-20 04:51:50 +00:00
|
|
|
}
|
|
|
|
if err := db.DB.Model(model.User{}).Where("mgmt_acc_id = ?", in.UserId).Updates(&updateData).Error; err != nil {
|
2023-02-24 16:30:57 +00:00
|
|
|
return &artistInfoUser.BindArtistIdResp{Error: err.Error()}, err
|
2023-02-15 14:35:28 +00:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
2023-02-17 03:33:56 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) FindUser(ctx context.Context, in *artistInfoUser.FindUserRequest) (*artistInfoUser.UserInfo, error) {
|
2023-02-17 03:33:56 +00:00
|
|
|
return a.artistInfoLogic.FindUser(in)
|
|
|
|
}
|
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) UpdateUserData(ctx context.Context, in *artistInfoUser.UserInfo) (*artistInfoUser.CommonNoParams, error) {
|
2023-02-17 03:33:56 +00:00
|
|
|
return a.artistInfoLogic.UpdateUserData(in)
|
|
|
|
}
|
2023-02-22 05:37:50 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) PreSaveArtistInfo(ctx context.Context, in *artistInfoUser.PreSaveArtistInfoData) (res *artistInfoUser.CommonNoParams, er error) {
|
2023-02-22 05:37:50 +00:00
|
|
|
return a.artistInfoLogic.PreSaveArtistInfo(in)
|
|
|
|
}
|
2023-03-10 09:27:10 +00:00
|
|
|
|
2023-02-24 16:30:57 +00:00
|
|
|
func (a *ArtistInfoUserProvider) GetPreSaveArtistInfo(ctx context.Context, in *artistInfoUser.GetPreSaveArtistInfoRequest) (res *artistInfoUser.PreSaveArtistInfoData, err error) {
|
2023-02-22 05:37:50 +00:00
|
|
|
return a.artistInfoLogic.GetPreSaveArtistInfo(in)
|
|
|
|
}
|