|
|
package client
import ( "encoding/json" "fmt" "hudongzhuanjia/controllers" "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.Get(&activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "主活动不存在")
customer := models.Customer{} exist, err = models.Get(&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, "签到模块不存在") historyIds, err := models.GetModuleServiceHistoryIdsByIdAndName(service.Id, service.Name) t.CheckErr(err)
module := new(models.ActivityModuleService) exist, err = module.GetByActivityIdAndHistoryIds(activityId, historyIds) 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.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := new(models.AreaStore) exist, err = models.Get(area, areaId) t.CheckErr(err) t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
user := new(models.User) exist, err = models.Get(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 && _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, area.Id) t.CheckErr(err) t.Assert(!exist, code.MSG_SIGN_HISTORY_EXIST, "您已经签到过了") // 存在判断
// 签到人数
signTotal, err := signHistory.Count(signUp.Id, activity.RehearsalId, activity.Id) t.CheckErr(err)
signUpTotal, err := new(models.InvitationLetter).Count(activity.Id, activity.RehearsalId) 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 = models.Add(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() { activityId := t.MustGetInt64("activity_id") userId := t.MustGetInt64("user_id") rehearsalId := t.MustGetInt64("rehearsal_id") areaId := t.MustGetAreaId()
user := new(models.User) exist, err := models.Get(user, userId) t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")
sign := new(models.SignUp) exist, err = sign.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在") t.Assert(sign.SignMethod != 1, code.MSG_ERR_Param, "非实名签到")
history := new(models.SignHistory) isSign, err := history.GetByUserId(activityId, userId, rehearsalId, areaId) 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(activityId, extSql) var body []byte body, err = json.Marshal(params) t.CheckErr(err)
history.ActivityId = activityId history.UserId = userId history.Nickname = user.Nickname history.RehearsalId = rehearsalId history.AreaId = areaId history.Content = string(body) if exist { // 存在 直接通过
history.Status = 1 } else { history.Status = 0 } 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 } }
|