package router import ( agentHdl "applet/app/agent/hdl" "applet/app/cfg" "applet/app/hdl" "applet/app/mw" storeHdl "applet/app/store/hdl" _ "applet/docs" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" ) // 初始化路由 // 1 func Init() *gin.Engine { // debug, release, test 项目阶段 mode := "release" if cfg.Debug { mode = "debug" } gin.SetMode(mode) //创建一个新的启动器 r := gin.New() r.GET("/api/swagger/*any", func(c *gin.Context) { //r.Use(mw.SwagAuth()) ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c) }) r.Use(mw.ChangeHeader) // 是否打印访问日志, 在非正式环境都打印 if mode != "release" { r.Use(gin.Logger()) } r.Use(gin.Recovery()) r.GET("/favicon.ico", func(c *gin.Context) { c.Status(204) }) r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}}) }) r.NoMethod(func(c *gin.Context) { c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}}) }) r.Use(mw.Cors) routeCommunityTeamAgent(r.Group("/api/v1/communityTeam/agent")) routeCommunityTeamOwnStore(r.Group("/api/v1/communityTeam/ownStore")) routeCommunityTeam(r.Group("/api/v1/communityTeam")) return r } func routeCommunityTeamAgent(r *gin.RouterGroup) { // 文件上传确认回调, 不校验设备等头部信息 r.POST("/file/img/callback", agentHdl.FileImgCallback) r.Use(mw.DB) // 下面接口再根据mid 获取数据库名 r.POST("/login", agentHdl.Login) r.Use(mw.AuthJWT) // 文件上传 r.POST("/img/upload", agentHdl.ImgReqUpload) r.GET("/user", agentHdl.User) r.POST("/service/file/upload", agentHdl.ServiceFileUpload) r.GET("/wechat/base", agentHdl.WechatBase) r.POST("/wechat/base/set", agentHdl.WechatBaseSet) r.GET("/alipay/base", agentHdl.AlipayBase) r.POST("/alipay/base/set", agentHdl.AlipayBaseSet) r.POST("/store/list", agentHdl.UserStoreList) r.POST("/store/save", agentHdl.UserStoreSave) r.POST("/store/order", agentHdl.UserStoreOrder) r.POST("/store/order/detail", agentHdl.UserStoreOrderDetail) r.POST("/store/total", agentHdl.UserStoreTotal) r.POST("/goods/list", agentHdl.Goods) r.POST("/goods/save", agentHdl.GoodsSave) r.POST("/goods/detail", agentHdl.GoodsDetail) r.POST("/goods/del", agentHdl.GoodsDel) r.POST("/goods/cate/list", agentHdl.GoodsCate) r.POST("/goods/cate/save", agentHdl.GoodsCateSave) r.POST("/goods/cate/show", agentHdl.GoodsCateShow) r.POST("/goods/cate/del", agentHdl.GoodsCateDel) r.POST("/store/withdraw/flow", agentHdl.StoreWithdrawFlow) r.POST("/store/withdraw/total", agentHdl.StoreWithdrawTotal) r.POST("/store/withdraw/audit", agentHdl.StoreWithdrawAudit) r.POST("/store/withdraw/all/audit", agentHdl.StoreWithdrawAuditAll) r.POST("/store/withdraw/output", agentHdl.StoreWithdrawOutPut) } func routeCommunityTeamOwnStore(r *gin.RouterGroup) { r.POST("/file/img/callback", storeHdl.FileImgCallback) r.Use(mw.DB) // 下面接口再根据mid 获取数据库名 r.POST("/login", storeHdl.Login) r.POST("/login/send_sms", storeHdl.LoginSendSms) r.POST("/login/fast_in", storeHdl.LoginFastIn) r.Use(mw.AuthJWT) r.GET("/sub_region_list", storeHdl.GetRegionChildNode) r.POST("/sms", storeHdl.Sms) r.POST("/img/upload", storeHdl.ImgReqUpload) r.GET("/user", storeHdl.User) r.GET("/base", storeHdl.Base) r.GET("/base/set", storeHdl.BaseSet) r.GET("/info", storeHdl.UserStoreInfo) r.POST("/info/set", storeHdl.UserStoreInfoSet) r.POST("/banner/save", storeHdl.UserStoreBannerSave) r.POST("/banner/del", storeHdl.UserStoreBannerDel) r.POST("/banner/detail", storeHdl.UserStoreBannerDetail) r.POST("/banner", storeHdl.UserStoreBanner) r.GET("/audit/info", storeHdl.AuditInfo) r.POST("/audit/doing", storeHdl.AuditDoing) r.POST("/store/order", storeHdl.UserStoreOrder) r.POST("/store/order/detail", storeHdl.UserStoreOrderDetail) r.POST("/store/order/confirm", storeHdl.StoreOrderConfirm) r.GET("/store/amount/base", storeHdl.StoreAmountBase) r.POST("/store/amount/flow", storeHdl.StoreAmountFlow) r.POST("/store/withdraw/flow", storeHdl.StoreWithdrawFlow) r.POST("/store/withdraw/doing", storeHdl.StoreWithdrawDoing) r.POST("/store/withdraw/bind/alipay", storeHdl.StoreWithdrawBindAlipay) r.POST("/goods/list", storeHdl.Goods) r.POST("/goods/save", storeHdl.GoodsSave) r.POST("/goods/detail", storeHdl.GoodsDetail) r.POST("/goods/del", storeHdl.GoodsDel) r.POST("/goods/cate/list", storeHdl.GoodsCate) r.POST("/goods/cate/save", storeHdl.GoodsCateSave) r.POST("/goods/cate/show", storeHdl.GoodsCateShow) r.POST("/goods/cate/del", storeHdl.GoodsCateDel) r.POST("/agent/goods/list", storeHdl.AgentGoods) r.POST("/agent/goods/detail", storeHdl.AgentGoodsDetail) r.POST("/agent/goods/copy", storeHdl.AgentGoodsCopy) } func routeCommunityTeam(r *gin.RouterGroup) { r.Use(mw.DB) // 下面接口再根据mid 获取数据库名 r.Use(mw.CheckBody) //body参数转换 r.Use(mw.CheckSign) //签名校验 r.Use(mw.Checker) r.POST("/city", hdl.City) r.GET("/bank/store/cate", hdl.BankStoreCate) r.POST("/bank/store/list", hdl.BankStore) r.GET("/new/store/cate", hdl.NewStoreCate) r.POST("/new/store/list", hdl.NewStore) r.POST("/store", hdl.Store) r.POST("/store/like/list", hdl.StoreLike) r.GET("/goods/cate", hdl.Cate) r.POST("/goods", hdl.Goods) r.POST("/goods/sku", hdl.GoodsSku) r.POST("/coupon", hdl.Coupon) r.GET("/user", hdl.User) // 用户授权后调用的接口 r.Use(mw.AuthJWT) r.POST("/coupon/receive", hdl.CouponReceive) r.POST("/store/addLike", hdl.StoreAddLike) r.POST("/store/cancelLike", hdl.StoreCancelLike) r.POST("/goods/coupon", hdl.GoodsCoupon) r.POST("/order/total", hdl.OrderTotal) r.POST("/order/create", hdl.OrderCreate) r.POST("/order/cancel", hdl.OrderCancel) r.POST("/order/confirm", hdl.OrderConfirm) r.POST("/order/coupon", hdl.OrderCoupon) r.POST("/order/list", hdl.OrderList) r.POST("/order/detail", hdl.OrderDetail) r.GET("/order/cate", hdl.OrderCate) r.POST("/pay/:payMethod/:orderType", hdl.Pay) r.POST("/store/order/list", hdl.StoreOrderList) r.POST("/store/order/detail", hdl.StoreOrderDetail) r.POST("/store/order/confirm", hdl.StoreOrderConfirm) r.GET("/store/order/cate", hdl.StoreOrderCate) }