附近小店
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

119 lines
3.8 KiB

  1. package router
  2. import (
  3. agentHdl "applet/app/agent/hdl"
  4. "applet/app/cfg"
  5. "applet/app/hdl"
  6. "applet/app/mw"
  7. _ "applet/docs"
  8. "github.com/gin-gonic/gin"
  9. swaggerFiles "github.com/swaggo/files"
  10. ginSwagger "github.com/swaggo/gin-swagger"
  11. )
  12. // 初始化路由
  13. // 1
  14. func Init() *gin.Engine {
  15. // debug, release, test 项目阶段
  16. mode := "release"
  17. if cfg.Debug {
  18. mode = "debug"
  19. }
  20. gin.SetMode(mode)
  21. //创建一个新的启动器
  22. r := gin.New()
  23. r.GET("/api/swagger/*any", func(c *gin.Context) {
  24. //r.Use(mw.SwagAuth())
  25. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  26. })
  27. r.Use(mw.ChangeHeader)
  28. // 是否打印访问日志, 在非正式环境都打印
  29. if mode != "release" {
  30. r.Use(gin.Logger())
  31. }
  32. r.Use(gin.Recovery())
  33. r.GET("/favicon.ico", func(c *gin.Context) {
  34. c.Status(204)
  35. })
  36. r.NoRoute(func(c *gin.Context) {
  37. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  38. })
  39. r.NoMethod(func(c *gin.Context) {
  40. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  41. })
  42. r.Use(mw.Cors)
  43. routeCommunityTeamAgent(r.Group("/api/v1/communityTeam/agent"))
  44. routeCommunityTeamOwnStore(r.Group("/api/v1/communityTeam/ownStore"))
  45. routeCommunityTeam(r.Group("/api/v1/communityTeam"))
  46. return r
  47. }
  48. func routeCommunityTeamAgent(r *gin.RouterGroup) {
  49. r.Use(mw.DB) // 下面接口再根据mid 获取数据库名
  50. r.POST("/login", agentHdl.Login)
  51. r.Use(mw.AuthJWT)
  52. r.GET("/user", agentHdl.User)
  53. r.POST("/service/file/upload", agentHdl.ServiceFileUpload)
  54. r.GET("/wechat/base", agentHdl.WechatBase)
  55. r.POST("/wechat/base/set", agentHdl.WechatBaseSet)
  56. r.GET("/alipay/base", agentHdl.AlipayBase)
  57. r.POST("/alipay/base/set", agentHdl.AlipayBaseSet)
  58. r.POST("/store/list", agentHdl.UserStoreList)
  59. r.POST("/store/save", agentHdl.UserStoreSave)
  60. r.POST("/store/order", agentHdl.UserStoreOrder)
  61. r.POST("/store/order/detail", agentHdl.UserStoreOrderDetail)
  62. r.POST("/store/total", agentHdl.UserStoreTotal)
  63. r.POST("/goods/list", agentHdl.Goods)
  64. r.POST("/goods/save", agentHdl.GoodsSave)
  65. r.POST("/goods/detail", agentHdl.GoodsDetail)
  66. r.POST("/goods/del", agentHdl.GoodsDel)
  67. r.POST("/goods/cate/list", agentHdl.GoodsCate)
  68. r.POST("/goods/cate/save", agentHdl.GoodsCateSave)
  69. r.POST("/goods/cate/show", agentHdl.GoodsCateShow)
  70. r.POST("/goods/cate/del", agentHdl.GoodsCateDel)
  71. }
  72. func routeCommunityTeamOwnStore(r *gin.RouterGroup) {
  73. }
  74. func routeCommunityTeam(r *gin.RouterGroup) {
  75. r.Use(mw.DB) // 下面接口再根据mid 获取数据库名
  76. r.Use(mw.CheckBody) //body参数转换
  77. r.Use(mw.CheckSign) //签名校验
  78. r.Use(mw.Checker)
  79. r.POST("/city", hdl.City)
  80. r.GET("/bank/store/cate", hdl.BankStoreCate)
  81. r.POST("/bank/store/list", hdl.BankStore)
  82. r.GET("/new/store/cate", hdl.NewStoreCate)
  83. r.POST("/new/store/list", hdl.NewStore)
  84. r.POST("/store", hdl.Store)
  85. r.POST("/store/like/list", hdl.StoreLike)
  86. r.GET("/goods/cate", hdl.Cate)
  87. r.POST("/goods", hdl.Goods)
  88. r.POST("/goods/sku", hdl.GoodsSku)
  89. r.POST("/coupon", hdl.Coupon)
  90. r.GET("/user", hdl.User)
  91. // 用户授权后调用的接口
  92. r.Use(mw.AuthJWT)
  93. r.POST("/coupon/receive", hdl.CouponReceive)
  94. r.POST("/store/addLike", hdl.StoreAddLike)
  95. r.POST("/store/cancelLike", hdl.StoreCancelLike)
  96. r.POST("/goods/coupon", hdl.GoodsCoupon)
  97. r.POST("/order/total", hdl.OrderTotal)
  98. r.POST("/order/create", hdl.OrderCreate)
  99. r.POST("/order/cancel", hdl.OrderCancel)
  100. r.POST("/order/confirm", hdl.OrderConfirm)
  101. r.POST("/order/coupon", hdl.OrderCoupon)
  102. r.POST("/order/list", hdl.OrderList)
  103. r.POST("/order/detail", hdl.OrderDetail)
  104. r.GET("/order/cate", hdl.OrderCate)
  105. r.POST("/pay/:payMethod/:orderType", hdl.Pay)
  106. r.POST("/store/order/list", hdl.StoreOrderList)
  107. r.POST("/store/order/detail", hdl.StoreOrderDetail)
  108. r.POST("/store/order/confirm", hdl.StoreOrderConfirm)
  109. r.GET("/store/order/cate", hdl.StoreOrderCate)
  110. }