- 在查询订单摘要信息时添加了对大量数据的分页处理,提升性能 - 新增 GetOrderCountByMap 函数用于获取订单总数 - 更新 QueryTotalSummary 和 QueryTodaySummary 函数,支持分页查询 - 为相关函数添加了 context 参数,以便于传递请求上下文 - 优化了部分代码结构,提高可读性和可维护性
49 lines
982 B
Go
49 lines
982 B
Go
package service
|
|
|
|
import (
|
|
"boss/internal/common"
|
|
"boss/internal/models/order"
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
type OrderSummary struct {
|
|
}
|
|
|
|
func (s *OrderSummary) GetTodaySummary() (todaySummary order.Summary) {
|
|
todaySummary = order.Summary{}
|
|
|
|
now := time.Now()
|
|
// 获取今日零点
|
|
todayZero := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
|
|
orderList, err := order.GetOrderByTime(todayZero.String(), now.String())
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
amount := 0.0
|
|
paidNum := int64(0)
|
|
paidAmount := 0.0
|
|
platformIncome := 0.0
|
|
|
|
for _, info := range orderList {
|
|
amount += info.OrderAmount
|
|
// 统计成功订单
|
|
if info.Status == common.OrderStatusSuccess {
|
|
paidNum += 1
|
|
paidAmount += info.OrderAmount
|
|
}
|
|
}
|
|
|
|
todaySummary = order.Summary{
|
|
TotalNum: int64(len(orderList)),
|
|
TotalAmount: math.Round(amount*100) / 100,
|
|
PaidNum: paidNum,
|
|
PaidAmount: math.Round(paidAmount*100) / 100,
|
|
PlatformIncome: platformIncome,
|
|
}
|
|
|
|
return
|
|
}
|