Browse Source

实名验证

master
黄梓健 5 years ago
parent
commit
c76baf90b7
  1. 25
      controllers/client/login.go
  2. 37
      controllers/client/sign.go
  3. 2
      go.mod
  4. 5
      log/hdzj.log
  5. 2
      models/customer.go
  6. 1
      models/init_models.go
  7. 37
      models/real_sign_list.go
  8. 25
      models/sign_up.go
  9. 12
      test/config_test.go
  10. 2
      utils/code/code.go

25
controllers/client/login.go

@ -121,25 +121,34 @@ func (t *UserCtl) WxLogin() {
if exist { // 存在数据
signIn = "已签到"
}
sign := new(models.SignUp)
exist, err = sign.GetByActivityId(activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_SIGN_UP_NOT_EXIST, "签到活动不存在")
realSignExist, err := new(models.RealSignList).CheckSignIn(user.Id, activityId)
t.CheckErr(err)
jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, customer.Id, customer.Pid, area.Id, activityId, user.Nickname)
t.CheckErr(err)
t.SetSession(define.TOKEN, jwtToken)
t.JSON(map[string]interface{}{
"user": user,
"token": jwtToken,
"activity": activity,
"sign_in": signIn,
"tag": "activity",
"user": user,
"token": jwtToken,
"activity": activity,
"sign_in": signIn,
"real_sign": realSignExist,
"real_sign_form": sign.RealSignJsonForm,
"tag": "activity",
})
}
// 模拟wx login
func (t *UserCtl) DebugLogin() {
uid := t.DefaultInt64("user_id", 19)
customerId := t.DefaultInt64("customer_id", 125)
activityId := t.DefaultInt64("activity_id", 592)
uid := t.DefaultInt64("user_id", 1)
customerId := t.DefaultInt64("customer_id", 1)
activityId := t.DefaultInt64("activity_id", 5)
user := new(models.User)
exist, err := models.GetById(user, uid)

37
controllers/client/sign.go

@ -8,6 +8,7 @@ import (
ws_send_service "hudongzhuanjia/services/ws_send"
"hudongzhuanjia/utils/code"
"hudongzhuanjia/utils/define"
"strings"
"time"
)
@ -94,3 +95,39 @@ func (t *SignCtl) Sign() {
})
t.SUCCESS("签到成功")
}
func (t *SignCtl) RealSign() {
aid := t.MustGetActivityId()
uid := t.MustGetUID()
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)
t.CheckErr(err)
if !exist && (sign.RealSignJsonForm != "" && sign.RealSignJsonForm != "[]") {
form := sign.RealSignJsonForm[1 : len(sign.RealSignJsonForm)-1]
var extSql = ""
for _, v := range strings.Split(form, ",") {
name := strings.Trim(v, "\"")
if value, ok := t.Get(name); ok {
extSql += "and json_list like \"%" + value + "%\" "
}
}
if len(extSql) > 0 {
_, err = realSignList.SignIn(uid, aid, extSql)
t.CheckErr(err)
} else {
t.ERROR("该用户实名签到数据不存在", code.MSG_SIGN_REAL_NOT_EXIST)
return
}
t.SUCCESS("实名签到成功")
return
} else {
t.SUCCESS("签到成功")
return
}
}

2
go.mod

