fix: align revenue statistics with order type
This commit is contained in:
@@ -162,8 +162,8 @@ func (m *customOrderModel) QueryMonthlyOrders(ctx context.Context, date time.Tim
|
||||
Where("status IN ? AND created_at BETWEEN ? AND ? AND method != ?", []int64{2, 5}, firstDay, lastDay, "balance").
|
||||
Select(
|
||||
"SUM(amount) as amount_total, " +
|
||||
"SUM(CASE WHEN is_new = 1 THEN amount ELSE 0 END) as new_order_amount, " +
|
||||
"SUM(CASE WHEN is_new = 0 THEN amount ELSE 0 END) as renewal_order_amount",
|
||||
"SUM(CASE WHEN type = 1 THEN amount ELSE 0 END) as new_order_amount, " +
|
||||
"SUM(CASE WHEN type = 2 THEN amount ELSE 0 END) as renewal_order_amount",
|
||||
).
|
||||
Scan(v).Error
|
||||
})
|
||||
@@ -179,8 +179,8 @@ func (m *customOrderModel) QueryDateOrders(ctx context.Context, date time.Time)
|
||||
Where("status IN ? AND DATE_FORMAT(created_at, '%Y-%m-%d') = ? AND method != ?", []int64{2, 5}, dateStr, "balance").
|
||||
Select(
|
||||
"SUM(amount) as amount_total, " +
|
||||
"SUM(CASE WHEN is_new = 1 THEN amount ELSE 0 END) as new_order_amount, " +
|
||||
"SUM(CASE WHEN is_new = 0 THEN amount ELSE 0 END) as renewal_order_amount",
|
||||
"SUM(CASE WHEN type = 1 THEN amount ELSE 0 END) as new_order_amount, " +
|
||||
"SUM(CASE WHEN type = 2 THEN amount ELSE 0 END) as renewal_order_amount",
|
||||
).
|
||||
Scan(v).Error
|
||||
})
|
||||
@@ -194,8 +194,8 @@ func (m *customOrderModel) QueryTotalOrders(ctx context.Context) (OrdersTotal, e
|
||||
return conn.Model(&Order{}).
|
||||
Select(`
|
||||
SUM(amount) AS amount_total,
|
||||
SUM(CASE WHEN is_new = 1 THEN amount ELSE 0 END) AS new_order_amount,
|
||||
SUM(CASE WHEN is_new = 0 THEN amount ELSE 0 END) AS renewal_order_amount
|
||||
SUM(CASE WHEN type = 1 THEN amount ELSE 0 END) AS new_order_amount,
|
||||
SUM(CASE WHEN type = 2 THEN amount ELSE 0 END) AS renewal_order_amount
|
||||
`).
|
||||
Where("status IN ? AND method != ?", []int64{2, 5}, "balance").
|
||||
Scan(&result).Error
|
||||
@@ -216,8 +216,8 @@ func (m *customOrderModel) QueryMonthlyUserCounts(ctx context.Context, date time
|
||||
err := m.QueryNoCacheCtx(ctx, nil, func(conn *gorm.DB, _ interface{}) error {
|
||||
return conn.Model(&Order{}).
|
||||
Select(`
|
||||
COUNT(DISTINCT CASE WHEN is_new = 1 THEN user_id END) AS new_users,
|
||||
COUNT(DISTINCT CASE WHEN is_new = 0 THEN user_id END) AS renewal_users
|
||||
COUNT(DISTINCT CASE WHEN type = 1 THEN user_id END) AS new_users,
|
||||
COUNT(DISTINCT CASE WHEN type = 2 THEN user_id END) AS renewal_users
|
||||
`).
|
||||
Where("status IN ? AND created_at >= ? AND created_at < ? AND method != ?",
|
||||
[]int64{2, 5}, firstDay, nextMonth, "balance").
|
||||
@@ -234,8 +234,8 @@ func (m *customOrderModel) QueryDateUserCounts(ctx context.Context, date time.Ti
|
||||
err := m.QueryNoCacheCtx(ctx, nil, func(conn *gorm.DB, _ interface{}) error {
|
||||
return conn.Model(&Order{}).
|
||||
Select(`
|
||||
COUNT(DISTINCT CASE WHEN is_new = 1 THEN user_id END) AS new_users,
|
||||
COUNT(DISTINCT CASE WHEN is_new = 0 THEN user_id END) AS renewal_users
|
||||
COUNT(DISTINCT CASE WHEN type = 1 THEN user_id END) AS new_users,
|
||||
COUNT(DISTINCT CASE WHEN type = 2 THEN user_id END) AS renewal_users
|
||||
`).
|
||||
Where("status IN ? AND DATE_FORMAT(created_at, '%Y-%m-%d') = ? AND method != ?",
|
||||
[]int64{2, 5}, dateStr, "balance").
|
||||
@@ -251,8 +251,8 @@ func (m *customOrderModel) QueryTotalUserCounts(ctx context.Context) (int64, int
|
||||
return conn.Model(&Order{}).
|
||||
Where("status IN ? AND method != ?", []int64{2, 5}, "balance").
|
||||
Select(`
|
||||
COUNT(DISTINCT CASE WHEN is_new = 1 THEN user_id END) AS new_users,
|
||||
COUNT(DISTINCT CASE WHEN is_new = 0 THEN user_id END) AS renewal_users
|
||||
COUNT(DISTINCT CASE WHEN type = 1 THEN user_id END) AS new_users,
|
||||
COUNT(DISTINCT CASE WHEN type = 2 THEN user_id END) AS renewal_users
|
||||
`).
|
||||
Scan(&counts).Error
|
||||
})
|
||||
@@ -284,8 +284,8 @@ func (m *customOrderModel) QueryDailyOrdersList(ctx context.Context, date time.T
|
||||
Select(`
|
||||
DATE_FORMAT(created_at, '%Y-%m-%d') AS date,
|
||||
SUM(amount) AS amount_total,
|
||||
SUM(CASE WHEN is_new = 1 THEN amount ELSE 0 END) AS new_order_amount,
|
||||
SUM(CASE WHEN is_new = 0 THEN amount ELSE 0 END) AS renewal_order_amount
|
||||
SUM(CASE WHEN type = 1 THEN amount ELSE 0 END) AS new_order_amount,
|
||||
SUM(CASE WHEN type = 2 THEN amount ELSE 0 END) AS renewal_order_amount
|
||||
`).
|
||||
Where("status IN ? AND created_at >= ? AND created_at < ? AND method != ?",
|
||||
[]int64{2, 5}, firstDay, nextDay, "balance").
|
||||
@@ -328,8 +328,8 @@ func (m *customOrderModel) QueryMonthlyOrdersList(ctx context.Context, date time
|
||||
Select(`
|
||||
DATE_FORMAT(created_at, '%Y-%m') AS date,
|
||||
SUM(amount) AS amount_total,
|
||||
SUM(CASE WHEN is_new = 1 THEN amount ELSE 0 END) AS new_order_amount,
|
||||
SUM(CASE WHEN is_new = 0 THEN amount ELSE 0 END) AS renewal_order_amount
|
||||
SUM(CASE WHEN type = 1 THEN amount ELSE 0 END) AS new_order_amount,
|
||||
SUM(CASE WHEN type = 2 THEN amount ELSE 0 END) AS renewal_order_amount
|
||||
`).
|
||||
Where("status IN ? AND created_at >= ? AND created_at < ? AND method != ?",
|
||||
[]int64{2, 5}, start, end, "balance").
|
||||
|
||||
Reference in New Issue
Block a user