Browse Source

fix:bug

token_replace
Tooooommy 4 years ago
parent
commit
685ba61fb9
  1. 2
      controllers/author.go
  2. 28
      controllers/client/login.go
  3. 13
      controllers/pc/sign.go
  4. 29
      models/sign_history.go

2
controllers/author.go

@ -42,8 +42,10 @@ func (t *AuthorCtl) Prepare() {
var param = make(map[string]interface{}, 0)
err := t.RequestToStruct(&param)
t.CheckErr(err)
if param[define.TOKEN] != nil {
token = param[define.TOKEN].(string)
}
}
if token == "" {
t.ERROR("token失效", code.MSG_ERR_Authority)

28
controllers/client/login.go

@ -166,22 +166,29 @@ func (t *UserCtl) WxLogin() {
func (t *UserCtl) Login() {
wxcode := t.MustGet("code")
activityId := t.MustGetInt("activity_id")
areaId := t.MustGetInt("area_id")
activity := &models.Activity{}
exist, err := models.Get(activity, activityId)
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
area := &models.AreaStore{}
exist, err = models.Get(area, areaId)
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
if activity.MoreAreaMode == define.StatusClose && area.IsMainArea != 1 {
t.ERROR("地区信息错误", code.MSG_AREASTORE_NOT_EXIST)
}
//user := new(models.User)
token, err := wechat.GetToken(wxcode)
t.CheckErr(err)
//user.Openid = token.OpenId
//exist, err := user.GetUserByOpenid(user.Openid)
//t.CheckErr(err)
//if !exist {
// _, err = models.Add(user)
// t.CheckErr(err)
//}
info, err := wechat.GetUserInfo(token)
t.CheckErr(err)
user := new(models.User)
exist, err := user.GetUserByOpenid(info.OpenId)
exist, err = user.GetUserByOpenid(info.OpenId)
t.CheckErr(err)
if user.Token == "" {
user.Token = utils.GenToken(user.Openid)
@ -203,9 +210,7 @@ func (t *UserCtl) Login() {
}
t.CheckErr(err)
area := &models.AreaStore{}
admin := 0
if activityId, ok := t.GetInt("activity_id"); ok && activityId != 0 {
if username, ok := t.Get("username"); ok && username != "" {
username := t.MustGet("username")
password := t.MustGet("password")
@ -225,7 +230,6 @@ func (t *UserCtl) Login() {
admin = 1
}
}
}
//jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, 0, 0, 0, 0)
//t.CheckErr(err)

13
controllers/pc/sign.go

@ -81,16 +81,7 @@ func (t *SignCtl) SignInfo() {
t.CheckErr(err)
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
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=? and arch_id=?",
activity.Id, activity.RehearsalId, activity.ArchId)
if t.PageSize > 0 { // 增加分页
session.Limit(t.PageSize, t.Page*t.PageSize)
}
count, err := session.FindAndCount(&result)
count, result, err := models.GetSignHistories(activity.Id, activity.RehearsalId, activity.ArchId, t.Page, t.PageSize)
t.CheckErr(err)
t.JSON(map[string]interface{}{
@ -110,12 +101,14 @@ func (t *SignCtl) RealSignInfo() {
results, err := models.GetApplyRealSigns(activity.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
t.JSON(map[string]interface{}{
"result": results,
"count": len(results),
})
}
// 审核实名签到
func (t *SignCtl) RealSignVerify() {
ids := strings.Split(t.MustGet("real_sign_history_ids"), ",")
history := new(models.SignHistory)

29
models/sign_history.go

@ -1,8 +1,6 @@
package models
import (
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
@ -10,7 +8,12 @@ const SignHistoryTN = TableNamePrefix + "sign_history"
//签到历史表
type SignHistory struct {
Id int `json:"id" xorm:"pk autoincr comment('主键') INT(11)"`
Model `xorm:"extends"`
//Id int `json:"id" xorm:"pk autoincr comment('主键') INT(11)"`
//IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)"`
//CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
//UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
AreaId int `json:"area_id" xorm:"not null default 0 comment('地区id') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
ActivityId int `json:"activity_id" xorm:"not null default 0 comment('主活动id') INT(11)"`
@ -22,9 +25,6 @@ type SignHistory struct {
Content string `json:"content" xorm:"json comment('提交审核的内容') TEXT"`
Nickname string `json:"nickname" xorm:"not null default('') comment('微信昵称') VARCHAR(128)"`
Status int `json:"status" xorm:"not null default 0 comment('是否通过审核[0未通过审核1申请审核2通过审核]') TINYINT(1)"`
IsDelete bool `json:"is_delete" xorm:"not null default(0) comment('删除') TINYINT(1)"`
CreatedAt time.Time `json:"created_at" xorm:"not null created comment('创建时间') DATETIME"`
UpdatedAt time.Time `json:"updated_at" xorm:"not null updated comment('更新时间') DATETIME"`
}
func (t *SignHistory) TableName() string {
@ -58,3 +58,20 @@ func GetApplyRealSigns(activityId, archId, rehearsalId interface{}) ([]*SignHist
" and status=1", activityId, archId, rehearsalId).Asc("updated_at").Find(&results)
return results, err
}
type SignHistoryAndUser struct {
SignHistory `xorm:"extends"`
User *User `json:"user" xorm:"extends"`
}
func GetSignHistories(activityId, rehearsalId, archId, page, size int) (total int64, result []*SignHistoryAndUser, err error) {
session := core.GetXormAuto().Table(new(SignHistory)).Alias("h").
Join("LEFT", new(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=? and arch_id=?",
activityId, rehearsalId, archId)
if size > 0 { // 增加分页
session.Limit(size, page*size)
}
total, err = session.FindAndCount(&result)
return
}
Loading…
Cancel
Save