package router import ( "applet/app/cfg" "applet/app/hdl" "applet/app/mw" _ "applet/docs" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" ) // 初始化路由 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.Use(mw.Limiter) //r.LoadHTMLGlob("static/html/*") 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) route(r.Group("/api")) return r } func route(r *gin.RouterGroup) { r.GET("/test", hdl.Demo) r.GET("/authorize", hdl.AppletAuthorize) r.POST("/qiniuyun/callback", hdl.FileImgCallback) //七牛云回调 r.Use(mw.DB) // 以下接口需要用到数据库 { r.POST("/login", hdl.Login) } r.Use(mw.CheckBody) //body参数转换 r.Use(mw.CheckSign) //签名校验 r.POST("/qiniuyun/upload", hdl.ImgReqUpload) //七牛云上传 r.POST("/registerForMedium", hdl.RegisterForMedium) r.POST("/registerForAgent", hdl.RegisterForAgent) r.Use(mw.Auth) // 以下接口需要JWT验证 rRole(r.Group("/role")) //权限管理 rQualification(r.Group("/qualification")) //资质认证公共数据 rAgentQualification(r.Group("/agentQualification")) //渠道-资质 rMediumQualification(r.Group("/mediumQualification")) //媒体-资质 rSetCenter(r.Group("/setCenter")) //设置中心 rMedium(r.Group("/mediumCenter")) //媒体中心 rDivisionStrategy(r.Group("/divisionStrategy")) //分成策略 rDataCenter(r.Group("/dataCenter")) //数据中心 rSettleCenter(r.Group("/settleCenter")) //结算中心 rFinanceCenter(r.Group("/financeCenter")) //财务中心 rIndex(r.Group("/index")) //首页 rFinancialDynamics(r.Group("/financialDynamics")) //资产动态 } func rIndex(r *gin.RouterGroup) { r.GET("/base", hdl.Base) //首页-基本信息 r.GET("/total", hdl.IndexTotal) //首页-统计数据 r.POST("/app/list", hdl.IndexAppList) //首页-应用数据 r.POST("/app/list/table", hdl.IndexAppListTable) //首页-应用数据-每个应用的折线图 } func rRole(r *gin.RouterGroup) { r.GET("/roleList", hdl.RoleList) //角色列表 r.POST("/addRole", hdl.AddRole) //角色添加 r.POST("/roleBindPermissionGroup", hdl.RoleBindPermissionGroup) //角色绑定权限组 r.POST("/updateRoleState", hdl.UpdateRoleState) //修改角色状态 r.POST("/updateRole", hdl.UpdateRole) //修改角色状态 r.DELETE("/deleteRole/:id", hdl.DeleteRole) //删除角色 r.GET("/permissionGroupList", hdl.PermissionGroupList) //权限组列表 r.POST("/adminList", hdl.AdminList) //管理员列表 r.POST("/updateAdminState", hdl.UpdateAdminState) //修改管理员状态 r.POST("/updateAdmin", hdl.UpdateAdmin) //修改管理员信息 r.POST("/addAdmin", hdl.AddAdmin) //新增管理员 r.DELETE("/deleteAdmin/:adm_id", hdl.DeleteAdmin) //删除管理员 r.GET("/adminInfo", hdl.AdminInfo) //获取管理员信息 r.POST("/bindAdminRole", hdl.BindAdminRole) //绑定角色 } func rQualification(r *gin.RouterGroup) { r.GET("/select/base", hdl.QualificationSelectBase) //资质认证-认证选择内容 } func rAgentQualification(r *gin.RouterGroup) { r.POST("/enterprise", hdl.AgentQualificationEnterprise) //企业主体资质 r.POST("/enterprise/audit", hdl.AgentQualificationEnterpriseAudit) //企业主体资质审核 r.POST("/bank", hdl.AgentQualificationBank) //银行资质 r.POST("/bank/audit", hdl.AgentQualificationBankAudit) //银行审核 r.POST("/contact", hdl.AgentQualificationContactInfo) //联系方式 r.POST("/contact/audit", hdl.AgentQualificationContactInfoAudit) //联系方式 } func rMediumQualification(r *gin.RouterGroup) { r.POST("/enterprise", hdl.MediumQualificationEnterprise) //企业主体资质 r.POST("/enterprise/audit", hdl.MediumQualificationEnterpriseAudit) //企业主体资质审核 r.POST("/bank", hdl.MediumQualificationBank) //银行资质 r.POST("/bank/audit", hdl.MediumQualificationBankAudit) //银行审核 r.POST("/contact", hdl.MediumQualificationContactInfo) //联系方式 r.POST("/contact/audit", hdl.MediumQualificationContactInfoAudit) //联系方式 } func rSetCenter(r *gin.RouterGroup) { rBasicSetCenter := r.Group("/basic") { rBasicSetCenter.POST("/setOss", hdl.SetOss) rBasicSetCenter.GET("/getOss", hdl.GetOss) rBasicSetCenter.POST("/wxOpenSet", hdl.WxOpenSet) rBasicSetCenter.GET("/wxOpenGet", hdl.WxOpenGet) rBasicSetCenter.POST("/setMob", hdl.SetMob) rBasicSetCenter.GET("/getMob", hdl.GetMob) rBasicSetCenter.POST("/setLogo", hdl.SetLogo) rBasicSetCenter.GET("/getLogo", hdl.GetLogo) } rAppletSetCenter := r.Group("/applet") { rAppletSetCenter.GET("/list", hdl.AppletList) rAppletSetCenter.POST("/add", hdl.AppletAdd) rAppletSetCenter.POST("/update", hdl.AppletUpdate) rAppletSetCenter.DELETE("/delete/:id", hdl.AppletDelete) rAppletSetCenter.GET("/authorize", hdl.AppletAuthorize) rAppletSetCenter.GET("/unauthorized", hdl.AppletUnauthorized) } rShareSetCenter := r.Group("/share") { rShareSetCenter.GET("/index", hdl.ShareIndex) } } func rMedium(r *gin.RouterGroup) { r.POST("/applet/application/medium/list", hdl.AppletApplicationMediumList) //应用管理-媒体列表 r.POST("/applet/application/list", hdl.AppletApplicationList) //小程序应用-列表数据 r.POST("/applet/application/audit", hdl.AppletApplicationAudit) //小程序应用-审核 r.POST("/applet/application/ad/space/medium/list", hdl.AppletApplicationAdSpaceMediumList) //广告管理-媒体列表 r.POST("/applet/application/ad/space/list", hdl.AppletApplicationAdSpaceList) //小程序应用-广告位列表数据 r.POST("/applet/application/ad/space/audit", hdl.AppletApplicationAdSpaceAudit) //小程序应用-广告位审核 r.POST("/medium/list", hdl.MediumList) //媒体列表 r.POST("/medium/bind/agent/list", hdl.MediumBindAgentList) //媒体绑定代理列表 r.POST("/medium/bind/agent/save", hdl.MediumBindAgentSave) //媒体绑定代理操作 r.POST("/medium/bind/agent/del", hdl.MediumBindAgentDel) //媒体绑定代理删除 r.POST("/agent/list", hdl.AgentList) //代理列表 r.POST("/agent/bind/medium/list", hdl.AgentBindMediumList) //代理绑定媒体列表 } func rDivisionStrategy(r *gin.RouterGroup) { r.POST("/list", hdl.DivisionStrategyList) //分成策略-列表 r.POST("/detail", hdl.DivisionStrategyDetail) //分成策略-详情 r.POST("/save", hdl.DivisionStrategySave) //分成策略-保存 } func rDataCenter(r *gin.RouterGroup) { r.POST("/original/data/list", hdl.OriginalDataList) //数据中心-原始数据 r.POST("/original/data/del", hdl.OriginalDataDel) //数据中心-原始数据-删除 r.POST("/original/data/total", hdl.OriginalDataTotal) //数据中心-原始数据-记录应用时统计 r.POST("/original/data/doing", hdl.OriginalDataDoing) //数据中心-原始数据-记录应用时操作 r.POST("/original/data/more/application", hdl.OriginalDataMoreApplication) //数据中心-原始数据-一键导入应用列表 r.POST("/original/data/more/application/doing", hdl.OriginalDataMoreApplicationDoing) //数据中心-原始数据-一键导入操作 r.GET("/original/data/more/application/state", hdl.OriginalDataMoreApplicationState) //数据中心-原始数据-一键导入操作后的完成状态 r.GET("/original/data/one/application", hdl.OriginalDataOneApplication) //数据中心-原始数据-单个导入应用列表 r.POST("/original/data/one/application/ad/list", hdl.OriginalDataOneApplicationAdList) //数据中心-原始数据-单个导入应用-广告位列表 r.POST("/original/data/one/application/total", hdl.OriginalDataOneApplicationTotal) //数据中心-原始数据-单个应用数据统计 r.POST("/original/data/one/application/doing", hdl.OriginalDataOneApplicationDoing) //数据中心-原始数据-单个应用数据操作 r.GET("/original/data/one/application/state", hdl.OriginalDataOneApplicationState) //数据中心-原始数据-单个应用数据操作后的完成状态 r.POST("/generate/data/list", hdl.GenerateDataList) //数据中心-分成数据 r.POST("/generate/data/del", hdl.GenerateDataDel) //数据中心-分成数据-删除 r.POST("/generate/data/detail", hdl.GenerateDataDetail) //数据中心-分成数据-详情 r.POST("/generate/data/doing", hdl.GenerateDataDoing) //数据中心-分成数据-报表生成操作 r.POST("/income/data/list", hdl.IncomeDataList) //数据中心-收益报表 r.POST("/income/data/detail", hdl.IncomeDataDetail) //数据中心-收益报表-详情 } func rSettleCenter(r *gin.RouterGroup) { r.POST("/medium/list", hdl.SettleCenterMediumList) //结算中心-媒体列表 r.POST("/medium/save", hdl.SettleCenterMediumSave) //结算中心-媒体修复结算方式 r.POST("/medium/detail", hdl.SettleCenterMediumDetail) //结算中心-媒体结算详情 r.POST("/agent/list", hdl.SettleCenterAgentList) //结算中心-代理列表 r.POST("/agent/save", hdl.SettleCenterAgentSave) //结算中心-代理修复结算方式 r.POST("/agent/detail", hdl.SettleCenterAgentDetail) //结算中心-代理结算详情 } func rFinanceCenter(r *gin.RouterGroup) { r.POST("/medium/list", hdl.FinanceCenterMediumList) //财务中心-媒体列表 r.POST("/medium/detail", hdl.FinanceCenterMediumDetail) //财务中心-媒体详情 r.POST("/medium/settle/file/save", hdl.FinanceCenterMediumSettleFileSave) //财务中心-媒体详情-结算单上传 r.POST("/medium/invoice/save", hdl.FinanceCenterMediumInvoiceSave) //财务中心-媒体详情-发票审核 r.POST("/medium/other/income/save", hdl.FinanceCenterMediumOtherIncomeSave) //财务中心-媒体详情-其他收益调整 r.POST("/medium/pay/save", hdl.FinanceCenterMediumPaySave) //财务中心-媒体详情-确认支付 r.POST("/platform/list", hdl.FinanceCenterPlatformList) //财务中心-平台报表 r.POST("/agent/list", hdl.FinanceCenterAgentList) //财务中心-代理列表 r.POST("/agent/detail", hdl.FinanceCenterAgentDetail) //财务中心-代理详情 r.POST("/agent/settle/file/save", hdl.FinanceCenterAgentSettleFileSave) //财务中心-代理详情-结算单上传 r.POST("/agent/invoice/save", hdl.FinanceCenterAgentInvoiceSave) //财务中心-代理详情-发票审核 r.POST("/agent/other/income/save", hdl.FinanceCenterAgentOtherIncomeSave) //财务中心-代理详情-其他收益调整 r.POST("/agent/pay/save", hdl.FinanceCenterAgentPaySave) //财务中心-代理详情-确认支付 } func rFinancialDynamics(r *gin.RouterGroup) { r.POST("/medium/total", hdl.FinancialDynamicsMediumTotal) //资产动态-媒体预付统计 r.POST("/medium/list", hdl.FinancialDynamicsMediumList) //资产动态-媒体预付 r.POST("/medium/save", hdl.FinancialDynamicsMediumSave) //资产动态-媒体预付创建 r.POST("/agent/total", hdl.FinancialDynamicsAgentTotal) //资产动态-代理预付统计 r.POST("/agent/list", hdl.FinancialDynamicsAgentList) //资产动态-代理预付 r.POST("/agent/save", hdl.FinancialDynamicsAgentSave) //资产动态-代理预付创建 }