41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package exchange
|
|
|
|
import (
|
|
"context"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"sundynix-micro-go/app/plant/api/internal/svc"
|
|
"sundynix-micro-go/app/plant/api/internal/types"
|
|
plantPb "sundynix-micro-go/app/plant/rpc/plant"
|
|
)
|
|
|
|
type CreateExchangeItemLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewCreateExchangeItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateExchangeItemLogic {
|
|
return &CreateExchangeItemLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
|
}
|
|
|
|
func (l *CreateExchangeItemLogic) CreateExchangeItem(req *types.CreateExchangeItemReq) error {
|
|
desc := req.Desc
|
|
if desc == "" {
|
|
desc = req.Description
|
|
}
|
|
imgID := req.ImgId
|
|
if imgID == "" {
|
|
imgID = req.ImageId
|
|
}
|
|
cost := req.Cost
|
|
if cost == 0 {
|
|
cost = req.CostSunlight
|
|
}
|
|
_, err := l.svcCtx.PlantRpc.CreateExchangeItem(l.ctx, &plantPb.CreateExchangeItemReq{
|
|
Name: req.Name, Desc: desc, ImgId: imgID, Cost: cost, Stock: int32(req.Stock),
|
|
Type: req.Type, CostSunlight: req.CostSunlight, LimitPerUser: int32(req.LimitPerUser),
|
|
Sort: int32(req.Sort), StartTime: req.StartTime, EndTime: req.EndTime, ImageId: req.ImageId,
|
|
})
|
|
return err
|
|
}
|