feat: 迁移plant
This commit is contained in:
@@ -5,9 +5,11 @@ package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -28,7 +30,14 @@ func NewCreateExchangeOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func (l *CreateExchangeOrderLogic) CreateExchangeOrder(req *types.ExchangeOrderReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
_, err := l.svcCtx.PlantRpc.CreateExchangeOrder(l.ctx, &plant.CreateExchangeOrderReq{
|
||||
UserId: userId,
|
||||
ItemId: req.ItemId,
|
||||
Quantity: int32(req.Quantity),
|
||||
RecipientName: req.RecipientName,
|
||||
Phone: req.Phone,
|
||||
Address: req.Address,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
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 DeleteExchangeItemLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteExchangeItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteExchangeItemLogic {
|
||||
return &DeleteExchangeItemLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteExchangeItemLogic) DeleteExchangeItem(req *types.IdsReq) error {
|
||||
_, err := l.svcCtx.PlantRpc.DeleteExchangeItem(l.ctx, &plantPb.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"sundynix-micro-go/app/plant/api/internal/svc"
|
||||
"sundynix-micro-go/app/plant/api/internal/types"
|
||||
"sundynix-micro-go/app/plant/rpc/plant"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -27,8 +28,16 @@ func NewGetExchangeItemListLogic(ctx context.Context, svcCtx *svc.ServiceContext
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetExchangeItemListLogic) GetExchangeItemList(req *types.ExchangeItemListReq) error {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return nil
|
||||
func (l *GetExchangeItemListLogic) GetExchangeItemList(req *types.ExchangeItemListReq) (interface{}, error) {
|
||||
result, err := l.svcCtx.PlantRpc.GetExchangeItemList(l.ctx, &plant.ExchangeItemListReq{
|
||||
Current: int32(req.Current),
|
||||
PageSize: int32(req.PageSize),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"list": result.List,
|
||||
"total": result.Total,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
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 GetExchangeOrderListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetExchangeOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetExchangeOrderListLogic {
|
||||
return &GetExchangeOrderListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetExchangeOrderListLogic) GetExchangeOrderList(req *types.ExchangeOrderListReq) (*plantPb.ExchangeOrderListResp, error) {
|
||||
return l.svcCtx.PlantRpc.GetExchangeOrderList(l.ctx, &plantPb.ExchangeOrderListReq{
|
||||
UserId: req.UserId, Current: int32(req.Current), PageSize: int32(req.PageSize), Status: int32(req.Status),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package exchange
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"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 GetMyExchangeOrdersLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetMyExchangeOrdersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMyExchangeOrdersLogic {
|
||||
return &GetMyExchangeOrdersLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMyExchangeOrdersLogic) GetMyExchangeOrders(req *types.ExchangeOrderListReq) (*plantPb.ExchangeOrderListResp, error) {
|
||||
userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
|
||||
return l.svcCtx.PlantRpc.GetMyExchangeOrders(l.ctx, &plantPb.ExchangeOrderListReq{
|
||||
UserId: userId, Current: int32(req.Current), PageSize: int32(req.PageSize), Status: int32(req.Status),
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
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 UpdateExchangeItemLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateExchangeItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateExchangeItemLogic {
|
||||
return &UpdateExchangeItemLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateExchangeItemLogic) UpdateExchangeItem(req *types.UpdateExchangeItemReq) 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.UpdateExchangeItem(l.ctx, &plantPb.UpdateExchangeItemReq{
|
||||
Id: req.Id, Name: req.Name, Desc: desc, ImgId: imgID,
|
||||
Cost: cost, Stock: int32(req.Stock), Status: int32(req.Status),
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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 UpdateExchangeOrderLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateExchangeOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateExchangeOrderLogic {
|
||||
return &UpdateExchangeOrderLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateExchangeOrderLogic) UpdateExchangeOrder(req *types.UpdateExchangeOrderReq) error {
|
||||
_, err := l.svcCtx.PlantRpc.UpdateExchangeOrder(l.ctx, &plantPb.UpdateExchangeOrderReq{
|
||||
Id: req.Id, Status: int32(req.Status), TrackingNo: req.TrackingNo, Remark: req.Remark,
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user