@@ -1,4 +1,4 @@
|
||||
package card
|
||||
package cart
|
||||
|
||||
import (
|
||||
"cake_crm/internal/modules/storage"
|
||||
@@ -23,8 +23,10 @@ func NewService(storage storage.IStorage) *Service {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*proto.CardItem, error) {
|
||||
res := make([]*proto.CardItem, 0, len(items))
|
||||
func (s *Service) GetCart(ctx context.Context, items []*proto.OrderItem) (*proto.CartRsp, error) {
|
||||
var cartAmount int64
|
||||
var cartAmountOld int64
|
||||
res := make([]*proto.CartItem, 0, len(items))
|
||||
for _, item := range items {
|
||||
product, err := s.storage.GetProduct(ctx, item.ProductId)
|
||||
if err != nil {
|
||||
@@ -41,7 +43,7 @@ func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*pro
|
||||
}
|
||||
res = append(
|
||||
res,
|
||||
&proto.CardItem{
|
||||
&proto.CartItem{
|
||||
Id: product.Id,
|
||||
Article: product.Article,
|
||||
Name: product.Name,
|
||||
@@ -56,8 +58,14 @@ func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*pro
|
||||
Labels: product.Labels,
|
||||
},
|
||||
)
|
||||
cartAmount += amount
|
||||
cartAmountOld += amountOld
|
||||
}
|
||||
return res, nil
|
||||
return &proto.CartRsp{
|
||||
Items: res,
|
||||
Amount: cartAmount,
|
||||
AmountOld: cartAmountOld,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func calcItemAmount(item *ProductAndCount) (int64, int64, error) {
|
||||
@@ -13,12 +13,11 @@ func NewService() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
|
||||
func (s *Service) CreateOrderText(req *proto.OrderReq, items []*proto.CardItem) (string, error) {
|
||||
func (s *Service) CreateOrderText(req *proto.OrderReq, cart *proto.CartRsp) (string, error) {
|
||||
buffer := bytes.Buffer{}
|
||||
var orderAmount int64
|
||||
buffer.WriteString(fmt.Sprintf("Заказ от:\n%s\n%s\n", req.Order.Name, req.Order.Phone))
|
||||
buffer.WriteString("\n")
|
||||
for _, item := range items {
|
||||
for _, item := range cart.Items {
|
||||
buffer.WriteString(item.Name)
|
||||
buffer.WriteString("\n")
|
||||
unit, err := unitToText(item.Unit)
|
||||
@@ -26,12 +25,11 @@ func (s *Service) CreateOrderText(req *proto.OrderReq, items []*proto.CardItem)
|
||||
return "", err
|
||||
}
|
||||
buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.Count, unit))
|
||||
orderAmount += item.Amount
|
||||
buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", float64(item.Amount)/100))
|
||||
buffer.WriteString("\n")
|
||||
}
|
||||
buffer.WriteString("\n")
|
||||
buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(orderAmount)/100))
|
||||
buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(cart.Amount)/100))
|
||||
return buffer.String(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user