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

65 lines
1.8 KiB

package client
import (
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
"hudongzhuanjia/utils/code"
"time"
)
type InvitationLetterCtl struct {
controllers.AuthorCtl
}
func (t *InvitationLetterCtl) Invite() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
invitationId := t.MustGetInt64("invitation_id")
answer := t.MustGet("answer")
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
letter := new(models.InvitationLetter)
exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
letter.UserId = uid
letter.ActivityId = activityId
letter.InvitationId = invitationId
letter.RehearsalId = activity.RehearsalId
letter.ExtraData = answer
letter.IsDelete = false
letter.CreatedAt = time.Now()
letter.UpdatedAt = time.Now()
_, err = models.Add(letter)
t.CheckErr(err)
t.SUCCESS("success")
}
func (t *InvitationLetterCtl) Setting() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
activity := new(models.Activity)
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
letter := new(models.InvitationLetter)
exist, err = letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(!exist, code.MSG_INVITE_LETTER_EXIST, "您已经接受过邀请")
invitation := new(models.Invitation)
exist, err = invitation.GetInvitationByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_INVITE_SETTING_NOT_EXIST, "邀请函设置不存在")
t.JSON(map[string]interface{}{
"setting": invitation,
})
}