53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
|
|
package order
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"muyu-apiserver/gateway/internal/svc"
|
||
|
|
"muyu-apiserver/gateway/internal/types"
|
||
|
|
"muyu-apiserver/rpc/purchase/purchaseservice"
|
||
|
|
|
||
|
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
|
)
|
||
|
|
|
||
|
|
type CreatePurchaseOrderLogic struct {
|
||
|
|
logx.Logger
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewCreatePurchaseOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePurchaseOrderLogic {
|
||
|
|
return &CreatePurchaseOrderLogic{
|
||
|
|
Logger: logx.WithContext(ctx),
|
||
|
|
ctx: ctx,
|
||
|
|
svcCtx: svcCtx,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *CreatePurchaseOrderLogic) CreatePurchaseOrder(req *types.CreatePurchaseOrderReq) (*types.IdResp, error) {
|
||
|
|
details := make([]*purchaseservice.PurchaseOrderDetailReq, 0, len(req.Details))
|
||
|
|
for _, d := range req.Details {
|
||
|
|
details = append(details, &purchaseservice.PurchaseOrderDetailReq{
|
||
|
|
ProductId: d.ProductId,
|
||
|
|
ProductName: d.ProductName,
|
||
|
|
Spec: d.Spec,
|
||
|
|
Color: d.Color,
|
||
|
|
Quantity: d.Quantity,
|
||
|
|
UnitPrice: d.UnitPrice,
|
||
|
|
Remark: d.Remark,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
resp, err := l.svcCtx.PurchaseRpc.CreatePurchaseOrder(l.ctx, &purchaseservice.CreatePurchaseOrderReq{
|
||
|
|
SupplierId: req.SupplierId,
|
||
|
|
OrderDate: req.OrderDate,
|
||
|
|
PurchaseBy: req.PurchaseBy,
|
||
|
|
Remark: req.Remark,
|
||
|
|
Details: details,
|
||
|
|
})
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return &types.IdResp{Id: resp.Id}, nil
|
||
|
|
}
|