Files
juwan-backend/app/shop/rpc/internal/logic/addShopsLogic.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

78 lines
2.0 KiB
Go

package logic
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/shopspring/decimal"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopsLogic {
return &AddShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shops-----------------------
func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, 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")
}
var templateConfig map[string]interface{}
err = json.Unmarshal([]byte(in.TemplateConfig), &templateConfig)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("invalid template config")
}
rating, err := decimal.NewFromString(in.Rating)
if err != nil {
return nil, errors.New("invalid rating")
}
commissionValue, err := decimal.NewFromString(in.CommissionValue)
if err != nil {
return nil, errors.New("invalid commissionValue")
}
_, err = l.svcCtx.ShopModelRO.Shops.Create().
SetID(idResp.Id).
SetOwnerID(in.OwnerId).
SetName(in.Name).
SetBanner(in.Banner).
SetDescription(in.Description).
SetRating(rating).
SetTotalOrders(int(in.TotalOrders)).
SetPlayerCount(int(in.PlayerCount)).
SetNillableCommissionType(&in.CommissionType).
SetCommissionValue(commissionValue).
SetAllowMultiShop(in.AllowMultiShop).
SetAllowIndependentOrders(in.AllowIndependentOrders).
SetDispatchMode(in.DispatchMode).
SetAnnouncements(in.Announcements).
SetTemplateConfig(templateConfig).
Save(l.ctx)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("add player service failed")
}
return &pb.AddShopsResp{}, nil
}