Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-09-21 18:36:50 +08:00
commit f2fc0a35f6
3 changed files with 14 additions and 4 deletions

View File

@ -130,7 +130,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
calculateResultList = append(calculateResultList, types.CalculateResultItem{ calculateResultList = append(calculateResultList, types.CalculateResultItem{
CartId: cart.Id, CartId: cart.Id,
ItemPrice: format.CentitoDollar(itemPrice, 3), ItemPrice: format.CentitoDollar(itemPrice, 3),
TotalPrice: format.CentitoDollar(totalPrice, 2), TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
}) })
updData := &gmodel.FsShoppingCart{ updData := &gmodel.FsShoppingCart{
PurchaseQuantity: &reqPurchaseQuantity, PurchaseQuantity: &reqPurchaseQuantity,
@ -152,7 +152,7 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error()) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, err.Error())
} }
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{ return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateCartPriceRsp{
SubTotalPrice: format.CentitoDollar(subTotalPrice, 2), SubTotalPrice: format.CentitoDollarWithNoHalfAdjust(subTotalPrice, 2),
CalculateResultList: calculateResultList, CalculateResultList: calculateResultList,
}) })
} }

View File

@ -174,7 +174,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
FittingName: fittingName, FittingName: fittingName,
}, },
ItemPrice: format.CentitoDollar(itemPrice, 3), ItemPrice: format.CentitoDollar(itemPrice, 3),
TotalPrice: format.CentitoDollar(totalPrice, 2), TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
DiyInformation: types.DiyInformation{ DiyInformation: types.DiyInformation{
Phone: snapShot.UserDiyInformation.Phone, Phone: snapShot.UserDiyInformation.Phone,
Address: snapShot.UserDiyInformation.Address, Address: snapShot.UserDiyInformation.Address,

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
) )
// 厘转美元 // 厘转美元(四舍五入)
func CentitoDollar(price int64, remainFloatPoint ...uint) string { func CentitoDollar(price int64, remainFloatPoint ...uint) string {
s := "%0.3f" s := "%0.3f"
if len(remainFloatPoint) > 0 { if len(remainFloatPoint) > 0 {
@ -13,6 +13,16 @@ func CentitoDollar(price int64, remainFloatPoint ...uint) string {
return fmt.Sprintf(s, float64(price)/float64(1000)) return fmt.Sprintf(s, float64(price)/float64(1000))
} }
// 厘转美元(向下截断,舍弃掉厘)用于计算总价
func CentitoDollarWithNoHalfAdjust(price int64, remainFloatPoint ...uint) string {
s := "%0.2f"
if len(remainFloatPoint) > 0 {
s = fmt.Sprintf("%%0.%df", remainFloatPoint[0])
}
t := price / 10
return fmt.Sprintf(s, float64(t)/float64(100))
}
// 厘转美元 // 厘转美元
func CentitoDollarStr(price float64) string { func CentitoDollarStr(price float64) string {
s := "%0.2f" s := "%0.2f"