fix: shop_players 关系表主键与模型对齐

This commit is contained in:
zetaloop
2026-04-04 06:25:49 +08:00
parent 3a81aec527
commit 7dc088eadf
18 changed files with 91 additions and 310 deletions
@@ -3,7 +3,6 @@ package logic
import (
"context"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
@@ -27,14 +26,7 @@ func NewAddShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ad
// -----------------------shopPlayers-----------------------
func (l *AddShopPlayersLogic) AddShopPlayers(in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, 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")
}
_, err = l.svcCtx.ShopModelRW.ShopPlayers.Create().
SetID(idResp.Id).
_, err := l.svcCtx.ShopModelRW.ShopPlayers.Create().
SetShopID(in.ShopId).
SetPlayerID(in.PlayerId).
SetIsPrimary(in.IsPrimary).
@@ -3,6 +3,7 @@ package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
@@ -25,11 +26,19 @@ func NewDelShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De
}
func (l *DelShopPlayersLogic) DelShopPlayers(in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) {
err := l.svcCtx.ShopModelRO.ShopPlayers.DeleteOneID(in.Id).Exec(l.ctx)
affected, err := l.svcCtx.ShopModelRW.ShopPlayers.Delete().
Where(
shopplayers.ShopIDEQ(in.ShopId),
shopplayers.PlayerIDEQ(in.PlayerId),
).
Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop players failed, %s", err.Error())
return nil, errors.New("delete failed")
}
if affected == 0 {
return nil, errors.New("delete failed")
}
return &pb.DelShopPlayersResp{}, nil
}
@@ -26,7 +26,10 @@ func NewGetShopPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *GetShopPlayersByIdLogic) GetShopPlayersById(in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) {
shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where(shopplayers.IDEQ(in.Id)).First(l.ctx)
shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where(
shopplayers.ShopIDEQ(in.ShopId),
shopplayers.PlayerIDEQ(in.PlayerId),
).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopPlayersByIdLogic err: %v", err)
return nil, errors.New("get shop players by id failed")