float62 32 格式化为两位
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"lone-services/services/order/internal/dao"
|
||||
"lone-services/services/order/internal/model"
|
||||
"lone-services/services/order/validator"
|
||||
@@ -63,6 +64,55 @@ func (l *WebCartLogic) WebCart(in *order.CartRequest) (*order.Response, error) {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
var ret []dao.CartRet
|
||||
if len(info.Content) < utils.NumberOne {
|
||||
return l.ok(ret)
|
||||
}
|
||||
|
||||
return l.ok(info)
|
||||
var data [][]int
|
||||
ok := utils.JsonStringToStruct(info.Content, &data)
|
||||
if !ok {
|
||||
return l.ok(ret)
|
||||
}
|
||||
|
||||
var ids []int64
|
||||
idsName := make(map[int64]int)
|
||||
for _, v := range data {
|
||||
ids = append(ids, int64(v[0]))
|
||||
idsName[int64(v[0])] = v[1]
|
||||
}
|
||||
|
||||
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
|
||||
if err != nil {
|
||||
logx.Errorf("get rpc client err: %v", err)
|
||||
return l.fail(utils.ErrorInternalServer)
|
||||
}
|
||||
productClient := product.NewProductClient(cli.Conn())
|
||||
productItems, err := productClient.ItemsByIds(context.Background(), &product.ItemsByIdsReq{Ids: ids})
|
||||
if err != nil {
|
||||
logx.Errorf("get products err: %v", err)
|
||||
return l.fail(utils.ErrorInternalServer)
|
||||
}
|
||||
|
||||
logx.Errorf("get products: %v", productItems.Items)
|
||||
logx.Errorf("get ids: %v", idsName)
|
||||
|
||||
for _, productItem := range productItems.Items {
|
||||
num := 0
|
||||
if v, ok := idsName[productItem.Id]; ok {
|
||||
num = v
|
||||
}
|
||||
ret = append(ret, dao.CartRet{
|
||||
ProductId: productItem.Id,
|
||||
ProductName: productItem.Name,
|
||||
Price: utils.RoundFloat(productItem.Price),
|
||||
SalePrice: utils.RoundFloat(productItem.SalePrice),
|
||||
StorePrice: utils.RoundFloat(productItem.StorePrice),
|
||||
Stock: productItem.Number,
|
||||
Images: productItem.Images,
|
||||
Number: num,
|
||||
})
|
||||
}
|
||||
|
||||
return l.ok(ret)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user