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 }