exchangecode.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // 实时数据
  2. package controllers
  3. import (
  4. "box-gm/models"
  5. "box-gm/utils"
  6. "encoding/json"
  7. "log"
  8. "github.com/astaxie/beego"
  9. )
  10. type ExchangeCodeController struct {
  11. beego.Controller
  12. }
  13. func (c *ExchangeCodeController) Get() {
  14. userinfo := c.GetSession("user")
  15. if userinfo == nil {
  16. c.Ctx.Redirect(302, "/accountlogin")
  17. return
  18. }
  19. c.Data["username"] = userinfo.(*LoginInfo).Username
  20. c.Data["token"] = models.GetToken()
  21. userPermission := models.GetPermission(userinfo.(*LoginInfo).Username)
  22. if (userPermission & (1 << uint(models.ModelSystem))) == 0 {
  23. c.Ctx.Redirect(302, "/accountlogin")
  24. return
  25. }
  26. c.Data["ItemList"] = models.GetItemInfoList()
  27. c.Data["infoList"] = models.GetExchangeCodeInfo()
  28. c.TplName = "exchangecode.tpl"
  29. }
  30. func (c *ExchangeCodeController) Post() {
  31. userinfo := c.GetSession("user")
  32. log.Printf("ExchangeCodeController Post userinfo[%v]", userinfo)
  33. if userinfo == nil {
  34. c.Ctx.Redirect(302, "/accountlogin")
  35. return
  36. }
  37. pcode := c.GetString("pcode")
  38. log.Printf("ExchangeCodeController Post pcode[%s]", pcode)
  39. hf := models.GetExchangeCodeInfoByCode(pcode)
  40. if hf != nil {
  41. c.Data["json"] = &map[string]interface{}{"status": false, "info": "新增失败:渠道已配置"}
  42. c.ServeJSON()
  43. return
  44. }
  45. awardTimes, _ := c.GetInt64("awardTimes")
  46. expireTime := c.GetString("expireTime")
  47. items := c.GetString("items")
  48. u := new(models.ExchangeCodeInfo)
  49. u.Pcode = pcode
  50. u.AwardTimes = awardTimes
  51. u.ExpireTime = utils.GetTime64(expireTime)
  52. var eItems []*models.ExchangeItemsInfo
  53. err := json.Unmarshal([]byte(items), &eItems)
  54. if err != nil {
  55. log.Printf("ExchangeCodeController items[%s] err[%v]", items, err)
  56. c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()}
  57. c.ServeJSON()
  58. return
  59. }
  60. u.Items = eItems
  61. err = models.AddExchangeCodeInfo(u)
  62. if err != nil {
  63. c.Data["json"] = &map[string]interface{}{"status": false, "info": err.Error()}
  64. c.ServeJSON()
  65. return
  66. }
  67. c.Data["json"] = &map[string]interface{}{"status": true, "info": "新增兑换码成功"}
  68. c.ServeJSON()
  69. }
  70. func (c *ExchangeCodeController) Put() {
  71. userinfo := c.GetSession("user")
  72. if userinfo == nil {
  73. c.Ctx.Redirect(302, "/accountlogin")
  74. return
  75. }
  76. u := new(models.HotfixInfo)
  77. u.Id, _ = c.GetInt64("id")
  78. u.Channel, _ = c.GetInt64("channel")
  79. u.Version = c.GetString("version")
  80. u.DowloadAddr = c.GetString("addr")
  81. u.FileSize = c.GetString("filesize")
  82. _, err := models.UpdateHotfixInfo(u)
  83. if err != nil {
  84. c.Data["json"] = &map[string]interface{}{"status": false, "info": err}
  85. c.ServeJSON()
  86. return
  87. }
  88. c.Data["json"] = &map[string]interface{}{"status": true, "info": "更新热更新参数成功"}
  89. c.ServeJSON()
  90. }
  91. func (c *ExchangeCodeController) Delete() {
  92. userinfo := c.GetSession("user")
  93. if userinfo == nil {
  94. c.Ctx.Redirect(302, "/accountlogin")
  95. return
  96. }
  97. id, _ := c.GetInt64("id")
  98. cp := models.GetHotfixInfoById(id)
  99. if cp == nil {
  100. c.Data["json"] = &map[string]interface{}{"status": false, "info": "参数不存在"}
  101. c.ServeJSON()
  102. return
  103. }
  104. models.DelHotfixInfoById(id)
  105. c.Data["json"] = &map[string]interface{}{"status": true, "info": "删除热更新参成功"}
  106. c.ServeJSON()
  107. }