muyu-apiserver/rpc/purchase/internal/logic/getpurchaseorderlogic.go
Chever John a25acdc5e4 chore: sync codebase with upstream
Pull latest changes from upstream/main (GitHub) including:
- Purchase RPC service (proto, server, logic, models)
- Gateway route updates for purchase endpoints
- SQL migration and config updates

Excludes deploy/bin/ pre-compiled arm64 binaries (builds use
multi-stage Dockerfiles targeting amd64).
2026-06-15 09:20:56 +08:00

78 lines
2.3 KiB
Go

package logic
import (
"context"
"fmt"
"muyu-apiserver/rpc/purchase/internal/svc"
"muyu-apiserver/rpc/purchase/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetPurchaseOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetPurchaseOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPurchaseOrderLogic {
return &GetPurchaseOrderLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *GetPurchaseOrderLogic) GetPurchaseOrder(in *pb.GetPurchaseOrderReq) (*pb.PurchaseOrderInfo, error) {
order, err := l.svcCtx.OrderModel.FindOneByOrderId(l.ctx, in.OrderId)
if err != nil {
return nil, ErrOrderNotFound
}
details, err := l.svcCtx.OrderDetailModel.FindByOrderId(l.ctx, in.OrderId)
if err != nil {
return nil, err
}
pbDetails := make([]*pb.PurchaseOrderDetailInfo, 0, len(details))
for _, d := range details {
pbDetails = append(pbDetails, &pb.PurchaseOrderDetailInfo{
DetailId: d.DetailId,
OrderId: d.OrderId,
ProductId: d.ProductId,
ProductName: d.ProductName,
Spec: d.Spec,
Color: d.Color,
Quantity: fmt.Sprintf("%.2f", d.Quantity),
UnitPrice: fmt.Sprintf("%.2f", d.UnitPrice),
Amount: fmt.Sprintf("%.2f", d.Amount),
ReceivedQty: fmt.Sprintf("%.2f", d.ReceivedQty),
Remark: d.Remark.String,
})
}
// Get supplier name
supplierName := ""
if s, err := l.svcCtx.SupplierModel.FindOneBySupplierId(l.ctx, order.SupplierId); err == nil {
supplierName = s.SupplierName
}
return &pb.PurchaseOrderInfo{
OrderId: order.OrderId,
OrderNo: order.OrderNo,
SupplierId: order.SupplierId,
SupplierName: supplierName,
OrderDate: order.OrderDate.Format("2006-01-02"),
ContractAmount: fmt.Sprintf("%.2f", order.ContractAmount),
ReceivedQty: fmt.Sprintf("%.2f", order.ReceivedQty),
PaidAmount: fmt.Sprintf("%.2f", order.PaidAmount),
PaymentStatus: order.PaymentStatus,
ReceiptStatus: order.ReceiptStatus,
PurchaseBy: order.PurchaseBy,
Creator: order.Creator,
Operator: order.Operator,
Status: order.Status,
Remark: order.Remark.String,
CreatedAt: order.CreatedAt.Format("2006-01-02 15:04:05"),
UpdatedAt: order.UpdatedAt.Format("2006-01-02 15:04:05"),
Details: pbDetails,
}, nil
}