feat: 易支付积分充值 + 站内公告 + OpenAI 视频修复 + grok/adobe 失败处理

充值/订单(易支付 mapi):
- 订单表 + 30 分钟自动取消;支付弹窗(二维码/跳转监控、倒计时、轮询、5s 倒计时关闭)
- 系统设置可配:开关/商户ID/密钥/支付地址(根地址拼 /mapi)/支付方式/最低额/积分比例(默认 1元=100积分)
- 异步通知 MD5 验签、幂等到账;用户累计充值;前台/后台订单页(筛选+搜索+分页,前后台分风格);用户管理累计充值列

站内公告:
- Markdown 公告,登录用户首次访问/刷新弹出;内容哈希做版本,改了就重新推;管理员不弹;空内容=下线

OpenAI 视频(/v1/videos)修复:
- /content 拿不到视频:grok 资源 URL 需鉴权,改为用生成账号 token 取流;adobe/runway 公开 URL 直代理(不存 RustFS)
- size→分辨率用短边判定(1280x720 = 720p,之前误判 1080p 被拒)

失败处理:
- grok 429「Too many requests」/403 anti-bot 改判临时错误(不再误封号),真额度耗尽才算 quota
- adobe 视频 408 / system under load 归为临时错误 → tempAsDead 封号

其它:
- 充值默认关闭;签到格子浅色可见;登录验证码按钮浅色可读;并发/账户信息展示
- 创作记录/画图台只显示画图台作品(排除 API);日志页 API 视频预览显示 —
- 视频去画中画/下载/投屏(全局);图片缩略图改背景图规避 Edge 视觉搜索
- 订单/兑换码/配置/日志菜单文案与图标;充值版块样式

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 01:32:33 +08:00
co-authored by Claude Opus 4.8
parent 5cf6206ee9
commit 8ec4562f81
39 changed files with 2237 additions and 68 deletions
@@ -182,6 +182,7 @@ func userPublic(user model.User) gin.H {
"status": user.Status,
"credits": user.Credits,
"notes": user.Notes,
"recharge_total": user.RechargeTotal,
"concurrency_group_id": user.ConcurrencyGroupID,
"created_at": unixSec(user.CreatedAt),
"last_login_at": unixSecPtr(user.LastLoginAt),
@@ -0,0 +1,65 @@
package handler
import (
"net/http"
"backend/internal/service"
"github.com/gin-gonic/gin"
)
type AnnouncementHandler struct {
svc *service.AnnouncementService
}
func NewAnnouncementHandler(svc *service.AnnouncementService) *AnnouncementHandler {
return &AnnouncementHandler{svc: svc}
}
// Get — logged-in user: the current announcement + whether THIS user has seen it.
func (h *AnnouncementHandler) Get(c *gin.Context) {
user := currentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"detail": "未登录或会话已过期"})
return
}
c.JSON(http.StatusOK, h.svc.ForUser(c.Request.Context(), user))
}
// MarkSeen — user dismissed the announcement of the given version.
func (h *AnnouncementHandler) MarkSeen(c *gin.Context) {
user := currentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"detail": "未登录或会话已过期"})
return
}
var body struct {
Version string `json:"version"`
}
_ = c.ShouldBindJSON(&body)
if err := h.svc.MarkSeen(c.Request.Context(), user.ID, body.Version); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to save"})
return
}
c.JSON(http.StatusOK, gin.H{"ok": true})
}
// AdminGet — admin editor: the raw markdown.
func (h *AnnouncementHandler) AdminGet(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"content": h.svc.Content(c.Request.Context())})
}
// AdminPut — admin saves new markdown (re-pops for everyone who hasn't seen it).
func (h *AnnouncementHandler) AdminPut(c *gin.Context) {
var body struct {
Content string `json:"content"`
}
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "invalid request body"})
return
}
if err := h.svc.Save(c.Request.Context(), body.Content); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to save"})
return
}
c.JSON(http.StatusOK, gin.H{"ok": true})
}
+190
View File
@@ -0,0 +1,190 @@
package handler
import (
"errors"
"net/http"
"strings"
"time"
"backend/internal/model"
"backend/internal/service"
"github.com/gin-gonic/gin"
)
type PaymentHandler struct {
pay *service.PaymentService
}
func NewPaymentHandler(pay *service.PaymentService) *PaymentHandler {
return &PaymentHandler{pay: pay}
}
func orderJSON(o *model.Order) gin.H {
h := gin.H{
"id": o.ID,
"amount": o.Amount,
"points": o.Points,
"pay_type": o.PayType,
"status": o.Status,
"pay_info": o.PayInfo,
"pay_info_type": o.PayInfoType,
"created_at": o.CreatedAt.Unix(),
"expires_at": o.ExpiresAt.Unix(),
"server_now": time.Now().Unix(), // lets the popup count down on server time
}
if o.PaidAt != nil {
h["paid_at"] = o.PaidAt.Unix()
}
return h
}
// ---- user ----
// Config returns the recharge config for the user UI (enabled, methods, min, ratio).
func (h *PaymentHandler) Config(c *gin.Context) {
c.JSON(http.StatusOK, h.pay.Public(c.Request.Context()))
}
func (h *PaymentHandler) Recharge(c *gin.Context) {
user := currentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"detail": "未登录或会话已过期"})
return
}
var body struct {
Amount float64 `json:"amount"`
Method string `json:"method"`
}
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "invalid request body"})
return
}
order, err := h.pay.CreateOrder(c.Request.Context(), user, body.Amount, body.Method, requestBaseURL(c), clientIP(c))
if err != nil {
h.writeErr(c, err)
return
}
c.JSON(http.StatusOK, orderJSON(order))
}
func (h *PaymentHandler) MyOrders(c *gin.Context) {
user := currentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"detail": "未登录或会话已过期"})
return
}
limit := parseInt(c.Query("limit"), 20)
offset := parseInt(c.Query("offset"), 0)
orders, total, err := h.pay.ListByUser(c.Request.Context(), user.ID, c.Query("status"), limit, offset)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load orders"})
return
}
out := make([]gin.H, 0, len(orders))
for i := range orders {
out = append(out, orderJSON(&orders[i]))
}
c.JSON(http.StatusOK, gin.H{"data": out, "total": total})
}
func (h *PaymentHandler) OrderStatus(c *gin.Context) {
user := currentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"detail": "未登录或会话已过期"})
return
}
order, err := h.pay.GetForUser(c.Request.Context(), user.ID, c.Param("id"))
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"detail": "订单不存在"})
return
}
c.JSON(http.StatusOK, orderJSON(order))
}
func (h *PaymentHandler) ContinueOrder(c *gin.Context) {
user := currentUser(c)
if user == nil {
c.JSON(http.StatusUnauthorized, gin.H{"detail": "未登录或会话已过期"})
return
}
order, err := h.pay.Continue(c.Request.Context(), user, c.Param("id"), requestBaseURL(c), clientIP(c))
if err != nil {
h.writeErr(c, err)
return
}
c.JSON(http.StatusOK, orderJSON(order))
}
// ---- admin ----
func (h *PaymentHandler) AdminOrders(c *gin.Context) {
status := c.Query("status")
limit := parseInt(c.Query("limit"), 100)
offset := parseInt(c.Query("offset"), 0)
orders, total, err := h.pay.ListAll(c.Request.Context(), status, limit, offset)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load orders"})
return
}
names := h.pay.UserNames(c.Request.Context())
out := make([]gin.H, 0, len(orders))
for i := range orders {
row := orderJSON(&orders[i])
row["user_name"] = names[orders[i].UserID]
out = append(out, row)
}
c.JSON(http.StatusOK, gin.H{"data": out, "total": total})
}
func (h *PaymentHandler) SettingsGet(c *gin.Context) {
c.JSON(http.StatusOK, h.pay.Settings(c.Request.Context()))
}
func (h *PaymentHandler) SettingsSave(c *gin.Context) {
var in service.PaySettings
if err := c.ShouldBindJSON(&in); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": "invalid request body"})
return
}
if err := h.pay.SaveSettings(c.Request.Context(), in); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"detail": strings.TrimSpace(err.Error())})
return
}
c.JSON(http.StatusOK, gin.H{"ok": true})
}
// ---- public async notify (no auth — called by the 易支付 server) ----
func (h *PaymentHandler) Notify(c *gin.Context) {
params := map[string]string{}
for k, v := range c.Request.URL.Query() {
if len(v) > 0 {
params[k] = v[0]
}
}
if _, err := h.pay.HandleNotify(c.Request.Context(), params); err != nil {
c.String(http.StatusOK, "fail")
return
}
// 易支付 expects the literal string "success" to stop re-notifying.
c.String(http.StatusOK, "success")
}
func (h *PaymentHandler) writeErr(c *gin.Context, err error) {
switch {
case errors.Is(err, service.ErrPayDisabled):
c.JSON(http.StatusForbidden, gin.H{"detail": "充值已关闭"})
case errors.Is(err, service.ErrPayNotConfig):
c.JSON(http.StatusServiceUnavailable, gin.H{"detail": "支付未配置"})
case errors.Is(err, service.ErrPayMethod):
c.JSON(http.StatusBadRequest, gin.H{"detail": "不支持的支付方式"})
case errors.Is(err, service.ErrPayAmount):
c.JSON(http.StatusBadRequest, gin.H{"detail": "金额低于最低充值额"})
case errors.Is(err, service.ErrOrderNotFound):
c.JSON(http.StatusNotFound, gin.H{"detail": "订单不存在"})
case errors.Is(err, service.ErrOrderPaid):
c.JSON(http.StatusBadRequest, gin.H{"detail": "订单已支付"})
default:
c.JSON(http.StatusBadGateway, gin.H{"detail": strings.TrimSpace(err.Error())})
}
}
+3 -5
View File
@@ -259,12 +259,10 @@ func videoSizeToInternal(size string) (ratio, resolution string) {
if w == 0 || h == 0 {
return "16:9", "720p"
}
long := w
if h > long {
long = h
}
// The "p" resolution is the SHORT edge (720p = 1280×720, 1080p = 1920×1080),
// so a standard 1280×720 must read as 720p — not 1080p off the long edge.
resolution = "720p"
if long >= 1080 {
if min(w, h) >= 1080 {
resolution = "1080p"
}
return guessRatioWH(w, h), resolution
+17
View File
@@ -26,6 +26,8 @@ type Handlers struct {
UserGen *handler.UserGenerationHandler
ProviderAdmin *handler.ProviderAdminHandler
ConcGroups *handler.ConcurrencyGroupHandler
Announcement *handler.AnnouncementHandler
Payment *handler.PaymentHandler
}
func New(cfg *config.Config, auth *service.AuthService, handlers Handlers) *gin.Engine {
@@ -62,6 +64,9 @@ func New(cfg *config.Config, auth *service.AuthService, handlers Handlers) *gin.
publicAdmin.GET("/video-presets", handlers.UserGen.VideoPresets)
publicAdmin.GET("/catalog", handlers.UserGen.Catalog)
publicAdmin.GET("/models", handlers.UserGen.Models)
// 易支付 async notify — called server-to-server by the pay platform, no auth.
publicAdmin.GET("/pay/notify", handlers.Payment.Notify)
publicAdmin.POST("/pay/notify", handlers.Payment.Notify)
}
authGroup := engine.Group("/admin/api/auth")
@@ -82,6 +87,13 @@ func New(cfg *config.Config, auth *service.AuthService, handlers Handlers) *gin.
userAuthed.POST("/test", handlers.UserGen.Test)
userAuthed.GET("/jobs/mine", handlers.UserGen.MyJobs)
userAuthed.GET("/my-images", handlers.UserGen.MyImages)
userAuthed.GET("/announcement", handlers.Announcement.Get)
userAuthed.POST("/announcement/seen", handlers.Announcement.MarkSeen)
userAuthed.GET("/pay/config", handlers.Payment.Config)
userAuthed.POST("/pay/recharge", handlers.Payment.Recharge)
userAuthed.GET("/pay/orders", handlers.Payment.MyOrders)
userAuthed.GET("/pay/orders/:id", handlers.Payment.OrderStatus)
userAuthed.POST("/pay/orders/:id/continue", handlers.Payment.ContinueOrder)
}
authed := engine.Group("/admin/api")
@@ -102,6 +114,7 @@ func New(cfg *config.Config, auth *service.AuthService, handlers Handlers) *gin.
authed.PATCH("/concurrency-groups/:id", handlers.ConcGroups.Update)
authed.POST("/concurrency-groups/:id/default", handlers.ConcGroups.SetDefault)
authed.DELETE("/concurrency-groups/:id", handlers.ConcGroups.Delete)
authed.GET("/pay/admin/orders", handlers.Payment.AdminOrders)
authed.GET("/cdks", handlers.CDK.List)
authed.POST("/cdks", handlers.CDK.Create)
authed.POST("/cdks/delete-bulk", handlers.CDK.DeleteBulk)
@@ -158,6 +171,10 @@ func New(cfg *config.Config, auth *service.AuthService, handlers Handlers) *gin.
settings.PUT("/logs", handlers.AppSettings.LogsPut)
settings.GET("/media", handlers.AppSettings.MediaGet)
settings.PUT("/media", handlers.AppSettings.MediaPut)
settings.GET("/announcement", handlers.Announcement.AdminGet)
settings.PUT("/announcement", handlers.Announcement.AdminPut)
settings.GET("/pay", handlers.Payment.SettingsGet)
settings.PUT("/pay", handlers.Payment.SettingsSave)
}
}