52 lines
1.5 KiB
Go
52 lines
1.5 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 ListSupplierLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewListSupplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListSupplierLogic {
|
||
|
|
return &ListSupplierLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *ListSupplierLogic) ListSupplier(in *pb.ListSupplierReq) (*pb.ListSupplierResp, error) {
|
||
|
|
tenantId := tenantctx.ExtractTenantId(l.ctx)
|
||
|
|
status := in.Status
|
||
|
|
if status == 0 {
|
||
|
|
status = -1
|
||
|
|
}
|
||
|
|
list, total, err := l.svcCtx.SupplierModel.FindList(l.ctx, tenantId, in.Page, in.PageSize, in.SupplierName, status)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items := make([]*pb.SupplierInfo, 0, len(list))
|
||
|
|
for _, s := range list {
|
||
|
|
items = append(items, &pb.SupplierInfo{
|
||
|
|
SupplierId: s.SupplierId,
|
||
|
|
SupplierName: s.SupplierName,
|
||
|
|
Phone: s.Phone,
|
||
|
|
PurchaseCount: s.PurchaseCount,
|
||
|
|
DeliveredQty: fmt.Sprintf("%.2f", s.DeliveredQty),
|
||
|
|
PayableAmount: fmt.Sprintf("%.2f", s.PayableAmount),
|
||
|
|
PaidAmount: fmt.Sprintf("%.2f", s.PaidAmount),
|
||
|
|
Status: s.Status,
|
||
|
|
Remark: s.Remark.String,
|
||
|
|
CreatedAt: s.CreatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
UpdatedAt: s.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return &pb.ListSupplierResp{Total: total, List: items}, nil
|
||
|
|
}
|