临时提交
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
"xboard-go/internal/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func AdminDashboardSummary(c *gin.Context) {
|
||||
@@ -859,3 +861,77 @@ func planName(plan *model.Plan) string {
|
||||
}
|
||||
return plan.Name
|
||||
}
|
||||
|
||||
func AdminUserBatchGenerate(c *gin.Context) {
|
||||
var payload struct {
|
||||
Count int `json:"count"`
|
||||
PlanID int `json:"plan_id"`
|
||||
Expire int64 `json:"expire"`
|
||||
Group int `json:"group_id"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&payload); err != nil || payload.Count <= 0 {
|
||||
Fail(c, http.StatusBadRequest, "invalid parameters")
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
for i := 0; i < payload.Count; i++ {
|
||||
email := fmt.Sprintf("u_%d_%d@generated.com", now, i)
|
||||
user := model.User{
|
||||
Email: email,
|
||||
Password: service.GenerateSubscriptionToken()[:8],
|
||||
UUID: uuid.NewString(),
|
||||
Token: service.GenerateSubscriptionToken(),
|
||||
PlanID: &payload.PlanID,
|
||||
GroupID: &payload.Group,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
database.DB.Create(&user)
|
||||
}
|
||||
Success(c, true)
|
||||
}
|
||||
|
||||
func AdminUserBatchSendMail(c *gin.Context) {
|
||||
var payload struct {
|
||||
IDs []int `json:"ids"`
|
||||
Subject string `json:"subject"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||
Fail(c, http.StatusBadRequest, "invalid request body")
|
||||
return
|
||||
}
|
||||
|
||||
var users []model.User
|
||||
database.DB.Select("email").Where("id IN ?", payload.IDs).Find(&users)
|
||||
|
||||
emails := make([]string, 0, len(users))
|
||||
for _, u := range users {
|
||||
emails = append(emails, u.Email)
|
||||
}
|
||||
|
||||
if len(emails) > 0 {
|
||||
service.SendMailWithCurrentSettings(service.EmailMessage{
|
||||
To: emails,
|
||||
Subject: payload.Subject,
|
||||
TextBody: payload.Content,
|
||||
})
|
||||
}
|
||||
Success(c, true)
|
||||
}
|
||||
|
||||
func AdminUserBatchDelete(c *gin.Context) {
|
||||
var payload struct {
|
||||
IDs []int `json:"ids"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&payload); err != nil {
|
||||
Fail(c, http.StatusBadRequest, "invalid request body")
|
||||
return
|
||||
}
|
||||
if err := database.DB.Where("id IN ?", payload.IDs).Delete(&model.User{}).Error; err != nil {
|
||||
Fail(c, http.StatusInternalServerError, "batch delete failed")
|
||||
return
|
||||
}
|
||||
Success(c, true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user