Browse Source

fix;bug

token_replace
黄梓健 5 years ago
parent
commit
211a00884a
  1. 2
      controllers/client/activity.go
  2. 6
      controllers/client/calorie.go
  3. 4
      controllers/pc/calorie.go
  4. 30
      models/CalorieUser.go
  5. 7
      models/bahe_team_member.go
  6. 2
      models/calorie.go
  7. 4
      models/tug_of_war.go
  8. 6
      services/bahe/tug_war.go
  9. 11
      services/calorie/calorie.go

2
controllers/client/activity.go

@ -42,7 +42,7 @@ func (t *ActivityCtl) ModuleCurrent() {
var data map[string]interface{}
switch moduleName {
case define.MODULE_TUGWAR: // 拔河
data, err = bahe_service.GetCurrentTugWar(activityId, uid, activity.RehearsalId)
data, err = bahe_service.GetCurrentTugWar(activity.Id, activity.ArchId, uid, activity.RehearsalId)
case define.MODULE_CALORIE: // 卡路里
data, err = calorie_service.GetCurrentCalorie(activityId, uid, activity.RehearsalId)
case define.MODULE_SHAKRB: // 摇红包

6
controllers/client/calorie.go

@ -29,7 +29,7 @@ func (t *CalorieCtl) Shake() {
t.CheckRunning(activity.Status)
calorieUser := new(models.CalorieUser)
exist, err = calorieUser.GetByCalorieIdAndUserId(calorieId, uid, activity.RehearsalId)
exist, err = calorieUser.GetByCalorieIdAndUserId(calorieId, activity.ArchId, uid, activity.RehearsalId)
t.CheckErr(err)
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "您尚未参与卡路里活动")
@ -40,10 +40,10 @@ func (t *CalorieCtl) Shake() {
calorieUser.Score += int64(score) // 增加
}
count, err := calorieUser.CountByCalorieId(calorie.Id, activity.RehearsalId)
count, err := calorieUser.CountByCalorieId(calorie.Id, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
users, err := models.GetCalorieUsersByCalorieIdAndScore(calorie.Id, activity.RehearsalId, calorieUser.Score)
users, err := models.GetCalorieUsersByCalorieIdAndScore(calorie.Id, activity.ArchId, activity.RehearsalId, calorieUser.Score)
t.CheckErr(err)
var rank int

4
controllers/pc/calorie.go

@ -136,11 +136,11 @@ func (t *CalorieCtl) Count() {
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "卡路里不存在")
// 统计人数
count, err := new(models.CalorieUser).Count(calorieId, activity.RehearsalId)
count, err := new(models.CalorieUser).Count(calorieId, activity.ArchId, activity.RehearsalId)
t.CheckErr(err)
// 统计排名
result, err := calorie_service.RankCalorieUser(calorieId, activity.RehearsalId, limit)
result, err := calorie_service.RankCalorieUser(calorieId, activity.ArchId, activity.RehearsalId, limit)
t.CheckErr(err)
t.JSON(map[string]interface{}{

30
models/CalorieUser.go

@ -10,8 +10,7 @@ const CalorieUserTableName = TableNamePrefix + "calorie_user"
type CalorieUser struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ActivityId int64 `json:"activity_id" xorm:"not null comment('互动id') INT(11)"`
Avatar string `json:"avatar" xorm:"-"`
Nickname string `json:"nickname" xorm:"-"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
UserId int64 `json:"user_id" xorm:"not null comment('用户表id') INT(11)"`
CalorieId int64 `json:"calorie_id" xorm:"not null comment('calorie表id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id') INT(11)"`
@ -20,14 +19,19 @@ type CalorieUser struct {
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 default(CURRENT_TIMESTAMP) updated comment('创建时间') TIMESTAMP"`
// 无关变量
Avatar string `json:"avatar" xorm:"-"`
Nickname string `json:"nickname" xorm:"-"`
}
func (t *CalorieUser) TableName() string {
return CalorieUserTableName
}
func (t *CalorieUser) GetByCalorieIdAndUserId(cid, uid, rid int64) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and user_id=? and rehearsal_id=?", cid, uid, rid).Get(t)
func (t *CalorieUser) GetByCalorieIdAndUserId(calorieId, archId, userId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and user_id=? and rehearsal_id=?",
calorieId, archId, userId, rehearsalId).Get(t)
}
func (t *CalorieUser) IncrScore(archId, id, score interface{}) (int64, error) {
@ -36,19 +40,19 @@ func (t *CalorieUser) IncrScore(archId, id, score interface{}) (int64, error) {
Cols("score", "join_time").Incr("score", score).Update(t)
}
func (t *CalorieUser) CountByCalorieId(calorieId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?",
calorieId, rehearsalId).Count(&CalorieUser{})
func (t *CalorieUser) CountByCalorieId(calorieId, archId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?",
calorieId, archId, rehearsalId).Count(&CalorieUser{})
}
func GetCalorieUsersByCalorieIdAndScore(calorieId, rehearsalId, score interface{}) ([]*CalorieUser, error) {
func GetCalorieUsersByCalorieIdAndScore(calorieId, archId, rehearsalId, score interface{}) ([]*CalorieUser, error) {
users := make([]*CalorieUser, 0)
err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=? and score<=?",
calorieId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users)
err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=? and score<=?",
calorieId, archId, rehearsalId, score).Desc("score").Asc("join_time").Find(&users)
return users, err
}
func (t *CalorieUser) Count(calorieId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?",
calorieId, rehearsalId).Count(t)
func (t *CalorieUser) Count(calorieId, archId, rehearsalId interface{}) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and calorie_id=? and arch_id=? and rehearsal_id=?",
calorieId, archId, rehearsalId).Count(t)
}

