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

248 lines
7.4 KiB

package client
import (
"encoding/json"
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
ws_send_service "hudongzhuanjia/services/ws_send"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"strings"
"time"
)
//签到
type SignCtl struct {
controllers.AuthorCtl
}
func (t *SignCtl) CheckSign() {
activityId := t.MustGetInt64("activity_id")
uid := t.MustGetUID()
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在")
if live.AdaptationFunc != nil && len(live.AdaptationFunc) != 0 {
exist, err = new(models.ModuleServiceHistory).ExistSignModule(live.AdaptationFunc)
t.CheckErr(err)
if !exist {
t.JSON(!exist)
}
} else {
t.JSON(true)
}
activity := models.Activity{}
exist, err = models.GetById(&activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "主活动不存在")
customer := models.Customer{}
exist, err = models.GetById(&customer, activity.CustomerId)
t.CheckErr(err)
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在")
area := new(models.AreaStore)
if customer.AreaId == 0 {
exist, err = area.GetMainAreaById(activityId)
} else {
exist, err = area.GetAreaStoreById(customer.AreaId)
}
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
history := new(models.SignHistory)
signExist, err := history.GetByUserId(activityId, uid, activity.RehearsalId, area.Id)
t.CheckErr(err)
t.JSON(signExist)
}
func (t *SignCtl) Setting() {
activityId := t.MustGetInt64("activity_id")
service := new(models.ModuleService)
exist, err := service.GetByName(define.MODULE_SIGNIN)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
histories := make([]*models.ModuleServiceHistory, 0)
err = core.GetXormAuto().Where("is_delete=0 and service_module_id=? and name=?", service.Id, service.Name).Find(&histories)
t.CheckErr(err)
historyIds := make([]int64, 0)
for _, history := range histories {
historyIds = append(historyIds, history.Id)
}
module := new(models.ActivityModuleService)
exist, err = core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).In("service_module_history_id", historyIds).Get(module)
t.CheckErr(err)
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "签到模块不存在")
phoneBg := ""
if module.PhoneBgSwitch == define.StatusOpen {
phoneBg = module.PhoneBgUrl
}
t.JSON(map[string]interface{}{
"phone_bg": phoneBg,
})
}
//签到动作
func (t *SignCtl) Sign() {
uid := t.MustGetUID()
activityId := t.MustGetInt64("activity_id")
_type := t.DefaultInt("type", 0) // 默认 0
areaId := t.MustGetAreaId()
//根据activity_id查找主活动的信息
activity := new(models.Activity)
exist, err := models.GetById(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := new(models.AreaStore)
exist, err = models.GetById(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
user := new(models.User)
exist, err = models.GetById(user, uid)
logger.Error("user:===>%+v", user)
logger.Error("token:==>%v", t.MustGet("token"))
logger.Error("user_id:===>%v", 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 && _type == 0 { // 直播不需要进行邀请函
// 邀请函才能签到
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.Type = _type
signHistory.UserId = uid
signHistory.RehearsalId = activity.RehearsalId
signHistory.ActivityId = activityId
signHistory.SignRuleId = signUp.Id
signHistory.AreaId = 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, activity.CustomerId, map[string]interface{}{
"type": "sign_up",
"customer_id": area.CustomerId,
"data": map[string]interface{}{
"avatar": user.Avatar,
"sign_total": signTotal + 1,
"sign_up_total": signUpTotal,
},
})
t.SUCCESS("签到成功")
}
func (t *SignCtl) RealSign() {
aid := t.MustGetInt64("activity_id")
uid := t.MustGetInt64("user_id")
rid := t.MustGetInt64("rehearsal_id")
user := new(models.User)
exist, err := user.GetById(uid)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
sign := new(models.SignUp)
exist, err = sign.GetByActivityId(aid)
t.CheckErr(err)
t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
history := new(models.RealSignHistory)
isSign, err := history.Info(uid, aid, rid)
t.CheckErr(err)
if isSign && history.Status == 1 {
t.SUCCESS("已通过实名签到")
return
} else if sign.RealSignJsonForm != "" && sign.RealSignJsonForm != "[]" {
form := sign.RealSignJsonForm[1 : len(sign.RealSignJsonForm)-1]
var extSql = ""
var params = make(map[string]string, 0)
for _, v := range strings.Split(form, ",") {
name := strings.Trim(v, "\"")
if value, ok := t.Get(name); ok {
extSql += "and json_list like \"%" + value + "%\" "
params[name] = value
}
}
if len(extSql) > 0 {
exist, err = new(models.RealSignList).CheckSignIn(aid, extSql)
var body []byte
body, err = json.Marshal(params)
t.CheckErr(err)
history.ActivityId = aid
history.UserId = uid
history.Nickname = user.Nickname
history.RehearsalId = rid
history.Content = string(body)
if exist { // 存在 直接通过
history.Status = 1
} else {
history.Status = 0
}
history.IsDelete = 0
history.CreatedAt = time.Now()
history.UpdatedAt = time.Now()
if isSign {
err = history.UpdateById([]interface{}{history.Id})
} else {
err = history.Insert()
}
t.CheckErr(err)
if !exist { // 找不到导入的签名信息
t.ERROR("您的信息不在名单之内", code.MSG_ERR)
return
}
} else {
t.ERROR("填写内容不能为空", code.MSG_ERR)
return
}
t.SUCCESS("实名签到成功")
return
} else {
t.ERROR("实名签到活动不存在", code.MSG_SIGN_REAL_NOT_EXIST)
return
}
}