互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6 KiB

5 years ago
  1. package client
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "hudongzhuanjia/controllers"
  5. "hudongzhuanjia/models"
  6. "hudongzhuanjia/utils/code"
  7. "time"
  8. )
  9. type InvitationLetterCtl struct {
  10. controllers.AuthorCtl
  11. }
  12. // InviteEnvelope doc
  13. // @Summary InviteEnvelope
  14. // @Description 填写要求信息
  15. // @Tags invite envelope
  16. // @Accept json
  17. // @Produce json
  18. // @Param activity_id query int true "邀请函内容"
  19. // @Success 0 {string} string "success"
  20. // @Failure 404 {string} string "参数不存在"
  21. // @Failure 405 {string} string "用户不存在"
  22. // @Router /Client/InviteEnvelopeCtl/invite [post]
  23. func (t *InvitationLetterCtl) Invite() {
  24. uid := t.MustGetUID()
  25. activityId := t.MustGetActivityId()
  26. invitationId := t.MustGetInt64("invitation_id")
  27. answer := t.MustGet("answer")
  28. activity := new(models.Activity)
  29. exist, err := models.GetById(activity, activityId)
  30. t.CheckErr(err)
  31. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  32. letter := new(models.InvitationLetter)
  33. exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  34. t.CheckErr(err)
  35. t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
  36. letter.UserId = uid
  37. letter.ActivityId = activityId
  38. letter.InvitationId = invitationId
  39. letter.RehearsalId = activity.RehearsalId
  40. letter.ExtraData = answer
  41. letter.IsDelete = false
  42. letter.CreatedAt = time.Now()
  43. letter.UpdatedAt = time.Now()
  44. _, err = core.GetXormAuto().InsertOne(letter)
  45. t.CheckErr(err)
  46. t.STRING("success")
  47. }
  48. // InviteEnvelope doc
  49. // @Summary InviteEnvelope
  50. // @Description get invite envelope setting
  51. // @Tags invite envelope
  52. // @Accept json
  53. // @Produce json
  54. // @Param activity_id query int true "Activity ID"
  55. // @Success 0 {object} models.Invitation
  56. // @Failure 404 {string} string "参数不存在"
  57. // @Failure 405 {string} string "用户不存在"
  58. // @Router /Client/InviteEnvelopeCtl/setting [get]
  59. func (t *InvitationLetterCtl) Setting() {
  60. activityId := t.MustGetActivityId()
  61. uid := t.MustGetUID()
  62. activity := new(models.Activity)
  63. exist, err := models.GetById(activity, activityId)
  64. t.CheckErr(err)
  65. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  66. letter := new(models.InvitationLetter)
  67. exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  68. t.CheckErr(err)
  69. t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
  70. invitation := new(models.Invitation)
  71. exist, err = invitation.GetInvitationByActivityId(activityId)
  72. t.CheckErr(err)
  73. t.Assert(exist, code.MSG_INVITE_SETTING_NOT_EXIST, "邀请函设置不存在")
  74. t.JSON(map[string]interface{}{
  75. "setting": invitation,
  76. })
  77. }