|
|
package client
import ( "hudongzhuanjia/controllers" "hudongzhuanjia/models" "hudongzhuanjia/utils/code" "time" )
type InvitationLetterCtl struct { controllers.AuthorCtl }
func (t *InvitationLetterCtl) Invite() { uid := t.GetAccountId() activityId := t.MustGetInt("activity_id") invitationId := t.MustGetInt("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, "互动不存在")
area := new(models.AreaStore) exist, err = area.GetByCustomerId(activity.CustomerId, activity.Id) t.CheckErr(err) t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
customer := new(models.Customer) exist, err = models.Get(customer, activity.CustomerId) t.CheckErr(err) t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
letter := new(models.InvitationLetter) exist, err = letter.GetByUserIdAndActivityId(uid, activity.Id, activity.ArchId, 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.ArchId = activity.ArchId letter.IsDelete = false letter.CreatedAt = time.Now() letter.UpdatedAt = time.Now() _, err = models.Add(letter) t.CheckErr(err)
sign := new(models.SignUp) exist, err = sign.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在") history := new(models.SignHistory) signExist, err := history.GetByUserId(activityId, activity.ArchId, uid, activity.RehearsalId, area.Id) t.CheckErr(err) if customer.IsSpecial == 1 || customer.IsSpecial == 3 { if signExist { history = new(models.SignHistory) history.UserId = uid history.RehearsalId = activity.RehearsalId history.ActivityId = activityId history.SignRuleId = sign.Id history.AreaId = area.Id history.ArchId = activity.ArchId history.Status = 2 _, err = models.Add(history) t.CheckErr(err) } }
t.SUCCESS("success") }
func (t *InvitationLetterCtl) Setting() { activityId := t.MustGetInt("activity_id") uid := t.GetAccountId()
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.ArchId, 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, }) }
|