58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"juwan-backend/app/snowflake/rpc/snowflake"
|
|
|
|
"juwan-backend/app/player/rpc/internal/svc"
|
|
"juwan-backend/app/player/rpc/pb"
|
|
|
|
"github.com/shopspring/decimal"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AddPlayersLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewAddPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddPlayersLogic {
|
|
return &AddPlayersLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// -----------------------players-----------------------
|
|
func (l *AddPlayersLogic) AddPlayers(in *pb.AddPlayersReq) (*pb.AddPlayersResp, error) {
|
|
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
|
|
if err != nil {
|
|
logx.Errorf("addPlayerServices err:%v", err)
|
|
return nil, errors.New("create player service id failed")
|
|
}
|
|
gender := 0
|
|
if in.Gender != 0 {
|
|
gender = 1
|
|
}
|
|
_, err = l.svcCtx.PlayerModelRW.Players.Create().
|
|
SetID(idResp.Id).
|
|
SetUserID(in.UserId).
|
|
SetStatus(in.Status).
|
|
SetRating(decimal.NewFromFloat(in.Rating)).
|
|
SetTotalOrders(int(in.TotalOrders)).
|
|
SetCompletedOrders(int(in.CompletedOrders)).
|
|
SetShopID(in.ShopId).
|
|
SetTags(in.Tags).
|
|
SetGender(gender).
|
|
SetGames(in.Games).
|
|
Save(l.ctx)
|
|
if err != nil {
|
|
logx.Errorf("addPlayerServices err:%v", err)
|
|
return nil, errors.New("add player service failed")
|
|
}
|
|
return &pb.AddPlayersResp{}, nil
|
|
}
|