muyu-apiserver/rpc/purchase/internal/logic/listpurchasepaymentlogic.go

46 lines
1.4 KiB
Go
Raw Normal View History

package logic
import (
"context"
"fmt"
"muyu-apiserver/pkg/tenantctx"
"muyu-apiserver/rpc/purchase/internal/svc"
"muyu-apiserver/rpc/purchase/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type ListPurchasePaymentLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewListPurchasePaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPurchasePaymentLogic {
return &ListPurchasePaymentLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *ListPurchasePaymentLogic) ListPurchasePayment(in *pb.ListPurchasePaymentReq) (*pb.ListPurchasePaymentResp, error) {
tenantId := tenantctx.ExtractTenantId(l.ctx)
list, total, err := l.svcCtx.PaymentModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.OrderId, in.SupplierId, in.StartDate, in.EndDate)
if err != nil {
return nil, err
}
items := make([]*pb.PurchasePaymentInfo, 0, len(list))
for _, p := range list {
items = append(items, &pb.PurchasePaymentInfo{
PaymentId: p.PaymentId,
OrderId: p.OrderId,
SupplierId: p.SupplierId,
PaymentDate: p.PaymentDate.Format("2006-01-02"),
Amount: fmt.Sprintf("%.2f", p.Amount),
PaymentMethod: p.PaymentMethod,
Operator: p.Operator,
Remark: p.Remark.String,
CreatedAt: p.CreatedAt.Format("2006-01-02 15:04:05"),
})
}
return &pb.ListPurchasePaymentResp{Total: total, List: items}, nil
}