fix: 修复仪表盘时区统计偏移、重复订阅、新增map_apple字段
Build docker and publish / build (20.15.1) (push) Successful in 5m23s
Build docker and publish / build (20.15.1) (push) Successful in 5m23s
- fix(order/model): QueryDateOrders/QueryDailyOrdersList 使用 time.Date 替代 Truncate 修复 UTC+8 时区偏移 - fix(user/model): QueryResisterUserTotalByDate 同样修复时区截断 - fix(traffic/model): QueryServerTrafficByDay 同样修复时区截断 - fix(activateOrder): 兜底查询防止过期用户重购产生重复订阅 - feat(api): SubscribeDiscount 新增 map_apple 字段
This commit is contained in:
@@ -166,8 +166,8 @@ func (m *customOrderModel) QueryMonthlyOrders(ctx context.Context, date time.Tim
|
||||
|
||||
// QueryDateOrders Query orders by date
|
||||
func (m *customOrderModel) QueryDateOrders(ctx context.Context, date time.Time) (OrdersTotal, error) {
|
||||
start := date.Truncate(24 * time.Hour)
|
||||
end := start.Add(24 * time.Hour).Add(-time.Nanosecond)
|
||||
start := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
|
||||
end := start.AddDate(0, 0, 1).Add(-time.Nanosecond)
|
||||
var result OrdersTotal
|
||||
err := m.QueryNoCacheCtx(ctx, &result, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&Order{}).
|
||||
@@ -276,7 +276,7 @@ func (m *customOrderModel) QueryDailyOrdersList(ctx context.Context, date time.T
|
||||
// 当月 1 号 00:00:00
|
||||
firstDay := time.Date(date.Year(), date.Month(), 1, 0, 0, 0, 0, date.Location())
|
||||
// 第二天 00:00:00
|
||||
nextDay := date.AddDate(0, 0, 1).Truncate(24 * time.Hour)
|
||||
nextDay := time.Date(date.Year(), date.Month(), date.Day()+1, 0, 0, 0, 0, date.Location())
|
||||
|
||||
return conn.Model(&Order{}).
|
||||
Select(`
|
||||
|
||||
@@ -27,8 +27,8 @@ func NewModel(conn *gorm.DB) Model {
|
||||
|
||||
func (m *customTrafficModel) QueryServerTrafficByDay(ctx context.Context, serverId int64, date time.Time) (*TotalTraffic, error) {
|
||||
var data TotalTraffic
|
||||
start := date.Truncate(24 * time.Hour)
|
||||
end := start.Add(24 * time.Hour).Add(-time.Nanosecond)
|
||||
start := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
|
||||
end := start.AddDate(0, 0, 1).Add(-time.Nanosecond)
|
||||
err := m.Conn.WithContext(ctx).Model(&TrafficLog{}).
|
||||
Select("sum(download) as download, sum(upload) as upload").
|
||||
Where("server_id = ? AND timestamp BETWEEN ? AND ?", serverId, start, end).
|
||||
|
||||
@@ -314,8 +314,8 @@ func (m *customUserModel) UpdateUserSubscribeWithTraffic(ctx context.Context, id
|
||||
|
||||
func (m *customUserModel) QueryResisterUserTotalByDate(ctx context.Context, date time.Time) (int64, error) {
|
||||
var total int64
|
||||
start := date.Truncate(24 * time.Hour)
|
||||
end := start.Add(24 * time.Hour).Add(-time.Second)
|
||||
start := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
|
||||
end := start.AddDate(0, 0, 1).Add(-time.Second)
|
||||
err := m.QueryNoCacheCtx(ctx, &total, func(conn *gorm.DB, v interface{}) error {
|
||||
return conn.Model(&User{}).Where("created_at > ? and created_at < ?", start, end).Count(&total).Error
|
||||
})
|
||||
|
||||
@@ -2655,6 +2655,7 @@ type SubscribeDiscount struct {
|
||||
Quantity int64 `json:"quantity"`
|
||||
Discount float64 `json:"discount"`
|
||||
NewUserOnly bool `json:"new_user_only"`
|
||||
MapApple string `json:"map_apple"`
|
||||
}
|
||||
|
||||
type SubscribeGroup struct {
|
||||
|
||||
Reference in New Issue
Block a user