Browse Source

fix:bug

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

4
controllers/author.go

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

58
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,27 +210,24 @@ 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")
exist, err := area.Login(activityId, username, password)
if username, ok := t.Get("username"); ok && username != "" {
username := t.MustGet("username")
password := t.MustGet("password")
exist, err := area.Login(activityId, username, password)
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR_Authority, "不存在地区管理员")
if area.UserId != user.Id {
area.UserId = user.Id
_, err = models.Update(area.Id, area, "user_id")
t.CheckErr(err)
t.Assert(exist, code.MSG_ERR_Authority, "不存在地区管理员")
if area.UserId != user.Id {
area.UserId = user.Id
_, err = models.Update(area.Id, area, "user_id")
t.CheckErr(err)
}
}
admin = 1
} else {
exist, err := area.GetByUserId(activityId, user.Id)
t.CheckErr(err)
if exist { // 管理员
admin = 1
} else {
exist, err := area.GetByUserId(activityId, user.Id)
t.CheckErr(err)
if exist { // 管理员
admin = 1
}
}
}

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)

51
models/sign_history.go

@ -1,8 +1,6 @@
package models
import (
"time"
"github.com/ouxuanserver/osmanthuswine/src/core"
)
@ -10,21 +8,23 @@ const SignHistoryTN = TableNamePrefix + "sign_history"
//签到历史表
type SignHistory struct {
Id int `json:"id" xorm:"pk autoincr comment('主键') INT(11)"`
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)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0正式') INT(11)"`
SignRuleId int `json:"sign_rule_id" xorm:"not null default 0 comment('sign_up表id') INT(11)"`
Type int `json:"type" xorm:"not null default 0 comment('普通签到') TINYINT(1)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户表id') TINYINT(11)"`
SignMethod int `json:"sign_method" xorm:"not null default 0 comment('1扫码签到2实名签到3人脸签到') TINYINT(1)"`
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"`
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)"`
RehearsalId int `json:"rehearsal_id" xorm:"not null default 0 comment('彩排id/ 0正式') INT(11)"`
SignRuleId int `json:"sign_rule_id" xorm:"not null default 0 comment('sign_up表id') INT(11)"`
Type int `json:"type" xorm:"not null default 0 comment('普通签到') TINYINT(1)"`
UserId int `json:"user_id" xorm:"not null default 0 comment('用户表id') TINYINT(11)"`
SignMethod int `json:"sign_method" xorm:"not null default 0 comment('1扫码签到2实名签到3人脸签到') TINYINT(1)"`
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)"`
}
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