diff --git a/server/order/internal/logic/orderdetaillogic.go b/server/order/internal/logic/orderdetaillogic.go index b4b2aef9..cd974870 100644 --- a/server/order/internal/logic/orderdetaillogic.go +++ b/server/order/internal/logic/orderdetaillogic.go @@ -47,7 +47,7 @@ func (l *OrderDetailLogic) OrderDetail(req *types.OrderDetailReq, userinfo *auth } return resp.SetStatus(basic.CodeOK, map[string]interface{}{ - "order_detail": res, + "order_detail": res.OrderDetail, }) } diff --git a/service/repositories/order.go b/service/repositories/order.go index ae3d44b8..b6afc6ae 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -63,6 +63,7 @@ type ( OrderSn string `json:"order_sn"` } DetailRes struct { + OrderDetail gmodel.OrderDetail } /* 详情 */ ) @@ -72,10 +73,16 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe var order gmodel.FsOrder result := d.MysqlConn.Where("order_sn = ?", in.OrderSn).Where("user_id = ?", in.UserId).Take(&order) if result.Error != nil { + logx.Errorf("detail failed, err: %v", err) return nil, result.Error } - d.OrderDetailHandler(ctx, &order) - return &DetailRes{}, nil + ress, err := d.OrderDetailHandler(ctx, &order) + if err != nil { + return nil, err + } + return &DetailRes{ + ress.OrderDetail, + }, nil } func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder) (res *DetailRes, err error) { @@ -83,17 +90,23 @@ func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel err = json.Unmarshal(*orderInfo.Metadata, &orderDetail) if err != nil { - logx.Errorf("create handler unmarshal metadata failed, err: %v", err) + logx.Errorf("detail handler unmarshal metadata failed, err: %v", err) return nil, err } - for _, orderProduct := range orderDetail.OrderProduct { - orderProduct.TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) - orderProduct.ItemPrice = order.GetAmountInfoFormat(&orderProduct.ItemPrice) - orderProduct.ShoppingCartSnapshot = nil + for orderProductKey, orderProduct := range orderDetail.OrderProduct { + orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) + orderDetail.OrderProduct[orderProductKey].ItemPrice = order.GetAmountInfoFormat(&orderProduct.ItemPrice) + orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot = nil + orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil } orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink) orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount) - return nil, nil + orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.RemainingBalance.PayAmount) + orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal) + orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total) + return &DetailRes{ + OrderDetail: orderDetail, + }, nil } // 下单 diff --git a/utils/format/price.go b/utils/format/price.go index 6627e8aa..9af4a35e 100644 --- a/utils/format/price.go +++ b/utils/format/price.go @@ -18,7 +18,7 @@ func CentitoDollar(price int64, remainFloatPoint ...uint) float64 { } // 厘转美元 -func CentitoDollarStr(price int64) string { +func CentitoDollarStr(price float64) string { s := "%.2f" - return fmt.Sprintf(s, float64(price)/float64(1000)) + return fmt.Sprintf(s, price/float64(1000)) } diff --git a/utils/order/order.go b/utils/order/order.go index 022fcd6a..60c25905 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -91,9 +91,9 @@ type GetAmountCurrencyUSDReq struct { // 处理金额(元) func GetAmountCurrencyFormat(req *gmodel.AmountCurrency) (res gmodel.AmountCurrency) { return gmodel.AmountCurrency{ - ExchangeRate: format.CentitoDollarStr(req.ExchangeRate.(int64)), - CurrentAmount: format.CentitoDollarStr(req.CurrentAmount.(int64)), - OriginalAmount: format.CentitoDollarStr(req.OriginalAmount.(int64)), + ExchangeRate: format.CentitoDollarStr(req.ExchangeRate.(float64)), + CurrentAmount: format.CentitoDollarStr(req.CurrentAmount.(float64)), + OriginalAmount: format.CentitoDollarStr(req.OriginalAmount.(float64)), CurrentCurrency: req.CurrentCurrency, OriginalCurrency: req.OriginalCurrency, } @@ -101,6 +101,8 @@ func GetAmountCurrencyFormat(req *gmodel.AmountCurrency) (res gmodel.AmountCurre // 处理金额(元) func GetAmountInfoFormat(req *gmodel.AmountInfo) gmodel.AmountInfo { + Current := GetAmountCurrencyFormat(&req.Current) + fmt.Println(Current) return gmodel.AmountInfo{ Change: GetAmountCurrencyFormat(&req.Change), ChangeRemark: req.ChangeRemark,