互动
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.

66 lines
1.9 KiB

5 years ago
5 years ago
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. func (t *InvitationLetterCtl) Invite() {
  13. uid := t.MustGetUID()
  14. activityId := t.MustGetInt64("activity_id")
  15. invitationId := t.MustGetInt64("invitation_id")
  16. answer := t.MustGet("answer")
  17. activity := new(models.Activity)
  18. exist, err := models.GetById(activity, activityId)
  19. t.CheckErr(err)
  20. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  21. letter := new(models.InvitationLetter)
  22. exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  23. t.CheckErr(err)
  24. t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
  25. letter.UserId = uid
  26. letter.ActivityId = activityId
  27. letter.InvitationId = invitationId
  28. letter.RehearsalId = activity.RehearsalId
  29. letter.ExtraData = answer
  30. letter.IsDelete = false
  31. letter.CreatedAt = time.Now()
  32. letter.UpdatedAt = time.Now()
  33. _, err = core.GetXormAuto().InsertOne(letter)
  34. t.CheckErr(err)
  35. t.STRING("success")
  36. }
  37. func (t *InvitationLetterCtl) Setting() {
  38. activityId := t.MustGetInt64("activity_id")
  39. uid := t.MustGetUID()
  40. activity := new(models.Activity)
  41. exist, err := models.GetById(activity, activityId)
  42. t.CheckErr(err)
  43. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  44. letter := new(models.InvitationLetter)
  45. exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
  46. t.CheckErr(err)
  47. t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
  48. invitation := new(models.Invitation)
  49. exist, err = invitation.GetInvitationByActivityId(activityId)
  50. t.CheckErr(err)
  51. t.Assert(exist, code.MSG_INVITE_SETTING_NOT_EXIST, "邀请函设置不存在")
  52. t.JSON(map[string]interface{}{
  53. "setting": invitation,
  54. })
  55. }