special_award.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. "go-common/app/admin/main/growup/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/http/blademaster"
  10. "go-common/library/net/http/blademaster/binding"
  11. )
  12. func awardAdd(c *blademaster.Context) {
  13. username, _, err := checkCookie(c)
  14. if err != nil {
  15. c.JSON(nil, err)
  16. return
  17. }
  18. arg := new(model.AddAwardArg)
  19. if err = c.BindWith(arg, binding.JSON); err != nil {
  20. return
  21. }
  22. awardID, err := svr.AddAward(c, arg, username)
  23. if err != nil {
  24. log.Error("svr.AddAward err(%v)", err)
  25. c.JSON(nil, err)
  26. return
  27. }
  28. c.JSON(awardID, nil)
  29. }
  30. func awardUpdate(c *blademaster.Context) {
  31. arg := new(model.SaveAwardArg)
  32. if err := c.BindWith(arg, binding.JSON); err != nil {
  33. return
  34. }
  35. err := svr.UpdateAward(c, arg)
  36. if err != nil {
  37. log.Error("svr.UpdateAward err(%v)", err)
  38. c.JSON(nil, err)
  39. return
  40. }
  41. c.JSON(true, nil)
  42. }
  43. func awardList(c *blademaster.Context) {
  44. arg := new(struct {
  45. From int `form:"from" validate:"min=0" default:"0"`
  46. Limit int `form:"limit" validate:"min=1" default:"20"`
  47. })
  48. if err := c.Bind(arg); err != nil {
  49. return
  50. }
  51. total, list, err := svr.ListAward(c, arg.From, arg.Limit)
  52. if err != nil {
  53. log.Error("svr.ListAward err(%v)", err)
  54. c.JSON(nil, err)
  55. return
  56. }
  57. renderPagRes(list, total, arg.Limit)(c)
  58. }
  59. func awardDetail(c *blademaster.Context) {
  60. arg := new(struct {
  61. AwardID int64 `form:"award_id" validate:"required"`
  62. })
  63. if err := c.Bind(arg); err != nil {
  64. return
  65. }
  66. data, err := svr.DetailAward(c, arg.AwardID)
  67. if err != nil {
  68. log.Error("svr.DetailAward err(%v)", err)
  69. c.JSON(nil, err)
  70. return
  71. }
  72. c.JSON(data, nil)
  73. }
  74. func awardWinnerList(c *blademaster.Context) {
  75. arg := new(model.QueryAwardWinnerArg)
  76. if err := c.Bind(arg); err != nil {
  77. return
  78. }
  79. total, list, err := svr.ListAwardWinner(c, arg)
  80. if err != nil {
  81. log.Error("svr.ListAwardRecord err(%v)", err)
  82. c.JSON(nil, err)
  83. return
  84. }
  85. renderPagRes(list, total, arg.Limit)(c)
  86. }
  87. func awardWinnerExport(c *blademaster.Context) {
  88. arg := new(model.QueryAwardWinnerArg)
  89. if err := c.Bind(arg); err != nil {
  90. return
  91. }
  92. content, err := svr.ExportAwardWinner(c, arg)
  93. if err != nil {
  94. log.Error("svr.ExportAwardWinner err(%v)", err)
  95. c.JSON(nil, err)
  96. return
  97. }
  98. c.Render(http.StatusOK, CSV{
  99. Content: content,
  100. Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "award_winner"),
  101. })
  102. }
  103. func awardResult(c *blademaster.Context) {
  104. arg := new(struct {
  105. AwardID int64 `form:"award_id" validate:"required"`
  106. })
  107. if err := c.Bind(arg); err != nil {
  108. return
  109. }
  110. data, err := svr.AwardResult(c, arg.AwardID)
  111. if err != nil {
  112. log.Error("svr.AwardResult err(%v)", err)
  113. c.JSON(nil, err)
  114. return
  115. }
  116. c.JSON(data, nil)
  117. }
  118. func awardResultSave(c *blademaster.Context) {
  119. arg := new(model.AwardResult)
  120. if err := c.BindWith(arg, binding.JSON); err != nil {
  121. return
  122. }
  123. if arg.AwardID == 0 {
  124. c.JSON(false, ecode.Error(ecode.RequestErr, "illegal award_id"))
  125. return
  126. }
  127. err := svr.SaveAwardResult(c, arg)
  128. if err != nil {
  129. log.Error("svr.SaveAwardResult err(%v)", err)
  130. c.JSON(false, err)
  131. return
  132. }
  133. c.JSON(true, nil)
  134. }
  135. func awardWinnerReplace(c *blademaster.Context) {
  136. arg := new(struct {
  137. AwardID int64 `form:"award_id" validate:"required"`
  138. PrevMID int64 `form:"prev_mid" validate:"required"`
  139. MID int64 `form:"mid" validate:"required"`
  140. })
  141. if err := c.Bind(arg); err != nil {
  142. return
  143. }
  144. err := svr.ReplaceAwardWinner(c, arg.AwardID, arg.PrevMID, arg.MID)
  145. if err != nil {
  146. log.Error("svr.ReplaceAwardWinner err(%v)", err)
  147. c.JSON(false, err)
  148. return
  149. }
  150. c.JSON(true, nil)
  151. }