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

96 lines
3.0 KiB

package client
import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/models"
ws_send_service "hudongzhuanjia/services/ws_send"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"time"
)
//签到
type SignCtl struct {
controllers.AuthorCtl
}
//签到动作
func (t *SignCtl) Sign() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
customerId := t.MustGetInt64("customer_id")
//根据activity_id查找主活动的信息
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
customer := new(models.Customer)
exist, err = models.GetById(customer, customerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
user := new(models.User)
exist, err = models.GetById(user, uid)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
//根据activity_id查找副活动的规则信息
signUp := new(models.SignUp)
exist, err = signUp.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "签到规则不存在")
if signUp.OnlyInvitation == 1 { //
// 邀请函才能签到
letter := new(models.InvitationLetter)
exist, err := letter.GetByUserIdAndActivityId(uid, activityId, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_INVITE_LETTER_NOT_EXIST, "您没收到邀请函")
}
//检查是否已经签到了
signHistory := new(models.SignHistory)
exist, err = signHistory.GetByUserId(activityId, uid, activity.RehearsalId, t.MustGetAreaId())
t.CheckErr(err)
t.Assert(!exist, code.MSG_SIGN_HISTORY_EXIST, "您已经签到过了") // 存在判断
// 签到人数
signTotal, err := core.GetXormAuto().Where("is_delete=0 and sign_rule_id=? and rehearsal_id=? and activity_id=?",
signUp.Id, activity.RehearsalId, activity.Id).Count(signHistory)
t.CheckErr(err)
signUpTotal, err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activity.Id).Count(new(models.InvitationLetter))
t.CheckErr(err)
if activity.RehearsalId != 0 && signTotal >= 10 {
t.ERROR("彩排人数不能超过10人", code.MSG_SIGN_UP_REHEARSAL_LIMIT)
}
signHistory = new(models.SignHistory)
signHistory.UserId = uid
signHistory.RehearsalId = activity.RehearsalId
signHistory.ActivityId = activityId
signHistory.SignRuleId = signUp.Id
signHistory.AreaId = user.AreaId
signHistory.IsDelete = false
signHistory.UpdatedAt = time.Now()
signHistory.CreatedAt = time.Now()
_, err = core.GetXormAuto().InsertOne(signHistory)
t.CheckErr(err)
go ws_send_service.SendSign(fmt.Sprintf("%d", activity.Id),
define.TYPE_CUSTOMER, customerId, map[string]interface{}{
"type": "sign_up",
"customer_id": customer.Id,
"data": map[string]interface{}{
"avatar": user.Avatar,
"sign_total": signTotal + 1,
"sign_up_total": signUpTotal,
},
})
t.SUCCESS("签到成功")
}