196 lines
6.1 KiB
Go
196 lines
6.1 KiB
Go
package web
|
|
|
|
import (
|
|
"platform/pkg/env"
|
|
auth2 "platform/web/auth"
|
|
"platform/web/handlers"
|
|
"time"
|
|
|
|
q "platform/web/queries"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func ApplyRouters(app *fiber.App) {
|
|
api := app.Group("/api")
|
|
userRouter(api)
|
|
adminRouter(api)
|
|
|
|
// 回调
|
|
callbacks := app.Group("/callback")
|
|
callbacks.Get("/identify", handlers.IdentifyCallbackNew)
|
|
|
|
// 临时
|
|
if env.RunMode == env.RunModeDev {
|
|
debug := app.Group("/debug")
|
|
debug.Get("/sms/:phone", handlers.DebugGetSmsCode)
|
|
debug.Get("/proxy/register", handlers.DebugRegisterProxyBaiYin)
|
|
debug.Get("/iden/clear/:phone", handlers.DebugIdentifyClear)
|
|
debug.Get("/session/now", func(ctx *fiber.Ctx) error {
|
|
rs, err := q.Session.Where(q.Session.AccessTokenExpires.Gt(time.Now())).Find()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ctx.JSON(rs)
|
|
})
|
|
}
|
|
}
|
|
|
|
// 用户接口路由
|
|
func userRouter(api fiber.Router) {
|
|
// 认证
|
|
auth := api.Group("/auth")
|
|
auth.Get("/authorize", auth2.AuthorizeGet)
|
|
auth.Post("/authorize", auth2.AuthorizePost)
|
|
auth.Post("/token", auth2.Token)
|
|
auth.Post("/revoke", auth2.Revoke)
|
|
auth.Post("/introspect", auth2.Introspect)
|
|
auth.Post("/verify/sms", handlers.SmsCode)
|
|
|
|
// 用户
|
|
user := api.Group("/user")
|
|
user.Post("/update", handlers.UpdateUser)
|
|
user.Post("/update/account", handlers.UpdateAccount)
|
|
user.Post("/update/password", handlers.UpdatePassword)
|
|
user.Post("/identify", handlers.Identify)
|
|
|
|
// 白名单
|
|
whitelist := api.Group("/whitelist")
|
|
whitelist.Post("/list", handlers.ListWhitelist)
|
|
whitelist.Post("/create", handlers.CreateWhitelist)
|
|
whitelist.Post("/update", handlers.UpdateWhitelist)
|
|
whitelist.Post("/remove", handlers.RemoveWhitelist)
|
|
|
|
// 套餐
|
|
resource := api.Group("/resource")
|
|
resource.Post("/all", handlers.AllActiveResource)
|
|
resource.Post("/list/short", handlers.PageResourceShort)
|
|
resource.Post("/list/long", handlers.PageResourceLong)
|
|
resource.Post("/create", handlers.CreateResource)
|
|
resource.Post("/price", handlers.ResourcePrice)
|
|
resource.Post("/statistics/free", handlers.StatisticResourceFree)
|
|
resource.Post("/statistics/usage", handlers.StatisticResourceUsage)
|
|
|
|
// 批次
|
|
batch := api.Group("/batch")
|
|
batch.Post("/page", handlers.PageResourceBatch)
|
|
|
|
// 通道
|
|
channel := api.Group("/channel")
|
|
channel.Post("/list", handlers.ListChannels)
|
|
channel.Post("/create", handlers.CreateChannel)
|
|
channel.Post("/remove", handlers.RemoveChannels)
|
|
|
|
// 交易
|
|
trade := api.Group("/trade")
|
|
trade.Post("/create", handlers.TradeCreate)
|
|
trade.Post("/complete", handlers.TradeComplete)
|
|
trade.Post("/cancel", handlers.TradeCancel)
|
|
trade.Get("/check", handlers.TradeCheck)
|
|
|
|
// 账单
|
|
bill := api.Group("/bill")
|
|
bill.Post("/list", handlers.ListBill)
|
|
|
|
// 公告
|
|
announcement := api.Group("/announcement")
|
|
announcement.Post("/list", handlers.ListAnnouncements)
|
|
|
|
// 网关
|
|
proxy := api.Group("/proxy")
|
|
proxy.Post("/online", handlers.ProxyReportOnline)
|
|
proxy.Post("/offline", handlers.ProxyReportOffline)
|
|
proxy.Post("/update", handlers.ProxyReportUpdate)
|
|
proxy.Post("/register/baidyin", handlers.ProxyRegisterBaiYin)
|
|
|
|
// 节点
|
|
edge := api.Group("/edge")
|
|
edge.Post("/assign", handlers.AssignEdge)
|
|
edge.Post("/all", handlers.AllEdgesAvailable)
|
|
|
|
// 前台
|
|
inquiry := api.Group("/inquiry")
|
|
inquiry.Post("/create", handlers.CreateInquiry)
|
|
}
|
|
|
|
// 管理员接口路由
|
|
func adminRouter(api fiber.Router) {
|
|
api = api.Group("/admin")
|
|
|
|
// permission 权限
|
|
var permission = api.Group("/permission")
|
|
permission.Post("/list", handlers.ListPermissionsByAdmin)
|
|
permission.Post("/page", handlers.PagePermissionByAdmin)
|
|
|
|
// admin-role 管理员角色
|
|
var adminRole = api.Group("/admin-role")
|
|
adminRole.Post("/list", handlers.ListAdminRolesByAdmin)
|
|
adminRole.Post("/page", handlers.PageAdminRolesByAdmin)
|
|
adminRole.Post("/create", handlers.CreateAdminRole)
|
|
adminRole.Post("/update", handlers.UpdateAdminRole)
|
|
adminRole.Post("/remove", handlers.RemoveAdminRole)
|
|
|
|
// admins 管理员账户
|
|
var admins = api.Group("/admin")
|
|
admins.Post("/page", handlers.PageAdminsByAdmin)
|
|
admins.Post("/create", handlers.CreateAdmin)
|
|
admins.Post("/update", handlers.UpdateAdmin)
|
|
admins.Post("/remove", handlers.RemoveAdmin)
|
|
|
|
// user 用户
|
|
var user = api.Group("/user")
|
|
user.Post("/page", handlers.PageUserByAdmin)
|
|
user.Post("/bind", handlers.BindAdmin)
|
|
|
|
// resource 套餐
|
|
var resource = api.Group("/resource")
|
|
resource.Post("/short/page", handlers.PageResourceShortByAdmin)
|
|
resource.Post("/long/page", handlers.PageResourceLongByAdmin)
|
|
resource.Post("/update", handlers.UpdateResourceByAdmin)
|
|
|
|
// batch 批次
|
|
var usage = api.Group("batch")
|
|
usage.Post("/page", handlers.PageBatchByAdmin)
|
|
|
|
// channel 通道
|
|
var channel = api.Group("/channel")
|
|
channel.Post("/page", handlers.PageChannelsByAdmin)
|
|
|
|
// trade 交易
|
|
var trade = api.Group("trade")
|
|
trade.Post("/page", handlers.PageTradeByAdmin)
|
|
|
|
// bill 账单
|
|
var bill = api.Group("/bill")
|
|
bill.Post("/page", handlers.PageBillByAdmin)
|
|
|
|
// product 产品
|
|
var product = api.Group("/product")
|
|
product.Post("/all", handlers.AllProductsByAdmin)
|
|
product.Post("/create", handlers.CreateProduct)
|
|
product.Post("/update", handlers.UpdateProduct)
|
|
product.Post("/remove", handlers.DeleteProduct)
|
|
product.Post("/sku/all", handlers.AllProductSkuByAdmin)
|
|
product.Post("/sku/page", handlers.PageProductSkuByAdmin)
|
|
product.Post("/sku/create", handlers.CreateProductSku)
|
|
product.Post("/sku/update", handlers.UpdateProductSku)
|
|
product.Post("/sku/update/discount/batch", handlers.BatchUpdateProductSkuDiscount)
|
|
product.Post("/sku/remove", handlers.DeleteProductSku)
|
|
|
|
// discount 折扣
|
|
var discount = api.Group("/discount")
|
|
discount.Post("/page", handlers.PageProductDiscountByAdmin)
|
|
discount.Post("/all", handlers.AllProductDiscountsByAdmin)
|
|
discount.Post("/create", handlers.CreateProductDiscount)
|
|
discount.Post("/update", handlers.UpdateProductDiscount)
|
|
discount.Post("/remove", handlers.DeleteProductDiscount)
|
|
|
|
// coupon 优惠券
|
|
var coupon = api.Group("/coupon")
|
|
coupon.Post("/page", handlers.PageCouponByAdmin)
|
|
coupon.Post("/all", handlers.AllCouponsByAdmin)
|
|
coupon.Post("/create", handlers.CreateCoupon)
|
|
coupon.Post("/update", handlers.UpdateCoupon)
|
|
coupon.Post("/remove", handlers.DeleteCoupon)
|
|
}
|