hotfix.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // 实时数据
  2. package controllers
  3. import (
  4. "box-gm/models"
  5. "log"
  6. "github.com/astaxie/beego"
  7. )
  8. type HotfixController struct {
  9. beego.Controller
  10. }
  11. func (c *HotfixController) Get() {
  12. userinfo := c.GetSession("user")
  13. if userinfo == nil {
  14. c.Ctx.Redirect(302, "/accountlogin")
  15. return
  16. }
  17. c.Data["username"] = userinfo.(*LoginInfo).Username
  18. c.Data["token"] = models.GetToken()
  19. userPermission := models.GetPermission(userinfo.(*LoginInfo).Username)
  20. if (userPermission & (1 << uint(models.ModelSystem))) == 0 {
  21. c.Ctx.Redirect(302, "/accountlogin")
  22. return
  23. }
  24. action := c.GetString("action")
  25. log.Printf("HotfixController Get action[%s]", action)
  26. switch action {
  27. case "select":
  28. id, _ := c.GetInt64("id")
  29. cp := models.GetHotfixInfoById(id)
  30. if cp == nil {
  31. c.Data["json"] = &map[string]interface{}{"status": false, "info": "参数不存在"}
  32. c.ServeJSON()
  33. return
  34. }
  35. c.Data["json"] = &map[string]interface{}{"status": true}
  36. c.ServeJSON()
  37. default:
  38. id, _ := c.GetInt64("id")
  39. cp := models.GetHotfixInfoById(id)
  40. if cp != nil {
  41. c.Data["Id"] = id
  42. c.Data["Channel"] = cp.Channel
  43. c.Data["Version"] = cp.Version
  44. c.Data["DowloadAddr"] = cp.DowloadAddr
  45. c.Data["FileSize"] = cp.FileSize
  46. }
  47. c.Data["infoList"] = models.GetHotfixInfo()
  48. c.TplName = "hotfix.tpl"
  49. }
  50. }
  51. func (c *HotfixController) Post() {
  52. userinfo := c.GetSession("user")
  53. log.Printf("HotfixController Post userinfo[%v]", userinfo)
  54. if userinfo == nil {
  55. c.Ctx.Redirect(302, "/accountlogin")
  56. return
  57. }
  58. channel, _ := c.GetInt64("channel")
  59. log.Printf("HotfixController Post channel[%d]", channel)
  60. hf := models.GetHotfixInfoByChannel(channel)
  61. if hf != nil {
  62. c.Data["json"] = &map[string]interface{}{"status": false, "info": "新增失败:渠道已配置"}
  63. c.ServeJSON()
  64. return
  65. }
  66. u := new(models.HotfixInfo)
  67. u.Channel = channel
  68. u.Version = c.GetString("version")
  69. u.DowloadAddr = c.GetString("addr")
  70. u.FileSize = c.GetString("filesize")
  71. if u.Channel == 0 || u.Version == "" {
  72. c.Data["json"] = &map[string]interface{}{"status": false, "info": "渠道和版本不能为空"}
  73. c.ServeJSON()
  74. return
  75. }
  76. _, err := models.AddHotfixInfo(u)
  77. if err != nil {
  78. c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()}
  79. c.ServeJSON()
  80. return
  81. }
  82. c.Data["json"] = &map[string]interface{}{"status": true, "info": "新增热更新参数成功"}
  83. c.ServeJSON()
  84. }
  85. func (c *HotfixController) Put() {
  86. userinfo := c.GetSession("user")
  87. if userinfo == nil {
  88. c.Ctx.Redirect(302, "/accountlogin")
  89. return
  90. }
  91. u := new(models.HotfixInfo)
  92. u.Id, _ = c.GetInt64("id")
  93. u.Channel, _ = c.GetInt64("channel")
  94. u.Version = c.GetString("version")
  95. u.DowloadAddr = c.GetString("addr")
  96. u.FileSize = c.GetString("filesize")
  97. _, err := models.UpdateHotfixInfo(u)
  98. if err != nil {
  99. c.Data["json"] = &map[string]interface{}{"status": false, "info": err}
  100. c.ServeJSON()
  101. return
  102. }
  103. c.Data["json"] = &map[string]interface{}{"status": true, "info": "更新热更新参数成功"}
  104. c.ServeJSON()
  105. }
  106. func (c *HotfixController) Delete() {
  107. userinfo := c.GetSession("user")
  108. if userinfo == nil {
  109. c.Ctx.Redirect(302, "/accountlogin")
  110. return
  111. }
  112. id, _ := c.GetInt64("id")
  113. cp := models.GetHotfixInfoById(id)
  114. if cp == nil {
  115. c.Data["json"] = &map[string]interface{}{"status": false, "info": "参数不存在"}
  116. c.ServeJSON()
  117. return
  118. }
  119. models.DelHotfixInfoById(id)
  120. c.Data["json"] = &map[string]interface{}{"status": true, "info": "删除热更新参成功"}
  121. c.ServeJSON()
  122. }