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).
59 lines
1.6 KiB
Go
59 lines
1.6 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 GetPurchaseReceiptLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGetPurchaseReceiptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPurchaseReceiptLogic {
|
|
return &GetPurchaseReceiptLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
|
}
|
|
|
|
func (l *GetPurchaseReceiptLogic) GetPurchaseReceipt(in *pb.GetPurchaseReceiptReq) (*pb.PurchaseReceiptInfo, error) {
|
|
receipt, err := l.svcCtx.ReceiptModel.FindOneByReceiptId(l.ctx, in.ReceiptId)
|
|
if err != nil {
|
|
return nil, ErrReceiptNotFound
|
|
}
|
|
|
|
details, err := l.svcCtx.ReceiptDetailModel.FindByReceiptId(l.ctx, in.ReceiptId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pbDetails := make([]*pb.PurchaseReceiptDetailInfo, 0, len(details))
|
|
for _, d := range details {
|
|
pbDetails = append(pbDetails, &pb.PurchaseReceiptDetailInfo{
|
|
DetailId: d.DetailId,
|
|
ReceiptId: d.ReceiptId,
|
|
OrderDetailId: d.OrderDetailId,
|
|
ProductId: d.ProductId,
|
|
ActualQty: fmt.Sprintf("%.2f", d.ActualQty),
|
|
UnitCost: fmt.Sprintf("%.2f", d.UnitCost),
|
|
Remark: d.Remark.String,
|
|
})
|
|
}
|
|
|
|
return &pb.PurchaseReceiptInfo{
|
|
ReceiptId: receipt.ReceiptId,
|
|
ReceiptNo: receipt.ReceiptNo,
|
|
OrderId: receipt.OrderId,
|
|
ReceiptDate: receipt.ReceiptDate.Format("2006-01-02"),
|
|
ReceivedBy: receipt.ReceivedBy,
|
|
Status: receipt.Status,
|
|
Remark: receipt.Remark.String,
|
|
CreatedAt: receipt.CreatedAt.Format("2006-01-02 15:04:05"),
|
|
Details: pbDetails,
|
|
}, nil
|
|
}
|