Files
juwan-backend/app/shop/rpc/internal/logic/updateShopPlayersLogic.go
T
wwweww 19cc7a778c Refactor: Remove deprecated gRPC service files and implement new API structure
- Deleted old gRPC service definitions in `game_grpc.pb.go` and `public.go`.
- Added new API server implementations for objectstory, player, and shop services.
- Introduced configuration files for new APIs in `etc/*.yaml`.
- Created main entry points for each service in `objectstory.go`, `player.go`, and `shop.go`.
- Removed unused user update handler and user API files.
- Added utility functions for context management and HTTP header parsing.
- Introduced PostgreSQL backup configuration in `backup/postgreSql.yaml`.
2026-02-28 18:35:56 +08:00

60 lines
1.4 KiB
Go

package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopPlayersLogic {
return &UpdateShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopPlayersLogic) UpdateShopPlayers(in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
if in.ShopId <= 0 || in.PlayerId <= 0 {
return nil, errors.New("invalid shop_id or player_id")
}
preds := []predicate.ShopPlayers{
shopplayers.ShopIDEQ(in.ShopId),
shopplayers.PlayerIDEQ(in.PlayerId),
}
updater := l.svcCtx.ShopModelRW.ShopPlayers.Update().
Where(shopplayers.And(preds...)).
SetIsPrimary(in.IsPrimary)
if in.LeftAt > 0 {
t := time.Unix(in.LeftAt, 0)
updater = updater.SetLeftAt(t)
}
affected, err := updater.Save(l.ctx)
if err != nil {
logx.Errorf("update shop players failed, %s", err.Error())
return nil, errors.New("update shop players failed")
}
if affected == 0 {
return nil, errors.New("shop player not found")
}
return &pb.UpdateShopPlayersResp{}, nil
}