package client import ( "encoding/json" "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" "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) 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("签到成功") } func (t *SignCtl) RealSign() { aid := t.MustGetActivityId() uid := t.MustGetUID() rid := t.MustGetInt64("rehearsal_id") 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 = t.MustGetName() 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(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 } }