feat(marketing): 新增营销图管理模块

- 新增 marketing 模块:model/repository/service/handler 四层架构
- 数据模型:marketing_categories、marketing_templates、marketing_user_downloads
- 小程序端接口:分类列表、模板列表/详情、下载记录、广告回调
- 管理后台接口:分类/模板 CRUD、下载统计(X-Admin-Token 鉴权)
- 路由注册:接入现有 AuthMiddleware,新增 AdminTokenMiddleware
- Web 管理后台:单页面 Vue3 + Element Plus(分类管理、模板管理、数据概览)

Closes #37, #38, #39, #40

Made-with: Cursor
This commit is contained in:
nepiedg
2026-03-06 07:36:05 +00:00
parent 5f492929df
commit ac49e1458c
17 changed files with 1599 additions and 1 deletions
@@ -0,0 +1,87 @@
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"wx_service/internal/marketing/service"
"wx_service/internal/middleware"
"wx_service/internal/model"
)
type DownloadHandler struct {
svc *service.DownloadService
}
func NewDownloadHandler(svc *service.DownloadService) *DownloadHandler {
return &DownloadHandler{svc: svc}
}
func (h *DownloadHandler) Create(c *gin.Context) {
user := middleware.MustCurrentUser(c)
var req service.CreateDownloadRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "请求参数错误"))
return
}
dl, err := h.svc.Create(user.ID, req)
if err != nil {
if service.IsBadRequestError(err) {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, err.Error()))
return
}
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "服务器错误"))
return
}
c.JSON(http.StatusOK, model.Success(dl))
}
type adCallbackRequest struct {
DownloadID uint `json:"download_id" binding:"required"`
}
func (h *DownloadHandler) AdCallback(c *gin.Context) {
var req adCallbackRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, model.Error(http.StatusBadRequest, "请求参数错误"))
return
}
if err := h.svc.MarkAdCompleted(req.DownloadID); err != nil {
if service.IsNotFoundError(err) {
c.JSON(http.StatusNotFound, model.Error(http.StatusNotFound, "记录不存在"))
return
}
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "服务器错误"))
return
}
c.JSON(http.StatusOK, model.Success(nil))
}
func (h *DownloadHandler) ListByUser(c *gin.Context) {
user := middleware.MustCurrentUser(c)
page := parseIntQuery(c, "page", 1)
pageSize := parseIntQuery(c, "page_size", 20)
resp, err := h.svc.ListByUser(user.ID, page, pageSize)
if err != nil {
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "服务器错误"))
return
}
c.JSON(http.StatusOK, model.Success(resp))
}
func (h *DownloadHandler) AdminStats(c *gin.Context) {
stats, err := h.svc.GetStats()
if err != nil {
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "服务器错误"))
return
}
c.JSON(http.StatusOK, model.Success(stats))
}