http.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package http
  2. import (
  3. "go-common/app/admin/main/up/conf"
  4. "go-common/app/admin/main/up/service"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/middleware/permit"
  8. "go-common/library/net/http/blademaster/middleware/verify"
  9. )
  10. var (
  11. //Svc service.
  12. Svc *service.Service
  13. authSrc *permit.Permit
  14. idfSvc *verify.Verify
  15. )
  16. // Init init account service.
  17. func Init(c *conf.Config) {
  18. // service
  19. initService(c)
  20. // init internal router
  21. engine := bm.DefaultServer(c.HTTPServer)
  22. setupInnerEngine(engine)
  23. // init internal server
  24. if err := engine.Start(); err != nil {
  25. log.Error("engine.Start error(%v)", err)
  26. panic(err)
  27. }
  28. }
  29. func initService(c *conf.Config) {
  30. idfSvc = verify.New(nil)
  31. Svc = service.New(c)
  32. authSrc = permit.New(c.Auth)
  33. }
  34. // innerRouter
  35. func setupInnerEngine(e *bm.Engine) {
  36. // monitor ping
  37. e.Ping(ping)
  38. e.Register(disRegister)
  39. // base
  40. var adminUpProfit *bm.RouterGroup
  41. var noAdminUpProfit *bm.RouterGroup
  42. var identifyUpProfit *bm.RouterGroup
  43. if conf.Conf.IsTest {
  44. adminUpProfit = e.Group("/allowance/api/x/admin/uper")
  45. } else {
  46. // 现在只要登录,默认放过
  47. adminUpProfit = e.Group("/allowance/api/x/admin/uper", authSrc.Verify(), authSrc.Permit(""))
  48. }
  49. // 因为经常出现-401,所以把这些接口的验证去掉
  50. noAdminUpProfit = e.Group("/allowance/api/x/admin/uper")
  51. {
  52. //noAdminUpProfit.GET("/score/query", crmScoreQuery) // 这个接口需要干掉
  53. noAdminUpProfit.GET("/score/query_section", crmScoreQuery)
  54. noAdminUpProfit.GET("/score/query_up", crmScoreQueryUp)
  55. noAdminUpProfit.GET("/score/query_up_history", crmScoreQueryUpHistory)
  56. noAdminUpProfit.GET("/play/query", crmPlayQueryInfo)
  57. noAdminUpProfit.GET("/info/query", crmInfoQueryUp)
  58. noAdminUpProfit.GET("/info/account_info", crmInfoAccountInfo)
  59. noAdminUpProfit.POST("/info/search", crmInfoSearch)
  60. noAdminUpProfit.GET("/creditlog/query", crmCreditLogQueryUp)
  61. noAdminUpProfit.GET("/rank/query_list", crmRankQueryList)
  62. noAdminUpProfit.POST("/file/upload", upload)
  63. noAdminUpProfit.GET("/data/batch_query_data", crmQueryUpInfoWithViewerData)
  64. noAdminUpProfit.GET("/data/fan_summary", dataGetFanSummary)
  65. noAdminUpProfit.GET("/data/fan_relation_history", dataRelationFansHistory)
  66. noAdminUpProfit.GET("/data/up_archive_info", dataGetUpArchiveInfo)
  67. noAdminUpProfit.GET("/data/up_archive_tag_info", dataGetUpArchiveTagInfo)
  68. noAdminUpProfit.GET("/data/up_view_info", dataGetUpViewInfo)
  69. }
  70. if conf.Conf.IsTest {
  71. identifyUpProfit = e.Group("/allowance/api/x/admin/uper")
  72. } else {
  73. identifyUpProfit = e.Group("/allowance/api/x/admin/uper", idfSvc.Verify)
  74. }
  75. {
  76. identifyUpProfit.GET("/service/batch_query_data", crmQueryUpInfoWithViewerData)
  77. identifyUpProfit.GET("/service/data/fan_summary", dataGetFanSummary)
  78. identifyUpProfit.GET("/service/data/fan_relation_history", dataRelationFansHistory)
  79. identifyUpProfit.GET("/service/data/up_archive_info", dataGetUpArchiveInfo)
  80. identifyUpProfit.GET("/service/data/up_archive_tag_info", dataGetUpArchiveTagInfo)
  81. noAdminUpProfit.GET("/test/get_view_base", testGetViewBase)
  82. }
  83. dashboard := noAdminUpProfit.Group("/dashboard")
  84. {
  85. dashboard.GET("/yesterday", yesterday)
  86. dashboard.GET("/trend", trend)
  87. dashboard.GET("/trend/detail", trendDetail)
  88. }
  89. // sign 需要admin验证,这里需要admin的名字和id
  90. sign := adminUpProfit.Group("/sign")
  91. {
  92. sign.POST("/add", signAdd)
  93. sign.POST("/update", signUpdate)
  94. sign.POST("/violation/add", violationAdd)
  95. sign.POST("/violation/retract", violationRetract)
  96. sign.GET("/violation/list", violationList)
  97. sign.POST("/absence/add", absenceAdd)
  98. sign.POST("/absence/retract", absenceRetract)
  99. sign.GET("/absence/list", absenceList)
  100. sign.GET("/up/view/check", viewCheck)
  101. sign.GET("/query", signQuery)
  102. sign.GET("/query/id", signQueryID)
  103. sign.GET("/up/aduit/log", signUpAuditLogs)
  104. sign.GET("/country/list", countrys)
  105. sign.GET("/tid/list", tids)
  106. sign.POST("/pay/complete", signPayComplete)
  107. }
  108. signNoAdmin := noAdminUpProfit.Group("/sign")
  109. {
  110. signNoAdmin.GET("/check_exist", signCheckExist)
  111. }
  112. commandNoAdmin := noAdminUpProfit.Group("/command")
  113. {
  114. commandNoAdmin.GET("/refresh_up_rank", commandRefreshUpRank)
  115. }
  116. //{
  117. // admin.GET("/special/get", specialGet)
  118. // admin.GET("/special/get_by_mid", specialGetByMid)
  119. // admin.POST("/special/delete", specialDel)
  120. // admin.POST("/special/add", specialAdd)
  121. // admin.POST("/special/edit", specialEdit)
  122. // admin.GET("/group/get", getGroup)
  123. // admin.POST("/group/add", authSrc.Permit("UPGROUP_ADD"), addGroup)
  124. // admin.POST("/group/update", updateGroup)
  125. // admin.POST("/group/delete", authSrc.Permit("UPGROUP_ADD"), removeGroup)
  126. //}
  127. }
  128. // ping check server ok.
  129. func ping(ctx *bm.Context) {
  130. if err := Svc.Ping(ctx); err != nil {
  131. ctx.Error = err
  132. ctx.AbortWithStatus(503)
  133. }
  134. }
  135. // disRegister check server ok.
  136. func disRegister(ctx *bm.Context) {
  137. ctx.JSON(map[string]interface{}{}, nil)
  138. }