diff --git a/controllers/client/login.go b/controllers/client/login.go index 42f818a..96d68bc 100644 --- a/controllers/client/login.go +++ b/controllers/client/login.go @@ -126,7 +126,7 @@ func (t *UserCtl) WxLogin() { t.CheckErr(err) t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在") - realSignExist, err := new(models.RealSignList).CheckSignIn(user.Id, activityId) + realSignExist, err := new(models.RealSignHistory).Check(user.Id, activity.Id, activity.RehearsalId) t.CheckErr(err) jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, customer.Id, customer.Pid, area.Id, activityId, user.Nickname) diff --git a/controllers/client/sign.go b/controllers/client/sign.go index 5f19219..90aa2e8 100644 --- a/controllers/client/sign.go +++ b/controllers/client/sign.go @@ -1,6 +1,7 @@ package client import ( + "encoding/json" "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" "hudongzhuanjia/controllers" @@ -99,35 +100,67 @@ func (t *SignCtl) Sign() { 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, "签到活动不存在") - realSignList := new(models.RealSignList) - exist, err = realSignList.CheckSignIn(uid, aid) + history := new(models.RealSignHistory) + isSign, err := history.Info(uid, aid, rid) t.CheckErr(err) - if !exist && (sign.RealSignJsonForm != "" && sign.RealSignJsonForm != "[]") { + 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 { - _, err = realSignList.SignIn(uid, aid, extSql) + 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_SIGN_REAL_NOT_EXIST) + t.ERROR("填写内容不能为空", code.MSG_ERR) return } t.SUCCESS("实名签到成功") return } else { - t.SUCCESS("签到成功") + t.ERROR("实名签到活动不存在", code.MSG_SIGN_REAL_NOT_EXIST) return } } diff --git a/controllers/pc/sign.go b/controllers/pc/sign.go index 2c31bd8..0a0d345 100644 --- a/controllers/pc/sign.go +++ b/controllers/pc/sign.go @@ -66,13 +66,14 @@ type SignResult struct { //处理签到信息 func (t *SignCtl) SignInfo() { - activityId := t.MustGetInt64("activity_id") + aid := t.MustGetActivityId() + //activityId := t.MustGetInt64("activity_id") rehearsalId := t.MustGetInt64("rehearsal_id") result := make([]*SignResult, 0) session := core.GetXormAuto().Table(new(models.SignHistory)).Alias("h"). Join("LEFT", new(models.User).Alias("u"), "h.user_id=u.id and u.is_delete=0"). - Where("h.is_delete=0 and h.activity_id=? and rehearsal_id=?", activityId, rehearsalId) + Where("h.is_delete=0 and h.activity_id=? and rehearsal_id=?", aid, rehearsalId) if t.PageSize > 0 { // 增加分页 session.Limit(t.PageSize, t.Page*t.PageSize) } @@ -85,3 +86,27 @@ func (t *SignCtl) SignInfo() { "sign_up_total": count, }) } + +// 实名签到信息 +func (t *SignCtl) RealSignInfo() { + aid := t.MustGetActivityId() + rid := t.MustGetInt64("rehearsal_id") + results := make([]*models.RealSignHistory, 0) + err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? status=0", + aid, rid).Asc("updated_at").Find(results) + t.CheckErr(err) + t.JSON(map[string]interface{}{ + "result": results, + "count": len(results), + }) +} + +func (t *SignCtl) RealSignReward() { + id := t.MustGetInt64("real_sign_history_id") // 获取历史信息 + + history := new(models.RealSignHistory) + history.Status = 1 + err := history.UpdateById(id, "status") + t.CheckErr(err) + t.SUCCESS("审核成功") +} diff --git a/go.sum b/go.sum index 6bd17fd..e9d413f 100644 --- a/go.sum +++ b/go.sum @@ -69,8 +69,10 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= +github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE= @@ -177,6 +179,7 @@ github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3 github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= @@ -247,8 +250,10 @@ github.com/tealeg/xlsx v1.0.3/go.mod h1:uxu5UY2ovkuRPWKQ8Q7JG0JbSivrISjdPzZQKeo7 github.com/tencentyun/cos-go-sdk-v5 v0.0.0-20190926121715-a33db3b0dede h1:4FiecrX2TsfWVkXozpV2JOOI09KvC4jD1JotxY2bSnQ= github.com/tencentyun/cos-go-sdk-v5 v0.0.0-20190926121715-a33db3b0dede/go.mod h1:wk2XFUg6egk4tSDNZtXeKfe2G6690UVyt163PuUxBZk= github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= +github.com/ugorji/go v1.1.5-pre h1:jyJKFOSEbdOc2HODrf2qcCkYOdq7zzXqA9bhW5oV4fM= github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0= github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/ugorji/go/codec v1.1.5-pre h1:5YV9PsFAN+ndcCtTM7s60no7nY7eTG3LPtxhSwuxzCs= github.com/ugorji/go/codec v1.1.5-pre/go.mod h1:tULtS6Gy1AE1yCENaw4Vb//HLH5njI2tfCQDUqRd8fI= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/wailovet/db2struct v0.0.0-20190220022639-a297dc96489a h1:RndWCoBQ9Ltyj1m46BmGexEv3ZU8hPjV3fGo1xxh07A= diff --git a/main b/main new file mode 100644 index 0000000..d7ea2be Binary files /dev/null and b/main differ diff --git a/models/real_sign_history.go b/models/real_sign_history.go new file mode 100644 index 0000000..489817f --- /dev/null +++ b/models/real_sign_history.go @@ -0,0 +1,49 @@ +package models + +import ( + "github.com/ouxuanserver/osmanthuswine/src/core" + "time" +) + +const RealSignHistoryTN = TableNamePrefix + "real_sign_history" + +type RealSignHistory struct { + Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动') INT(11)"` + UserId int64 `json:"user_id" xorm:"not null default 0 comment('用户id') INT(11)"` + Nickname string `json:"nickname" xorm:"not null default('') comment('微信昵称') VARCHAR(128)"` + RehearsalId int64 `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id') INT(11)"` + Content string `json:"content" xorm:"not null comment('提交审核的内容') TEXT"` + Status int64 `json:"status" xorm:"not null default 0 comment('是否通过审核') TINY(1)"` + IsDelete int `json:"is_delete" xorm:"not null default(0) comment('是否删除') TINY(1)"` + CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"` + UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') TIMESTAMP"` +} + +func (t *RealSignHistory) TableName() string { + return RealSignHistoryTN +} + +func (t *RealSignHistory) Info(uid, aid, rid int64) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=?", + uid, aid, rid).Get(t) +} + +func (t *RealSignHistory) Check(uid, aid, rid int64) (bool, error) { + return core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=? and rehearsal_id=? and status=1", + uid, aid, rid).Get(t) +} + +func (t *RealSignHistory) UpdateById(id int64, fields ...string) (err error) { + if len(fields) > 0 { + _, err = core.GetXormAuto().ID(id).Cols(fields...).Update(t) + } else { + + _, err = core.GetXormAuto().ID(id).AllCols().Update(t) + } + return err +} +func (t *RealSignHistory) Insert() error { + _, err := core.GetXormAuto().InsertOne(t) + return err +} diff --git a/models/real_sign_list.go b/models/real_sign_list.go index d0514fc..3260ec0 100644 --- a/models/real_sign_list.go +++ b/models/real_sign_list.go @@ -3,17 +3,15 @@ package models import ( "fmt" "github.com/ouxuanserver/osmanthuswine/src/core" - "github.com/pkg/errors" "time" ) const RealSignListTN = TableNamePrefix + "real_sign_list" type RealSignList struct { - Id int64 `json:"id"` - ActivityId int64 `json:"activity_id"` - JsonList string `json:"json_list"` - UserId int64 `json:"user_id"` + Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"` + ActivityId int64 `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"` + JsonList string `json:"json_list" xorm:"not null comment('名单记录') TEXT"` IsDelete bool `json:"is_delete" xorm:"default(0)" description:"是否删除"` CreatedAt time.Time `json:"created_at" xorm:"created" description:"创建时间"` UpdatedAt time.Time `json:"updated_at" xorm:"updated" description:"更新时间"` @@ -23,15 +21,13 @@ func (t *RealSignList) TableName() string { return RealSignListTN } -func (t *RealSignList) CheckSignIn(uid int64, aid int64) (bool, error) { - exist, err := core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=?", uid, aid).Exist(t) - return exist, errors.WithStack(err) -} +//func (t *RealSignList) CheckSignIn(uid int64, aid int64) (bool, error) { +// exist, err := core.GetXormAuto().Where("is_delete=0 and user_id=? and activity_id=?", uid, aid).Exist(t) +// return exist, errors.WithStack(err) +//} // 可能使用模糊匹配 -func (t *RealSignList) SignIn(uid, aid int64, ext string) (int64, error) { - t.UserId = uid - - var sql = fmt.Sprintf("is_delete=0 and user_id=0 and activity_id=%d %s", aid, ext) - return core.GetXormAuto().Where(sql).Cols("user_id").Update(t) +func (t *RealSignList) CheckSignIn(aid int64, ext string) (bool, error) { + var sql = fmt.Sprintf("is_delete=0 and activity_id=%d %s", aid, ext) + return core.GetXormAuto().Where(sql).Get(t) } diff --git a/models/sign_history.go b/models/sign_history.go index 9bfdb51..6744517 100644 --- a/models/sign_history.go +++ b/models/sign_history.go @@ -5,7 +5,7 @@ import ( "time" ) -const SignHistoryTableName = TableNamePrefix + "sign_history" +const SignHistoryTN = TableNamePrefix + "sign_history" //签到历史表 type SignHistory struct { @@ -22,7 +22,7 @@ type SignHistory struct { } func (t *SignHistory) TableName() string { - return SignHistoryTableName + return SignHistoryTN } func (t *SignHistory) GetByUserId(aid, uid, rid, arid int64) (bool, error) { diff --git a/utils/code/code.go b/utils/code/code.go index 2e42314..7968135 100644 --- a/utils/code/code.go +++ b/utils/code/code.go @@ -42,6 +42,7 @@ const ( MSG_SIGN_UP_REHEARSAL_LIMIT = 5002 // 签到彩排人数限制 MSG_SIGN_REAL_EXIST = 5003 // 实名签到存在 MSG_SIGN_REAL_NOT_EXIST = 5004 // 实名签到json_list 不存在 + MSG_SIGN_REAL_DATA_NOT_EXIST = 5005 // 实名签到json_list 不存在 MSG_BULLY_SCREEN_SERVER_NOT_EXIST = 6000 // 霸屏 不存在 MSG_BARRAGE_SERVER_NOT_EXIST = 6001 // 弹幕 不存在 MSG_REWARD_NOT_EXIST = 6002 // 打赏不存