|
1 | 1 | package admin |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "chat/admin/analysis" |
4 | 5 | "chat/utils" |
5 | 6 | "net/http" |
6 | 7 | "strconv" |
@@ -48,7 +49,8 @@ type BanForm struct { |
48 | 49 | type QuotaOperationForm struct { |
49 | 50 | Id int64 `json:"id" binding:"required"` |
50 | 51 | Quota *float32 `json:"quota" binding:"required"` |
51 | | - Override bool `json:"override"`} |
| 52 | + Override bool `json:"override"` |
| 53 | +} |
52 | 54 |
|
53 | 55 | type SubscriptionOperationForm struct { |
54 | 56 | Id int64 `json:"id" binding:"required"` |
@@ -97,36 +99,39 @@ func InfoAPI(c *gin.Context) { |
97 | 99 | cache := utils.GetCacheFromContext(c) |
98 | 100 |
|
99 | 101 | c.JSON(http.StatusOK, InfoForm{ |
100 | | - SubscriptionCount: GetSubscriptionUsers(db), |
101 | | - BillingToday: GetBillingToday(cache), |
102 | | - BillingMonth: GetBillingMonth(cache), |
| 102 | + OnlineChats: utils.GetConns(), |
| 103 | + SubscriptionCount: analysis.GetSubscriptionUsers(db), |
| 104 | + BillingToday: analysis.GetBillingToday(cache), |
| 105 | + BillingMonth: analysis.GetBillingMonth(cache), |
| 106 | + BillingYesterday: analysis.GetBillingYesterday(cache), |
| 107 | + BillingLastMonth: analysis.GetBillingLastMonth(cache), |
103 | 108 | }) |
104 | 109 | } |
105 | 110 |
|
106 | 111 | func ModelAnalysisAPI(c *gin.Context) { |
107 | 112 | cache := utils.GetCacheFromContext(c) |
108 | | - c.JSON(http.StatusOK, GetSortedModelData(cache)) |
| 113 | + c.JSON(http.StatusOK, analysis.GetSortedModelData(cache)) |
109 | 114 | } |
110 | 115 |
|
111 | 116 | func RequestAnalysisAPI(c *gin.Context) { |
112 | 117 | cache := utils.GetCacheFromContext(c) |
113 | | - c.JSON(http.StatusOK, GetRequestData(cache)) |
| 118 | + c.JSON(http.StatusOK, analysis.GetRequestData(cache)) |
114 | 119 | } |
115 | 120 |
|
116 | 121 | func BillingAnalysisAPI(c *gin.Context) { |
117 | 122 | cache := utils.GetCacheFromContext(c) |
118 | | - c.JSON(http.StatusOK, GetBillingData(cache)) |
| 123 | + c.JSON(http.StatusOK, analysis.GetBillingData(cache)) |
119 | 124 | } |
120 | 125 |
|
121 | 126 | func ErrorAnalysisAPI(c *gin.Context) { |
122 | 127 | cache := utils.GetCacheFromContext(c) |
123 | | - c.JSON(http.StatusOK, GetErrorData(cache)) |
| 128 | + c.JSON(http.StatusOK, analysis.GetErrorData(cache)) |
124 | 129 | } |
125 | 130 |
|
126 | 131 | func UserTypeAnalysisAPI(c *gin.Context) { |
127 | 132 | db := utils.GetDBFromContext(c) |
128 | | - if form, err := GetUserTypeData(db); err != nil { |
129 | | - c.JSON(http.StatusOK, &UserTypeForm{}) |
| 133 | + if form, err := analysis.GetUserTypeData(db); err != nil { |
| 134 | + c.JSON(http.StatusOK, &analysis.UserTypeForm{}) |
130 | 135 | } else { |
131 | 136 | c.JSON(http.StatusOK, form) |
132 | 137 | } |
@@ -364,26 +369,26 @@ func UserSubscriptionAPI(c *gin.Context) { |
364 | 369 | return |
365 | 370 | } |
366 | 371 |
|
367 | | -// convert to time |
368 | | -if _, err := time.Parse("2006-01-02 15:04:05", form.Expired); err != nil { |
369 | | - c.JSON(http.StatusOK, gin.H{ |
370 | | - "status": false, |
371 | | - "message": err.Error(), |
372 | | - }) |
373 | | - return |
374 | | -} |
| 372 | + // convert to time |
| 373 | + if _, err := time.Parse("2006-01-02 15:04:05", form.Expired); err != nil { |
| 374 | + c.JSON(http.StatusOK, gin.H{ |
| 375 | + "status": false, |
| 376 | + "message": err.Error(), |
| 377 | + }) |
| 378 | + return |
| 379 | + } |
| 380 | + |
| 381 | + if err := subscriptionMigration(db, form.Id, form.Expired); err != nil { |
| 382 | + c.JSON(http.StatusOK, gin.H{ |
| 383 | + "status": false, |
| 384 | + "message": err.Error(), |
| 385 | + }) |
| 386 | + return |
| 387 | + } |
375 | 388 |
|
376 | | -if err := subscriptionMigration(db, form.Id, form.Expired); err != nil { |
377 | 389 | c.JSON(http.StatusOK, gin.H{ |
378 | | - "status": false, |
379 | | - "message": err.Error(), |
| 390 | + "status": true, |
380 | 391 | }) |
381 | | - return |
382 | | -} |
383 | | - |
384 | | -c.JSON(http.StatusOK, gin.H{ |
385 | | - "status": true, |
386 | | -}) |
387 | 392 | } |
388 | 393 |
|
389 | 394 | func SubscriptionLevelAPI(c *gin.Context) { |
|
0 commit comments