This commit is contained in:
sjk
2025-11-28 15:18:10 +08:00
parent ad4a600af9
commit 5683f35942
188 changed files with 53680 additions and 1062 deletions

View File

@@ -35,6 +35,8 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
pointsRepo := repository.NewPointsRepository(db)
refundRepo := repository.NewRefundRepository(db)
commentRepo := repository.NewCommentRepository(db)
platformRepo := repository.NewPlatformRepository(db)
liveStreamRepo := repository.NewLiveStreamRepository(db)
// 初始化services
userService := service.NewUserService(db)
@@ -49,6 +51,8 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
roleService := service.NewRoleService(db)
logService := service.NewLogService(db)
commentService := service.NewCommentService(commentRepo, orderRepo, productRepo)
platformService := service.NewPlatformService(platformRepo, productRepo)
liveStreamService := service.NewLiveStreamService(liveStreamRepo)
// 初始化微信支付服务 - 使用官方SDK
var wechatPayService *service.WeChatPayService
if cfg.WeChatPay.AppID != "" && cfg.WeChatPay.MchID != "" {
@@ -133,6 +137,8 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
{
userRoutes.POST("/login", userHandler.Login) // 用户登录(兼容旧版本)
userRoutes.POST("/wechat-login", userHandler.WeChatLogin) // 微信登录
userRoutes.POST("/email-login", userHandler.EmailLogin) // 邮箱登录Web端
userRoutes.POST("/email-register", userHandler.EmailRegister) // 邮箱注册Web端
userRoutes.GET("/wechat-session", middleware.AuthMiddleware(), userHandler.GetWeChatSession) // 获取微信会话
userRoutes.POST("/register", userHandler.Register) // 用户注册
userRoutes.GET("/profile", middleware.AuthMiddleware(), userHandler.GetProfile) // 获取用户信息
@@ -166,6 +172,11 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
// 轮播图相关路由
bannerHandler := handler.NewBannerHandler(bannerService)
api.GET("/banners", bannerHandler.GetBanners) // 获取轮播图
// 直播投流源相关路由(前台)
liveStreamHandler := handler.NewLiveStreamHandler(liveStreamService)
api.GET("/livestreams", liveStreamHandler.GetActiveLiveStreams) // 获取启用的投流源
api.POST("/livestreams/:id/view", liveStreamHandler.IncrementViewCount) // 增加观看次数
// 优惠券相关路由
couponHandler := handler.NewCouponHandler(couponService)
@@ -261,7 +272,7 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
}
// 订单相关路由
orderHandler := handler.NewOrderHandler(orderService)
orderHandler := handler.NewOrderHandler(orderService, wechatPayService)
orderSettleHandler := handler.NewOrderSettleHandler(orderService, productService, userService)
orderRoutes := api.Group("/orders", middleware.AuthMiddleware())
{
@@ -271,6 +282,7 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
orderRoutes.POST("/settle", orderSettleHandler.SettleOrder) // 订单结算
orderRoutes.POST("/merge", orderHandler.MergeOrders) // 合并订单
orderRoutes.PUT("/:id/pay", orderHandler.PayOrder) // 支付订单
orderRoutes.GET("/:id/payment/status", orderHandler.GetPaymentStatus) // 获取支付状态
orderRoutes.PUT("/:id/cancel", orderHandler.CancelOrder) // 取消订单
orderRoutes.PUT("/:id/remind-ship", orderHandler.RemindShip) // 提醒发货
orderRoutes.PUT("/:id/receive", orderHandler.ConfirmReceive) // 确认收货
@@ -300,6 +312,7 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
commentRoutes := api.Group("/comments")
{
// 公开路由(无需认证)
commentRoutes.GET("/high-rating", commentHandler.GetHighRatingComments) // 获取高分评论(首页展示)
commentRoutes.GET("/products/:product_id", commentHandler.GetProductComments) // 获取商品评论列表
commentRoutes.GET("/products/:product_id/stats", commentHandler.GetCommentStats) // 获取商品评论统计
commentRoutes.GET("/:id", commentHandler.GetCommentDetail) // 获取评论详情
@@ -406,6 +419,18 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
categoryAdmin.DELETE("/:id", adminProductHandler.DeleteCategory) // 删除分类
}
// 平台管理
platformHandler := handler.NewPlatformHandler(platformService)
platformAdmin := admin.Group("/platforms")
{
platformAdmin.GET("", platformHandler.GetPlatforms) // 获取平台列表
platformAdmin.GET("/all/active", platformHandler.GetAllActivePlatforms) // 获取所有启用平台(用于下拉选择)
platformAdmin.GET("/:id", platformHandler.GetPlatform) // 获取平台详情
platformAdmin.POST("", platformHandler.CreatePlatform) // 创建平台
platformAdmin.PUT("/:id", platformHandler.UpdatePlatform) // 更新平台
platformAdmin.DELETE("/:id", platformHandler.DeletePlatform) // 删除平台
}
// 店铺管理
admin.GET("/stores", adminProductHandler.GetStores) // 获取店铺列表
@@ -503,6 +528,19 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
bannerAdmin.POST("/clean-expired", adminBannerHandler.CleanExpiredBanners) // 清理过期轮播图
}
// 直播投流源管理
adminLiveStreamHandler := handler.NewLiveStreamHandler(liveStreamService)
liveStreamAdmin := admin.Group("/livestreams")
{
liveStreamAdmin.GET("", adminLiveStreamHandler.GetLiveStreamList) // 获取投流源列表
liveStreamAdmin.GET("/:id", adminLiveStreamHandler.GetLiveStreamDetail) // 获取投流源详情
liveStreamAdmin.POST("", adminLiveStreamHandler.CreateLiveStream) // 创建投流源
liveStreamAdmin.PUT("/:id", adminLiveStreamHandler.UpdateLiveStream) // 更新投流源
liveStreamAdmin.DELETE("/:id", adminLiveStreamHandler.DeleteLiveStream) // 删除投流源
liveStreamAdmin.DELETE("/batch", adminLiveStreamHandler.BatchDeleteLiveStreams) // 批量删除投流源
liveStreamAdmin.PUT("/:id/status", adminLiveStreamHandler.UpdateLiveStreamStatus) // 更新投流源状态
}
// 文件上传管理(管理员专用)
uploadAdmin := admin.Group("/upload")
{
@@ -518,6 +556,23 @@ func Setup(db *gorm.DB, cfg *config.Config) *gin.Engine {
pointsAdmin.POST("/users/:id/deduct", pointsHandler.DeductPoints) // 扣除用户积分
}
// 优惠券管理
adminCouponHandler := handler.NewAdminCouponHandler(couponService)
couponAdmin := admin.Group("/coupons")
{
couponAdmin.GET("", adminCouponHandler.GetCouponList) // 获取优惠券列表
couponAdmin.GET("/:id", adminCouponHandler.GetCouponDetail) // 获取优惠券详情
couponAdmin.POST("", adminCouponHandler.CreateCoupon) // 创建优惠券
couponAdmin.PUT("/:id", adminCouponHandler.UpdateCoupon) // 更新优惠券
couponAdmin.DELETE("/:id", adminCouponHandler.DeleteCoupon) // 删除优惠券
couponAdmin.PUT("/:id/status", adminCouponHandler.UpdateCouponStatus) // 更新优惠券状态
couponAdmin.DELETE("/batch", adminCouponHandler.BatchDeleteCoupons) // 批量删除优惠券
couponAdmin.GET("/statistics", adminCouponHandler.GetCouponStatistics) // 获取优惠券统计
couponAdmin.GET("/user-coupons", adminCouponHandler.GetUserCouponList) // 获取用户优惠券列表
couponAdmin.POST("/distribute", adminCouponHandler.DistributeCoupon) // 发放优惠券
couponAdmin.GET("/distribute/history", adminCouponHandler.GetDistributeHistory) // 获取发放历史
}
// 角色权限管理
adminRoleHandler := handler.NewAdminRoleHandler(db, roleService)
roleAdmin := admin.Group("/roles")