invite.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/account/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. // stat get invite stat.
  10. func inviteStat(c *bm.Context) {
  11. mid, _ := c.Get("mid")
  12. var err error
  13. var stat *model.RichInviteStat
  14. if stat, err = usSvc.Stat(c, mid.(int64)); err != nil {
  15. log.Error("memberService.Stat(%d) error(%v)", mid, err)
  16. c.JSON(nil, err)
  17. return
  18. }
  19. c.JSON(stat, nil)
  20. }
  21. // buy buy invite code.
  22. func buy(c *bm.Context) {
  23. mid, _ := c.Get("mid")
  24. var err error
  25. var num int64
  26. req := c.Request.Form
  27. numStr := req.Get("num")
  28. if num, err = strconv.ParseInt(numStr, 10, 64); err != nil {
  29. c.JSON(nil, ecode.RequestErr)
  30. return
  31. }
  32. geeParam := new(model.GeeCheckRequest)
  33. if err = c.Bind(geeParam); err != nil {
  34. return
  35. }
  36. geeParam.MID = mid.(int64)
  37. if isPass := geetestSvr.Validate(c, geeParam); !isPass {
  38. c.JSON(nil, ecode.CaptchaErr)
  39. return
  40. }
  41. var invs []*model.RichInvite
  42. if invs, err = usSvc.Buy(c, mid.(int64), num); err != nil {
  43. log.Error("memberService.Buy(%d, %d) error(%v)", mid, num, err)
  44. c.JSON(nil, err)
  45. return
  46. }
  47. c.JSON(invs, nil)
  48. }
  49. // apply apply invite code.
  50. func apply(c *bm.Context) {
  51. mid, _ := c.Get("mid")
  52. var err error
  53. var num int64
  54. code := c.Request.Form.Get("invite_code")
  55. if code == "" {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. if err = usSvc.Apply(c, mid.(int64), code, c.Request.Header.Get("Cookie")); err != nil {
  60. log.Error("memberService.Apply(%d, %d) error(%v)", mid, num, err)
  61. c.JSON(nil, err)
  62. return
  63. }
  64. c.JSON(nil, nil)
  65. }