gameconfig.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // 实时数据
  2. package controllers
  3. import (
  4. "box-gm/models"
  5. "fmt"
  6. "log"
  7. "github.com/astaxie/beego"
  8. )
  9. type GameConfigController struct {
  10. beego.Controller
  11. }
  12. func (c *GameConfigController) Get() {
  13. userinfo := c.GetSession("user")
  14. if userinfo == nil {
  15. c.Ctx.Redirect(302, "/accountlogin")
  16. return
  17. }
  18. c.Data["username"] = userinfo.(*LoginInfo).Username
  19. c.Data["token"] = models.GetToken()
  20. userPermission := models.GetPermission(userinfo.(*LoginInfo).Username)
  21. if (userPermission & (1 << uint(models.ModelSystem))) == 0 {
  22. c.Ctx.Redirect(302, "/accountlogin")
  23. return
  24. }
  25. c.TplName = "gameconfig.tpl"
  26. }
  27. func (c *GameConfigController) Post() {
  28. userinfo := c.GetSession("user")
  29. log.Printf("GameConfigController Post userinfo[%v]", userinfo)
  30. if userinfo == nil {
  31. c.Ctx.Redirect(302, "/accountlogin")
  32. return
  33. }
  34. ty := c.GetString("ty")
  35. switch ty {
  36. case "items":
  37. models.UpdateItemConfig()
  38. case "goods":
  39. models.UpdateGoodsConfig()
  40. default:
  41. c.Data["json"] = &map[string]interface{}{"status": false, "info": fmt.Sprintf("更新失败:不支持类型%s", ty)}
  42. c.ServeJSON()
  43. return
  44. }
  45. c.Data["json"] = &map[string]interface{}{"status": true, "info": fmt.Sprintf("更新[%s]成功", ty)}
  46. c.ServeJSON()
  47. }