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

98 lines
2.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package client
  2. import (
  3. "hudongzhuanjia/controllers"
  4. "hudongzhuanjia/models"
  5. "hudongzhuanjia/utils/code"
  6. "time"
  7. )
  8. type InvitationLetterCtl struct {
  9. controllers.AuthorCtl
  10. }
  11. func (t *InvitationLetterCtl) Invite() {
  12. uid := t.GetAccountId()
  13. activityId := t.MustGetInt("activity_id")
  14. invitationId := t.MustGetInt("invitation_id")
  15. answer := t.MustGet("answer")
  16. activity := new(models.Activity)
  17. exist, err := models.Get(activity, activityId)
  18. t.CheckErr(err)
  19. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  20. area := new(models.AreaStore)
  21. exist, err = area.GetByCustomerId(activity.CustomerId, activity.Id)
  22. t.CheckErr(err)
  23. t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
  24. customer := new(models.Customer)
  25. exist, err = models.Get(customer, activity.CustomerId)
  26. t.CheckErr(err)
  27. t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
  28. letter := new(models.InvitationLetter)
  29. exist, err = letter.GetByUserIdAndActivityId(uid, activity.Id, activity.ArchId, activity.RehearsalId)
  30. t.CheckErr(err)
  31. t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
  32. letter.UserId = uid
  33. letter.ActivityId = activityId
  34. letter.InvitationId = invitationId
  35. letter.RehearsalId = activity.RehearsalId
  36. letter.ExtraData = answer
  37. letter.ArchId = activity.ArchId
  38. letter.IsDelete = false
  39. letter.CreatedAt = time.Now()
  40. letter.UpdatedAt = time.Now()
  41. _, err = models.Add(letter)
  42. t.CheckErr(err)
  43. sign := new(models.SignUp)
  44. exist, err = sign.GetByActivityId(activityId)
  45. t.CheckErr(err)
  46. t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
  47. history := new(models.SignHistory)
  48. signExist, err := history.GetByUserId(activityId, activity.ArchId, uid, activity.RehearsalId, area.Id)
  49. t.CheckErr(err)
  50. if customer.IsSpecial == 1 || customer.IsSpecial == 3 {
  51. if signExist {
  52. history = new(models.SignHistory)
  53. history.UserId = uid
  54. history.RehearsalId = activity.RehearsalId
  55. history.ActivityId = activityId
  56. history.SignRuleId = sign.Id
  57. history.AreaId = area.Id
  58. history.ArchId = activity.ArchId
  59. history.Status = 2
  60. _, err = models.Add(history)
  61. t.CheckErr(err)
  62. }
  63. }
  64. t.SUCCESS("success")
  65. }
  66. func (t *InvitationLetterCtl) Setting() {
  67. activityId := t.MustGetInt("activity_id")
  68. uid := t.GetAccountId()
  69. activity := new(models.Activity)
  70. exist, err := models.Get(activity, activityId)
  71. t.CheckErr(err)
  72. t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
  73. letter := new(models.InvitationLetter)
  74. exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.ArchId, activity.RehearsalId)
  75. t.CheckErr(err)
  76. t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
  77. invitation := new(models.Invitation)
  78. exist, err = invitation.GetInvitationByActivityId(activityId)
  79. t.CheckErr(err)
  80. t.Assert(exist, code.MSG_INVITE_SETTING_NOT_EXIST, "邀请函设置不存在")
  81. t.JSON(map[string]interface{}{
  82. "setting": invitation,
  83. })
  84. }