42 lines
1.1 KiB
Go
42 lines
1.1 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 GetSupplierLogic struct {
|
||
|
|
ctx context.Context
|
||
|
|
svcCtx *svc.ServiceContext
|
||
|
|
logx.Logger
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewGetSupplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSupplierLogic {
|
||
|
|
return &GetSupplierLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (l *GetSupplierLogic) GetSupplier(in *pb.GetSupplierReq) (*pb.SupplierInfo, error) {
|
||
|
|
s, err := l.svcCtx.SupplierModel.FindOneBySupplierId(l.ctx, in.SupplierId)
|
||
|
|
if err != nil {
|
||
|
|
return nil, ErrSupplierNotFound
|
||
|
|
}
|
||
|
|
return &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"),
|
||
|
|
}, nil
|
||
|
|
}
|