fix(statistics): add mock data for revenue and user statistics in demo mode
This commit is contained in:
@@ -2,6 +2,8 @@ package console
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
@@ -17,7 +19,7 @@ type QueryRevenueStatisticsLogic struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Query revenue statistics
|
||||
// NewQueryRevenueStatisticsLogic Query revenue statistics
|
||||
func NewQueryRevenueStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryRevenueStatisticsLogic {
|
||||
return &QueryRevenueStatisticsLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
@@ -27,6 +29,9 @@ func NewQueryRevenueStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||
}
|
||||
|
||||
func (l *QueryRevenueStatisticsLogic) QueryRevenueStatistics() (resp *types.RevenueStatisticsResponse, err error) {
|
||||
if strings.ToLower(os.Getenv("PPANEL_MODE")) == "demo" {
|
||||
return l.mockRevenueStatistics(), nil
|
||||
}
|
||||
|
||||
var today, monthly, all types.OrdersStatistics
|
||||
now := time.Now()
|
||||
@@ -75,3 +80,54 @@ func (l *QueryRevenueStatisticsLogic) QueryRevenueStatistics() (resp *types.Reve
|
||||
All: all,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// mockRevenueStatistics is a mock function to simulate revenue statistics data.
|
||||
func (l *QueryRevenueStatisticsLogic) mockRevenueStatistics() *types.RevenueStatisticsResponse {
|
||||
now := time.Now()
|
||||
|
||||
// Generate daily data for the past 7 days (oldest first)
|
||||
monthlyList := make([]types.OrdersStatistics, 7)
|
||||
for i := 0; i < 7; i++ {
|
||||
dayDate := now.AddDate(0, 0, -(6 - i))
|
||||
baseAmount := int64(25000 + ((6 - i) * 3000) + ((6-i)%3)*8000)
|
||||
monthlyList[i] = types.OrdersStatistics{
|
||||
Date: dayDate.Format("2006-01-02"),
|
||||
AmountTotal: baseAmount,
|
||||
NewOrderAmount: int64(float64(baseAmount) * 0.68),
|
||||
RenewalOrderAmount: int64(float64(baseAmount) * 0.32),
|
||||
}
|
||||
}
|
||||
|
||||
// Generate monthly data for the past 6 months (oldest first)
|
||||
allList := make([]types.OrdersStatistics, 6)
|
||||
for i := 0; i < 6; i++ {
|
||||
monthDate := now.AddDate(0, -(5 - i), 0)
|
||||
baseAmount := int64(1800000 + ((5 - i) * 200000) + ((5-i)%2)*500000)
|
||||
allList[i] = types.OrdersStatistics{
|
||||
Date: monthDate.Format("2006-01"),
|
||||
AmountTotal: baseAmount,
|
||||
NewOrderAmount: int64(float64(baseAmount) * 0.68),
|
||||
RenewalOrderAmount: int64(float64(baseAmount) * 0.32),
|
||||
}
|
||||
}
|
||||
|
||||
return &types.RevenueStatisticsResponse{
|
||||
Today: types.OrdersStatistics{
|
||||
AmountTotal: 35888,
|
||||
NewOrderAmount: 22888,
|
||||
RenewalOrderAmount: 13000,
|
||||
},
|
||||
Monthly: types.OrdersStatistics{
|
||||
AmountTotal: 888888,
|
||||
NewOrderAmount: 588888,
|
||||
RenewalOrderAmount: 300000,
|
||||
List: monthlyList,
|
||||
},
|
||||
All: types.OrdersStatistics{
|
||||
AmountTotal: 12888888,
|
||||
NewOrderAmount: 8588888,
|
||||
RenewalOrderAmount: 4300000,
|
||||
List: allList,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user