package router import ( "applet/app/admin/hdl" categoryHdl "applet/app/admin/hdl/category" goodsHdl "applet/app/admin/hdl/goods" orderHdl "applet/app/admin/hdl/order" "applet/app/admin/mw" "applet/app/cfg" "github.com/gin-gonic/gin" ) // Init 初始化路由 func Init() *gin.Engine { mode := "release" if cfg.Debug { mode = "debug" } gin.SetMode(mode) //创建一个新的启动器 r := gin.New() // 是否打印访问日志, 在非正式环境都打印 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) AdminRoute(r.Group("/api/admin")) IpadInit(r.Group("/api/ipad")) BigDataInit(r.Group("/api/bigData")) return r } func rCompany(r *gin.RouterGroup) { r.GET("/list", hdl.CompanyList) r.POST("/add", hdl.CompanyAdd) r.POST("/update", hdl.CompanyUpdate) r.DELETE("/delete/:id", hdl.CompanyDelete) } func rHomePage(r *gin.RouterGroup) { r.GET("/index", hdl.HomeIndex) r.GET("/operationalDataStatistics", hdl.OperationalDataStatistics) r.GET("/repayBehaviorAnalysis", hdl.RepayBehaviorAnalysis) } func rScheme(r *gin.RouterGroup) { r.GET("/list", hdl.SchemeList) r.POST("/add", hdl.AddScheme) r.POST("/update", hdl.UpdateScheme) r.POST("/bindEnterprise", hdl.SchemeBindEnterprise) r.POST("/updateSchemeState", hdl.UpdateSchemeState) r.DELETE("/delete/:id", hdl.DeleteScheme) r.GET("/goodsList", goodsHdl.GetMallGoodsList) r.GET("/goodsDetail", hdl.SchemeGoodsDetail) r.POST("/saveSchemeGoods", hdl.SaveSchemeGoods) } func rComm(r *gin.RouterGroup) { r.POST("/getMenuList", hdl.MenuList) // 获取菜单栏列表 } func rOss(r *gin.RouterGroup) { r.POST("/upload/token", hdl.ImgReqUpload) // 文件上传获取七牛云上传token } func rSetCenter(r *gin.RouterGroup) { r.GET("/get", hdl.GetCenter) // 设置中心-获取 r.POST("/set", hdl.SetCenter) // 设置中心-设置 } func rStaff(r *gin.RouterGroup) { r.POST("/list", hdl.StaffList) r.POST("/delete", hdl.StaffDelete) r.POST("/add", hdl.StaffAdd) r.POST("/update", hdl.StaffUpdate) } func rEnterprise(r *gin.RouterGroup) { r.POST("/list", hdl.EnterpriseList) r.POST("/add", hdl.EnterpriseAdd) r.POST("/update", hdl.EnterpriseUpdate) r.POST("/updateState", hdl.EnterpriseUpdateState) r.POST("/delete", hdl.EnterpriseDelete) } func rCategory(r *gin.RouterGroup) { r.GET("/list", categoryHdl.List) r.GET("/add", categoryHdl.Add) r.GET("/del", categoryHdl.Del) r.POST("/sort", categoryHdl.Sort) r.POST("/save", categoryHdl.Save) } func rGoods(r *gin.RouterGroup) { r.POST("/del", goodsHdl.DelMallGoods) r.POST("/add", goodsHdl.AddMallGoods) r.GET("/detail", goodsHdl.GetGoodsDetail) r.GET("/list", goodsHdl.GetMallGoodsList) r.GET("/checkSkuCode", goodsHdl.CheckSkuCode) r.POST("/change-sale-state", goodsHdl.ChangeSaleState) } 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 rGoodsPay(r *gin.RouterGroup) { r.POST("/enterpriseList", hdl.EnterpriseList) //校企列表 r.GET("/goodsList", goodsHdl.GetMallGoodsListByPay) //商品列表 r.POST("/calcAmount", orderHdl.GoodsPayCalcAmount) //商品下单计算价格 r.POST("/create", orderHdl.GoodsPayCreate) //商品下单 } func rOrder(r *gin.RouterGroup) { r.POST("/list", orderHdl.OrderList) //用户订单 r.POST("/total", orderHdl.OrderTotal) //用户订单统计 r.POST("/cancel", orderHdl.OrderCancel) //用户订单取消 r.POST("/detail", orderHdl.OrderDetail) //用户订单详情 r.POST("/output", orderHdl.OrderOutput) //用户订单导出 r.POST("/del", orderHdl.OrderDel) //用户订单商品删除 r.POST("/edit", orderHdl.OrderEdit) //用户订单修改购买人信息 r.POST("/editNum", orderHdl.OrderEditNum) //用户订单修改订单数 r.POST("/makeRecord", orderHdl.MarkRecord) //制作记录 } func rDataStatistics(r *gin.RouterGroup) { r.POST("/list", hdl.DataStatisticsList) //列表 r.POST("/export", hdl.DataStatisticsExport) //导出 r.POST("/delete", hdl.DataStatisticsDelete) //删除 } func rFinanceManage(r *gin.RouterGroup) { r.POST("/list", orderHdl.OrderList) //用户订单 r.POST("/export", orderHdl.OrderExport) //用户订单导出 r.POST("/total", orderHdl.OrderTotal) //用户订单统计 } func AdminRoute(r *gin.RouterGroup) { r.GET("/demo", hdl.Demo) r.POST("/login", hdl.Login) r.Use(mw.Auth) //检测登录状态 r.GET("/userInfo", hdl.UserInfo) //用户信息 r.GET("/sysCfg", hdl.GetSysCfg) //基础配置-获取 rOss(r.Group("/oss")) rComm(r.Group("/comm")) r.Use(mw.CheckPermission) //检测权限 rHomePage(r.Group("/homePage")) //首页 rCompany(r.Group("/company")) //公司管理 rScheme(r.Group("/scheme")) //方案管理 rEnterprise(r.Group("/enterprise")) //校企 rCategory(r.Group("/category")) //商品类目 rGoods(r.Group("/goods")) //商品 rRole(r.Group("/role")) //权限管理 rSetCenter(r.Group("/setCenter")) //设置中心 rStaff(r.Group("/staff")) //员工管理 rGoodsPay(r.Group("/goodsPay")) //商品下单 rOrder(r.Group("/order")) //用户订单 rFinanceManage(r.Group("/financeManage")) //财务管理 rDataStatistics(r.Group("/dataStatistics")) //数据统计 }