50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
|
|
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 ListPurchaseReceiptLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListPurchaseReceiptLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPurchaseReceiptLogic {
|
||
|
|
return &ListPurchaseReceiptLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListPurchaseReceiptLogic) ListPurchaseReceipt(in *pb.ListPurchaseReceiptReq) (*pb.ListPurchaseReceiptResp, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
status := in.Status
|
||
|
|
if status == 0 {
|
||
|
|
status = -1
|
||
|
|
}
|
||
|
|
list, total, err := l.svcCtx.ReceiptModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.OrderId, status, in.StartDate, in.EndDate)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items := make([]*pb.PurchaseReceiptInfo, 0, len(list))
|
||
|
|
for _, r := range list {
|
||
|
|
items = append(items, &pb.PurchaseReceiptInfo{
|
||
|
|
ReceiptId: r.ReceiptId,
|
||
|
|
ReceiptNo: r.ReceiptNo,
|
||
|
|
OrderId: r.OrderId,
|
||
|
|
ReceiptDate: r.ReceiptDate.Format("2006-01-02"),
|
||
|
|
ReceivedBy: r.ReceivedBy,
|
||
|
|
Status: r.Status,
|
||
|
|
Remark: r.Remark.String,
|
||
|
|
CreatedAt: r.CreatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
_ = fmt.Sprintf // suppress unused import
|
||
|
|
return &pb.ListPurchaseReceiptResp{Total: total, List: items}, nil
|
||
|
|
}
|