This commit is contained in:
sjk
2025-11-28 15:18:10 +08:00
parent ad4a600af9
commit 5683f35942
188 changed files with 53680 additions and 1062 deletions

View File

@@ -36,9 +36,16 @@ func (h *CartHandler) GetCart(c *gin.Context) {
return
}
// 计算购物车统计信息
count, _ := h.cartService.GetCartCount(userID.(uint))
total, _ := h.cartService.GetCartTotal(userID.(uint))
// 优化: 在一次查询结果基础上计算统计信息,避免重复查询
var count int
var total float64
for _, item := range cart {
count += item.Quantity
if item.Product.ID != 0 {
// 将价格从分转换为元
total += (float64(item.Product.Price) / 100) * float64(item.Quantity)
}
}
result := map[string]interface{}{
"items": cart,