@ -15,7 +15,7 @@ require (
github.com/kirinlabs/HttpRequest v0.1.5
github.com/ouxuanserver/osmanthuswine v0.0.0-20190916032555-480efadf4941
github.com/panjf2000/ants v4.0.2+incompatible
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9
github.com/smartystreets/goconvey v1.6.4
github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e

5
log/hdzj.log

@ -0,0 +1,5 @@
2020-03-09 12:12:48.883 ERROR logger/logger.go:92 check err {"error": "token invalid"}
2020-03-09 12:18:11.392 ERROR logger/logger.go:92 check err {"error": "token invalid"}
2020-03-09 12:19:33.431 ERROR logger/logger.go:92 check err {"error": "Error 1054: Unknown column 'user_id' in 'field list'", "errorVerbose": "Error 1054: Unknown column 'user_id' in 'field list'\nhudongzhuanjia/models.(*RealSignList).CheckSignIn\n\tE:/GoProject/src/hd/models/real_sign_list.go:27\nhudongzhuanjia/controllers/client.(*SignCtl).RealSign\n\tE:/GoProject/src/hd/controllers/client/sign.go:109\nreflect.Value.call\n\tE:/Go/src/reflect/value.go:460\nreflect.Value.Call\n\tE:/Go/src/reflect/value.go:321\ngithub.com/ouxuanserver/osmanthuswine/src/core.(*RouterManage).RouterSend\n\tE:/GoProject/pkg/mod/github.com/ouxuanserver/osmanthuswine@v0.0.0-20190916032555-480efadf4941/src/core/router.go:111\ngithub.com/ouxuanserver/osmanthuswine.RunProg.func1\n\tE:/GoProject/pkg/mod/github.com/ouxuanserver/osmanthuswine@v0.0.0-20190916032555-480efadf4941/osmanthuswine.go:112\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi.(*Mux).routeHTTP\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/mux.go:425\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi/middleware.Timeout.func1.1\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/middleware/timeout.go:45\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi/middleware.Recoverer.func1\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/middleware/recoverer.go:35\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi/middleware.RequestLogger.func1.1\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/middleware/logger.go:46\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi/middleware.RealIP.func1\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/middleware/realip.go:34\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi/middleware.RequestID.func1\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/middleware/request_id.go:72\nnet/http.HandlerFunc.ServeHTTP\n\tE:/Go/src/net/http/server.go:2007\ngithub.com/go-chi/chi.(*Mux).ServeHTTP\n\tE:/GoProject/pkg/mod/github.com/go-chi/chi@v4.0.2+incompatible/mux.go:82\nnet/http.serverHandler.ServeHTTP\n\tE:/Go/src/net/http/server.go:2802\nnet/http.(*conn).serve\n\tE:/Go/src/net/http/server.go:1890\nruntime.goexit\n\tE:/Go/src/runtime/asm_amd64.s:1357"}
2020-03-09 12:23:40.321 ERROR logger/logger.go:92 check err {"error": "Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%json_list like %)' at line 1"}
2020-03-09 12:40:14.756 ERROR logger/logger.go:92 check err {"error": "Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%张三% and json_list like %张三% )' at line 1"}

2
models/customer.go

@ -32,7 +32,7 @@ type Customer struct {
QqOpenid string `json:"qq_openid" xorm:"not null default('') comment('qq openid') VARCHAR(255)"`
Tag string `json:"tag" xorm:"-" description:"tag ws过滤信息"`
Pid int64 `json:"pid" xorm:"not null default(0) comment('上级账号,该值为空时不允许登陆web客户端') INT(11)"` // 可能判断是否为子账号h
RoleId int64 `json:"role_id" xorm:"not null default(4) comment('1超级管理员2代理商3渠道会员4普通会员5地区子账号') INT(11)"`
RoleId int64 `json:"role_id" xorm:"not null default(4) comment('1超级管理员|2平台管理员|3普通管理员|4代理会员|5渠道会员|6普通会员') INT(11)"`
TopId int64 `json:"top_id" xorm:"not null default(0) comment('角色的上级id') INT(11)"`
IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`

1
models/init_models.go

@ -82,6 +82,7 @@ func init() {
new(UserOrder),
new(UserRefund),
new(UserRedPack),
new(RealSignList),
)
fmt.Printf("error=======>%v\n\n", err)
}

37
models/real_sign_list.go

@ -0,0 +1,37 @@
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"`
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:"更新时间"`
}
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) 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)
}

25
models/sign_up.go

@ -5,22 +5,25 @@ import (
"time"
)
const SignUpTableName = TableNamePrefix + "sign_up"
const SignUpTN = TableNamePrefix + "sign_up"
type SignUp struct {
Id int64 `json:"id"`
ActivityId int64 `json:"activity_id"`
Title string `json:"title"`
MaxModel string `json:"max_model"`
OnlyInvitation int `json:"only_invitation"`
LogoUrl string `json:"logo_url"`
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:"更新时间"`
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)"`
Title string `json:"title"`
MaxModel string `json:"max_model"`
OnlyInvitation int `json:"only_invitation"`
LogoUrl string `json:"logo_url"`
RealSignJsonForm string `json:"real_sign_json_form"`
RealSignJsonTitle string `json:"real_sign_json_title"`
RealSignListPath string `json:"real_sign_list_path"`
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:"更新时间"`
}
func (t *SignUp) TableName() string {
return SignUpTableName
return SignUpTN
}
func (t *SignUp) GetByActivityId(aid int64) (bool, error) {

12
test/config_test.go

@ -6,7 +6,6 @@ import (
"github.com/ouxuanserver/osmanthuswine/src/helper"
"github.com/panjf2000/ants"
. "github.com/smartystreets/goconvey/convey"
"hudongzhuanjia/services/pay"
"hudongzhuanjia/utils"
"hudongzhuanjia/utils/define"
"math/rand"
@ -14,6 +13,7 @@ import (
"regexp"
"runtime"
"sort"
"strings"
"sync"
"testing"
"time"
@ -196,6 +196,12 @@ func TestDuration(t *testing.T) {
//}
func TestRefundRedPack(t *testing.T) {
res, err := pay_service.QueryRedPack("tDYW8edlzegSlVNaJMXsteZEeuVL")
fmt.Printf("%+v, %+v", res, err)
var a = `["姓名","电话"]`
fmt.Println(a[1 : len(a)-1])
as := strings.Split(a[1:len(a)-1], ",")
fmt.Printf("%+v\n", as)
fmt.Println(strings.Trim(as[1], "\"") == "电话")
fmt.Println(as[0] == "电话")
//res, err := pay_service.QueryRedPack("tDYW8edlzegSlVNaJMXsteZEeuVL")
//fmt.Printf("%+v, %+v", res, err)
}

2
utils/code/code.go

@ -40,6 +40,8 @@ const (
MSG_SIGN_UP_NOT_EXIST = 5000 // 签到规则不存在
MSG_SIGN_HISTORY_EXIST = 5001 // 签到存在
MSG_SIGN_UP_REHEARSAL_LIMIT = 5002 // 签到彩排人数限制
MSG_SIGN_REAL_EXIST = 5003 // 实名签到存在
MSG_SIGN_REAL_NOT_EXIST = 5004 // 实名签到json_list 不存在
MSG_BULLY_SCREEN_SERVER_NOT_EXIST = 6000 // 霸屏 不存在
MSG_BARRAGE_SERVER_NOT_EXIST = 6001 // 弹幕 不存在
MSG_REWARD_NOT_EXIST = 6002 // 打赏不存

Loading…
Cancel
Save