7
models/bahe_team_member.go

@ -11,12 +11,12 @@ const BaheTeamMemberTableName = TableNamePrefix + "bahe_team_member"
//拔河队伍人员
type BaheTeamMember struct {
Id int64 `json:"id" xorm:"not null pk autoincr INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
BaheActivityId int64 `json:"bahe_activity_id" xorm:"not null default(0) comment('拔河活動id') BIGINT(20)"`
TeamId int64 `json:"team_id" xorm:"not null default(0) comment('队伍id') BIGINT(20)"`
TeamName string `json:"team_name" xorm:"not null default('') comment('队伍名字') VARCHAR(255)"`
MemberId int64 `json:"member_id" xorm:"not null comment('用户id') BIGINT(20)"`
Score int64 `json:"score" xorm:"not null default(0) comment('分数') INT(11)"`
ArchId int `json:"arch_id" xorm:"not null default 0 comment('归档id') INT(11)"`
RehearsalId int64 `json:"rehearsal_id" xorm:"not null default(0) comment('彩排id/0正式') BIGINT(20)"`
Avatar string `json:"avatar" xorm:"not null comment('头像') VARCHAR(255)"`
NickName string `json:"nick_name" xorm:"not null comment('昵称') VARCHAR(255)"`
@ -34,8 +34,9 @@ func (t *BaheTeamMember) Alias(name string) string {
return Alias(t, name)
}
func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(uid, bid, rid int64) (bool, error) {
return core.GetXormAuto().Where("member_id=? and bahe_activity_id=? and rehearsal_id=? and is_delete=0", uid, bid, rid).Get(t)
func (t *BaheTeamMember) GetMemberByBaheIdAndUserId(archId, userId, baheId, rehearsalId interface{}) (bool, error) {
return core.GetXormAuto().Where("arch_id=? and member_id=? and bahe_activity_id=? "+
" and rehearsal_id=? and is_delete=0", archId, userId, baheId, rehearsalId).Get(t)
}
func (t *BaheTeamMember) IncrScoreById(archId, id, score interface{}) (int64, error) {

2
models/calorie.go

@ -36,7 +36,7 @@ func (t *Calorie) UpdateStatusById(id int64, status string) (int64, error) {
return core.GetXormAuto().Where("is_delete=0 and id=?", id).Cols("status", "start_time", "updated_at").Update(t)
}
func (t *Calorie) GetCurrent(aid int64) (bool, error) {
func (t *Calorie) GetCurrent(aid interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
aid, define.StatusReady, define.StatusRunning).Desc("created_at").Get(t)
}

4
models/tug_of_war.go

@ -27,9 +27,9 @@ func (t *TugOfWar) GetByActivityId(aid int64, status string) (bool, error) {
Desc("created_at").Get(t)
}
func (t *TugOfWar) GetCurrent(aid int64) (bool, error) {
func (t *TugOfWar) GetCurrent(activityId interface{}) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and activity_id=? and (status=? or status=?)",
aid, define.StatusReady, define.StatusRunning).Get(t)
activityId, define.StatusReady, define.StatusRunning).Get(t)
}
func (t *TugOfWar) UpdateStatusById(id int64, status string) (int64, error) {

6
services/bahe/tug_war.go

@ -31,9 +31,9 @@ func GetMember(bid, rid, uid int64) (*models.BaheTeamMember, bool, error) {
return member, exist, err
}
func GetCurrentTugWar(aid, uid, rid int64) (map[string]interface{}, error) {
func GetCurrentTugWar(activityId, archId, uid, rehearsalId interface{}) (map[string]interface{}, error) {
bahe := new(models.TugOfWar)
exist, err := bahe.GetCurrent(aid)
exist, err := bahe.GetCurrent(activityId)
if err != nil {
return nil, err
}
@ -42,7 +42,7 @@ func GetCurrentTugWar(aid, uid, rid int64) (map[string]interface{}, error) {
}
member := new(models.BaheTeamMember)
exist, err = member.GetMemberByBaheIdAndUserId(uid, bahe.Id, rid)
exist, err = member.GetMemberByBaheIdAndUserId(archId, uid, bahe.Id, rehearsalId)
if err != nil {
return nil, err
}

11
services/calorie/calorie.go

@ -7,7 +7,7 @@ import (
"time"
)
func GetCurrentCalorie(aid, uid, rid int64) (map[string]interface{}, error) {
func GetCurrentCalorie(aid, uid, rid int64, archId interface{}) (map[string]interface{}, error) {
calorie := new(models.Calorie)
exist, err := calorie.GetCurrent(aid)
if err != nil {
@ -17,7 +17,7 @@ func GetCurrentCalorie(aid, uid, rid int64) (map[string]interface{}, error) {
return nil, errors.New("轮次尚未开启")
}
calorieUser := new(models.CalorieUser)
exist, err = calorieUser.GetByCalorieIdAndUserId(calorie.Id, uid, rid)
exist, err = calorieUser.GetByCalorieIdAndUserId(calorie.Id, archId, uid, rid)
if err != nil {
return nil, err
}
@ -31,7 +31,8 @@ func GetCurrentCalorie(aid, uid, rid int64) (map[string]interface{}, error) {
calorieUser.JoinTime = time.Now().UnixNano()
calorieUser.CreatedAt = time.Now()
calorieUser.UpdatedAt = time.Now()
if _, err = core.GetXormAuto().InsertOne(calorieUser); err != nil {
_, err := models.Add(calorieUser)
if err != nil {
return nil, err
}
rank, err := core.GetXormAuto().Where("is_delete=0 and calorie_id=? and rehearsal_id=?",
@ -86,13 +87,13 @@ type CalorieCountResult struct {
Score int64 `json:"score"`
}
func RankCalorieUser(calorieId, rehearsalId interface{}, limit int) ([]*CalorieCountResult, error) {
func RankCalorieUser(calorieId, archId, rehearsalId interface{}, limit int) ([]*CalorieCountResult, error) {
// 统计排名
result := make([]*CalorieCountResult, 0)
err := core.GetXormAuto().Table(new(models.CalorieUser)).Alias("c").
Select("c.id, c.activity_id, c.calorie_id, c.user_id, u.avatar, u.nickname, c.score, c.join_time").
Join("LEFT", new(models.User).Alias("u"), "c.user_id=u.id and u.is_delete=0").
Where("c.is_delete=0 and c.calorie_id=? and c.rehearsal_id=?", calorieId, rehearsalId).
Where("c.is_delete=0 and c.calorie_id=? and c.arch_id=? and c.rehearsal_id=?", calorieId, archId, rehearsalId).
Limit(limit).Desc("c.score").Asc("c.join_time").Find(&result)
return result, err

Loading…
Cancel
Save