app_medal.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package http
  2. import (
  3. mdMdl "go-common/app/interface/main/creative/model/medal"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "strconv"
  7. )
  8. func appMedalStatus(c *bm.Context) {
  9. // check user
  10. midStr, _ := c.Get("mid")
  11. mid := midStr.(int64)
  12. if mid <= 0 {
  13. c.JSON(nil, ecode.CreativeNotLogin)
  14. return
  15. }
  16. st, err := mdSvc.Medal(c, mid)
  17. if err == ecode.Int(510002) {
  18. st = &mdMdl.Medal{
  19. UID: strconv.FormatInt(mid, 10),
  20. LiveStatus: "0",
  21. MasterStatus: "0",
  22. Status: "0",
  23. }
  24. err = nil
  25. }
  26. if err != nil {
  27. c.JSON(nil, err)
  28. return
  29. }
  30. c.JSON(st, nil)
  31. }
  32. func appMedalCheck(c *bm.Context) {
  33. req := c.Request
  34. params := req.Form
  35. name := params.Get("medal_name")
  36. // check user
  37. midStr, _ := c.Get("mid")
  38. mid := midStr.(int64)
  39. if mid <= 0 {
  40. c.JSON(nil, ecode.CreativeNotLogin)
  41. return
  42. }
  43. if name == "" {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. valid, err := mdSvc.CheckMedal(c, mid, name)
  48. if err != nil {
  49. c.JSON(nil, err)
  50. return
  51. }
  52. c.JSON(map[string]interface{}{
  53. "valid": valid,
  54. }, nil)
  55. }
  56. func appMedalOpen(c *bm.Context) {
  57. req := c.Request
  58. params := req.Form
  59. name := params.Get("medal_name")
  60. // check user
  61. midStr, _ := c.Get("mid")
  62. mid := midStr.(int64)
  63. if mid <= 0 {
  64. c.JSON(nil, ecode.CreativeNotLogin)
  65. return
  66. }
  67. if name == "" {
  68. c.JSON(nil, ecode.RequestErr)
  69. return
  70. }
  71. err := mdSvc.OpenMedal(c, mid, name)
  72. if err != nil {
  73. c.JSON(nil, err)
  74. return
  75. }
  76. c.JSON(nil, nil)
  77. }
  78. func appMedalRename(c *bm.Context) {
  79. req := c.Request
  80. params := c.Request.Form
  81. name := params.Get("medal_name")
  82. cookie := req.Header.Get("cookie")
  83. ak := params.Get("access_key")
  84. // check user
  85. midStr, _ := c.Get("mid")
  86. mid := midStr.(int64)
  87. if mid <= 0 {
  88. c.JSON(nil, ecode.CreativeNotLogin)
  89. return
  90. }
  91. if name == "" {
  92. c.JSON(nil, ecode.RequestErr)
  93. return
  94. }
  95. code := mdSvc.Rename(c, mid, name, ak, cookie)
  96. c.JSON(nil, code)
  97. }