package client import ( "encoding/json" "fmt" "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) CheckSign() { activityId := t.MustGetInt64("activity_id") uid := t.MustGetUID() _type := t.MustGetInt("type") if _type == 1 { live := new(models.LiveConfig) exist, err := live.GetByActivityId(activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "直播活动不存在") if live.LiveMode == 2 { var num = 0 if live.LimitType == 1 { // 累计人数->可以重复进入 viewer := new(models.LiveViewer) exist, err := viewer.ExistByUserId(uid, live.Id) t.CheckErr(err) if !exist { count, err := models.CountLiveViewerByLiveConfigId(live.Id) t.CheckErr(err) num = int(count) } } else if live.LimitType == 2 { num = live.WatchNum + 1 } if num >= live.Limit { t.ERROR("直播人数已满", code.MSG_LIVE_LIMIT_ENOUGH) return } } err = new(models.LiveViewer).Record(uid, activityId, live.Id) t.CheckErr(err) if live.AdaptationFunc != nil && len(live.AdaptationFunc) != 0 { exist, err = new(models.ModuleServiceHistory).ExistSignModule(live.AdaptationFunc) t.CheckErr(err) if !exist { t.JSON(true) } } 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) if !signExist || history.Status != 2 { t.JSON(false) } else { t.JSON(true) } } 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 } sign := new(models.SignUp) exist, err = sign.GetByActivityId(activityId) t.JSON(map[string]interface{}{ "phone_bg": phoneBg, "setting": sign, }) } //签到动作 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.SignMethod != 1 { t.ERROR("非扫码签到", code.MSG_ERR_Param) return } 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, "您没收到邀请函") } //检查是否已经签到了 history := new(models.SignHistory) exist, err = history.GetByUserId(activityId, uid, activity.RehearsalId, area.Id) t.CheckErr(err) if exist || history.Status == 2 { t.ERROR("您已经签到过了", code.MSG_SIGN_HISTORY_EXIST) } // 签到人数 signTotal, err := history.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) } history = new(models.SignHistory) history.Type = _type history.UserId = uid history.RehearsalId = activity.RehearsalId history.ActivityId = activityId history.SignRuleId = signUp.Id history.AreaId = areaId history.Status = 2 history.IsDelete = false history.UpdatedAt = time.Now() history.CreatedAt = time.Now() _, err = models.Add(history) 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.MustGetUID() areaId := t.MustGetInt64("area_id") user := new(models.User) exist, err := models.Get(user, userId) t.CheckErr(err) t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") activity := new(models.Activity) exist, err = models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_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 == 2, code.MSG_ERR_Param, "非实名签到") history := new(models.SignHistory) isSign, err := history.GetByUserId(activityId, userId, activity.RehearsalId, areaId) t.CheckErr(err) if isSign && history.Status == 2 { t.SUCCESS("已通过实名签到") return } else if sign.RealSignJsonTitle != nil && len(sign.RealSignJsonTitle) != 0 { var params = make(map[string]string, 0) var extSql string for _, v := range sign.RealSignJsonTitle { m, ok := v.(map[string]interface{}) if !ok { continue } name, _ := m["name"].(string) val, _ := m["val"].(string) if value, ok := t.Get(name); ok { params[val] = value //extSql += " json_list like '%\"" + val + "\"" + ":" + "\"" + value + "\"%' and " extSql += " json_list like '%" + value + "%' and " } else { t.ERROR(fmt.Sprintf("%s不能为空", val), code.MSG_ERR_Param) } } if len(extSql) == 0 || len(params) == 0 { t.ERROR("提交内容不能为空", code.MSG_ERR_Param) return } realSignList := new(models.RealSignList) exist, err = realSignList.CheckSignIn(activityId, extSql) t.CheckErr(err) if exist && realSignList.Status == 1 { t.ERROR("实名签到名单已被认证", code.MSG_SIGN_REAL_NOT_EXIST) return } var body []byte body, err = json.Marshal(params) t.CheckErr(err) history.SignRuleId = sign.Id history.SignMethod = 2 history.ActivityId = activityId history.UserId = userId history.Nickname = user.Nickname history.RehearsalId = activity.RehearsalId history.AreaId = areaId history.Content = string(body) if exist { // 存在 直接通过 history.Status = 2 } 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 } t.SUCCESS("实名签到成功") return } else { t.ERROR("实名签到活动未上传名单", code.MSG_SIGN_REAL_NOT_EXIST) return } } func (t *SignCtl) ApplySign() { userId := t.MustGetUID() areaId := t.MustGetAreaId() activityId := t.MustGetInt64("activity_id") activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") history := new(models.SignHistory) exist, err = history.GetByUserId(activityId, userId, activity.RehearsalId, areaId) t.CheckErr(err) t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到不存在") if history.Status == 2 { t.SUCCESS("你已经通过实名签到") return } history.Status = 1 _, err = models.Update(history.Id, history, "status") t.CheckErr(err) t.SUCCESS("申请成功") } func (t *SignCtl) CheckRealSign() { userId := t.MustGetUID() areaId := t.MustGetInt64("area_id") activityId := t.MustGetInt64("activity_id") activity := new(models.Activity) exist, err := models.Get(activity, activityId) t.CheckErr(err) t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") history := new(models.SignHistory) exist, err = history.GetByUserId(activityId, userId, activity.RehearsalId, areaId) t.CheckErr(err) t.Assert(exist, code.MSG_SIGN_HISTORY_NOT_EXIST, "签到信息不存在") if history.Status == 2 { t.SUCCESS("签到成功") } t.ERROR("签到尚未审核", code.MSG_SIGN_HISTORY_NOT_EXIST) }