medal.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. package http
  2. import (
  3. "fmt"
  4. "strconv"
  5. "go-common/app/admin/main/usersuit/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // medal.
  11. func medalList(c *bm.Context) {
  12. var (
  13. err error
  14. res []*model.MedalInfo
  15. )
  16. if res, err = svc.Medal(c); err != nil {
  17. httpCode(c, err)
  18. return
  19. }
  20. httpData(c, res, nil)
  21. }
  22. // medalView .
  23. func medalView(c *bm.Context) {
  24. arg := new(struct {
  25. ID int64 `form:"id" validate:"required"`
  26. })
  27. if err := c.Bind(arg); err != nil {
  28. return
  29. }
  30. var (
  31. err error
  32. np *model.MedalInfo
  33. )
  34. if np, err = svc.MedalView(c, arg.ID); err != nil {
  35. httpCode(c, err)
  36. return
  37. }
  38. np.Image = "http://i0.hdslb.com" + np.Image
  39. np.ImageSmall = "http://i0.hdslb.com" + np.ImageSmall
  40. httpData(c, np, nil)
  41. }
  42. // medalAdd add medal .
  43. func medalAdd(c *bm.Context) {
  44. var (
  45. err error
  46. )
  47. arg := new(model.Medal)
  48. if err = c.Bind(arg); err != nil {
  49. return
  50. }
  51. if err = svc.AddMedal(c, arg); err != nil {
  52. httpCode(c, err)
  53. return
  54. }
  55. httpCode(c, nil)
  56. }
  57. func medalEdit(c *bm.Context) {
  58. var (
  59. err error
  60. )
  61. arg := new(model.Medal)
  62. if err = c.Bind(arg); err != nil {
  63. return
  64. }
  65. if err = svc.UpMedal(c, arg.ID, arg); err != nil {
  66. httpCode(c, err)
  67. return
  68. }
  69. httpCode(c, nil)
  70. }
  71. func medalGroup(c *bm.Context) {
  72. var (
  73. err error
  74. res []*model.MedalGroup
  75. )
  76. if res, err = svc.MedalGroupInfo(c); err != nil {
  77. httpCode(c, err)
  78. return
  79. }
  80. httpData(c, res, nil)
  81. }
  82. func medalGroupView(c *bm.Context) {
  83. arg := new(struct {
  84. ID int64 `form:"id" validate:"required"`
  85. })
  86. if err := c.Bind(arg); err != nil {
  87. return
  88. }
  89. var (
  90. err error
  91. res *model.MedalGroup
  92. )
  93. if res, err = svc.MedalGroupByGid(c, arg.ID); err != nil {
  94. httpCode(c, err)
  95. return
  96. }
  97. httpData(c, res, nil)
  98. }
  99. func medalGroupParent(c *bm.Context) {
  100. var (
  101. err error
  102. res []*model.MedalGroup
  103. )
  104. if res, err = svc.MedalGroupParent(c); err != nil {
  105. httpCode(c, err)
  106. return
  107. }
  108. httpData(c, res, nil)
  109. }
  110. func medalGroupAdd(c *bm.Context) {
  111. var (
  112. err error
  113. )
  114. arg := new(model.MedalGroup)
  115. if err = c.Bind(arg); err != nil {
  116. return
  117. }
  118. if err = svc.MedalGroupAdd(c, arg); err != nil {
  119. httpCode(c, err)
  120. return
  121. }
  122. httpCode(c, nil)
  123. }
  124. func medalGroupEdit(c *bm.Context) {
  125. var (
  126. err error
  127. )
  128. arg := new(model.MedalGroup)
  129. if err = c.Bind(arg); err != nil {
  130. return
  131. }
  132. if err = svc.MedalGroupUp(c, arg.ID, arg); err != nil {
  133. httpCode(c, err)
  134. return
  135. }
  136. httpCode(c, nil)
  137. }
  138. func medalMemberMID(c *bm.Context) {
  139. arg := new(struct {
  140. MID int64 `form:"mid" validate:"required"`
  141. })
  142. if err := c.Bind(arg); err != nil {
  143. return
  144. }
  145. var (
  146. err error
  147. res []*model.MedalMemberMID
  148. )
  149. if res, err = svc.MedalOwner(c, arg.MID); err != nil {
  150. httpCode(c, err)
  151. return
  152. }
  153. httpData(c, res, nil)
  154. }
  155. func medalOwnerUpActivated(c *bm.Context) {
  156. arg := new(struct {
  157. ID int64 `form:"id" validate:"required"`
  158. MID int64 `form:"mid" validate:"required"`
  159. })
  160. if err := c.Bind(arg); err != nil {
  161. return
  162. }
  163. var (
  164. err error
  165. )
  166. if err = svc.MedalOwnerUpActivated(c, arg.MID, arg.ID); err != nil {
  167. httpCode(c, err)
  168. return
  169. }
  170. httpCode(c, nil)
  171. }
  172. func medalMemberAddList(c *bm.Context) {
  173. arg := new(struct {
  174. MID int64 `form:"mid" validate:"required"`
  175. })
  176. if err := c.Bind(arg); err != nil {
  177. return
  178. }
  179. var (
  180. err error
  181. res []*model.MedalMemberAddList
  182. )
  183. if res, err = svc.MedalOwnerAddList(c, arg.MID); err != nil {
  184. httpCode(c, err)
  185. return
  186. }
  187. httpData(c, res, nil)
  188. }
  189. func medalMemberAdd(c *bm.Context) {
  190. arg := new(struct {
  191. MID int64 `form:"mid" validate:"required"`
  192. NID int64 `form:"nid" validate:"required"`
  193. Title string `form:"title"`
  194. Message string `form:"message"`
  195. OID int64 `form:"oper_id" validate:"required"`
  196. })
  197. if err := c.Bind(arg); err != nil {
  198. return
  199. }
  200. var (
  201. err error
  202. )
  203. if err = svc.MedalOwnerAdd(c, arg.MID, arg.NID, arg.Title, arg.Message, arg.OID); err != nil {
  204. httpCode(c, err)
  205. return
  206. }
  207. httpCode(c, nil)
  208. }
  209. func medalMemberDel(c *bm.Context) {
  210. arg := new(struct {
  211. MID int64 `form:"mid" validate:"required"`
  212. NID int64 `form:"nid" validate:"required"`
  213. IsDel int8 `form:"is_del"`
  214. Title string `form:"title"`
  215. Message string `form:"message"`
  216. })
  217. if err := c.Bind(arg); err != nil {
  218. return
  219. }
  220. var (
  221. err error
  222. )
  223. if err = svc.MedalOwnerDel(c, arg.MID, arg.NID, arg.IsDel, arg.Title, arg.Message); err != nil {
  224. httpCode(c, err)
  225. return
  226. }
  227. httpCode(c, nil)
  228. }
  229. func medalBatchAdd(c *bm.Context) {
  230. var (
  231. err error
  232. nid int64
  233. )
  234. f, h, err := c.Request.FormFile("file")
  235. if err != nil {
  236. httpCode(c, ecode.RequestErr)
  237. return
  238. }
  239. defer f.Close()
  240. params := c.Request.Form
  241. nidStr := params.Get("nid")
  242. nid, err = strconv.ParseInt(nidStr, 10, 64)
  243. if err != nil || nid <= 0 {
  244. fmt.Printf("nid:%+v\n", nid)
  245. httpCode(c, ecode.RequestErr)
  246. return
  247. }
  248. msg, err := svc.BatchAdd(c, nid, f, h)
  249. if err != nil || msg != "" {
  250. log.Error("svc.BatchAdd error(%v), msg(%v)", err, msg)
  251. httpCode(c, ecode.ServerErr)
  252. return
  253. }
  254. res := new(struct {
  255. Message string `form:"message"`
  256. })
  257. res.Message = msg
  258. httpData(c, res, nil)
  259. }
  260. func medalOperlog(c *bm.Context) {
  261. arg := new(struct {
  262. PN int `form:"pn"`
  263. PS int `form:"ps"`
  264. MID int64 `form:"mid" validate:"required"`
  265. })
  266. arg.PN, arg.PS = 1, 20
  267. if err := c.Bind(arg); err != nil {
  268. return
  269. }
  270. opers, pager, err := svc.MedalOperlog(c, arg.MID, arg.PN, arg.PS)
  271. if err != nil {
  272. log.Error("svc.MedalOperlog(%+v) err(%v)", arg, err)
  273. httpCode(c, err)
  274. return
  275. }
  276. if len(opers) == 0 {
  277. httpData(c, nil, pager)
  278. return
  279. }
  280. httpData(c, opers, pager)
  281. }