You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
6.8 KiB
232 lines
6.8 KiB
package pc
|
|
|
|
import (
|
|
"fmt"
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/utils"
|
|
"hudongzhuanjia/utils/code"
|
|
"hudongzhuanjia/utils/define"
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
type TugOfWarCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
func (t *TugOfWarCtl) Ready() { // 准备中
|
|
baheId := t.MustGetInt64("bahe_activity_id")
|
|
|
|
bahe := new(models.TugOfWar)
|
|
exist, err := models.Get(bahe, baheId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "拔河不存在")
|
|
if bahe.Status != define.StatusNotBegin {
|
|
t.ERROR(fmt.Sprintf("该活动%s", bahe.Status), code.MSG_ERR)
|
|
}
|
|
// done: 把其他的准备中的状态改为未开始
|
|
_, err = bahe.UpdateToStatusByAid(bahe.ActivityId, define.StatusReady, define.StatusNotBegin)
|
|
t.CheckErr(err)
|
|
|
|
// 创建队伍 只容许创建一次
|
|
redTeam := &models.BaheTeam{
|
|
BaheTeamName: "red",
|
|
ActivityId: bahe.ActivityId,
|
|
BaheActivityId: bahe.Id,
|
|
IsDelete: false,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
}
|
|
err = models.Save(map[string]interface{}{
|
|
"bahe_activity_id=": bahe.Id,
|
|
"is_delete=": 0,
|
|
"bahe_team_name=": define.TUGWAR_TEAM_RED,
|
|
}, redTeam)
|
|
t.CheckErr(err)
|
|
|
|
blueTeam := &models.BaheTeam{
|
|
BaheTeamName: "blue",
|
|
ActivityId: bahe.ActivityId,
|
|
BaheActivityId: bahe.Id,
|
|
IsDelete: false,
|
|
CreatedAt: time.Now(),
|
|
UpdatedAt: time.Now(),
|
|
}
|
|
err = models.Save(map[string]interface{}{
|
|
"bahe_activity_id=": bahe.Id,
|
|
"is_delete=": 0,
|
|
"bahe_team_name=": define.TUGWAR_TEAM_BULE,
|
|
}, blueTeam)
|
|
t.CheckErr(err)
|
|
|
|
_, err = bahe.UpdateStatusById(bahe.Id, define.StatusReady)
|
|
t.CheckErr(err)
|
|
t.SUCCESS("操作成功")
|
|
}
|
|
|
|
func (t *TugOfWarCtl) Start() {
|
|
baheId := t.MustGetInt64("bahe_activity_id")
|
|
|
|
bahe := new(models.TugOfWar)
|
|
exist, err := models.Get(bahe, baheId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "拔河不存在")
|
|
if bahe.Status != define.StatusReady {
|
|
t.ERROR(fmt.Sprintf("该活动%s", bahe.Status), code.MSG_ERR)
|
|
}
|
|
|
|
_, err = bahe.UpdateStatusById(baheId, define.StatusRunning)
|
|
t.CheckErr(err)
|
|
t.SUCCESS("操作成功")
|
|
}
|
|
|
|
func (t *TugOfWarCtl) Stop() {
|
|
baheId := t.MustGetInt64("bahe_activity_id")
|
|
|
|
bahe := new(models.TugOfWar)
|
|
exist, err := models.Get(bahe, baheId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "拔河不存在")
|
|
if bahe.Status != define.StatusRunning {
|
|
t.ERROR(fmt.Sprintf("该活动%s", bahe.Status), code.MSG_ERR)
|
|
}
|
|
|
|
bahe.Status = define.StatusEnding
|
|
bahe.UpdatedAt = time.Now()
|
|
_, err = bahe.UpdateStatusById(bahe.Id, bahe.Status)
|
|
t.CheckErr(err)
|
|
t.SUCCESS("操作成功")
|
|
}
|
|
|
|
func (t *TugOfWarCtl) Team() {
|
|
baheId := t.MustGetInt64("bahe_activity_id")
|
|
customerId := t.MustGetUID()
|
|
|
|
bahe := new(models.TugOfWar)
|
|
exist, err := models.Get(bahe, baheId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_TUGWAR_NOT_EXIST, "拔河不存在")
|
|
|
|
activity := new(models.Activity)
|
|
exist, err = models.Get(activity, bahe.ActivityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
|
|
|
|
area := new(models.AreaStore)
|
|
exist, err = area.GetByCustomerId(customerId, bahe.ActivityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区信息异常")
|
|
|
|
//获取队伍信息: 名字、二维码、颜色
|
|
teams := make([]*models.BaheTeam, 0)
|
|
total, err := core.GetXormAuto().Where("is_delete=0 and bahe_activity_id=?", bahe.Id).FindAndCount(&teams)
|
|
t.CheckErr(err)
|
|
|
|
// 队伍颜色
|
|
qrcode := ""
|
|
// 二维码
|
|
if bahe.Model != "随机分配模式" {
|
|
// 非随机模式,自选队伍
|
|
for index := range teams {
|
|
qrcode, err = utils.GenH5Qrcode(define.H5TugOfWar, map[string]interface{}{
|
|
"area_id": area.Id,
|
|
"activity_id": bahe.ActivityId,
|
|
"customer_id": customerId,
|
|
"bahe_activity_id": bahe.Id,
|
|
"bahe_team_id": teams[index].Id,
|
|
"rehearsal_id": activity.RehearsalId,
|
|
})
|
|
t.CheckErr(err)
|
|
teams[index].Qrcode = qrcode
|
|
}
|
|
} else {
|
|
qrcode, err = utils.GenH5Qrcode(define.H5TugOfWar, map[string]interface{}{
|
|
"area_id": area.Id,
|
|
"activity_id": bahe.ActivityId,
|
|
"customer_id": customerId,
|
|
"bahe_activity_id": bahe.Id,
|
|
"bahe_team_id": 0,
|
|
"rehearsal_id": activity.RehearsalId,
|
|
})
|
|
t.CheckErr(err)
|
|
}
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"total": total,
|
|
"list": teams,
|
|
"qrcode": qrcode,
|
|
"model": bahe.Model,
|
|
})
|
|
}
|
|
|
|
func (t *TugOfWarCtl) Member() {
|
|
baheId := t.MustGetInt64("bahe_activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
teams := make([]*models.BaheTeam, 0)
|
|
err := core.GetXormAuto().Where("is_delete=0 and bahe_activity_id=?", baheId).Find(&teams)
|
|
t.CheckErr(err)
|
|
|
|
var total int64 = 0
|
|
for index := range teams {
|
|
members := make([]*models.BaheTeamMember, 0)
|
|
num, err := core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?",
|
|
teams[index].Id, rehearsalId).Desc("score").Asc("sort_time").FindAndCount(&members)
|
|
t.CheckErr(err)
|
|
total += num
|
|
teams[index].Members = members
|
|
}
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"total": total,
|
|
"list": teams,
|
|
})
|
|
}
|
|
|
|
type BaheScoreResult struct {
|
|
TotalScore int64 `json:"total_score" description:"总分数"`
|
|
Id int64 `json:"id" description:"id"`
|
|
ActivityId int64 `json:"activity_id" description:"活动id"`
|
|
BaheActivityId int64 `json:"bahe_activity_id" description:"拔河活动id"`
|
|
BaheTeamName string `json:"bahe_team_name" description:"拔河队伍得名称"`
|
|
Members []*models.BaheTeamMember `json:"members"`
|
|
}
|
|
|
|
func (t *TugOfWarCtl) Score() {
|
|
baheActivityId := t.MustGetInt64("bahe_activity_id")
|
|
rehearsalId := t.MustGetInt64("rehearsal_id")
|
|
|
|
teams := make([]*BaheScoreResult, 0)
|
|
err := core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t").
|
|
Select("sum(m.score) as total_score, t.id, t.activity_id, t.bahe_activity_id, t.bahe_team_name").
|
|
Join("LEFT", new(models.BaheTeamMember).Alias("m"),
|
|
"t.id=m.team_id and m.is_delete=0 and m.rehearsal_id=?", rehearsalId).
|
|
Where("t.is_delete=0 and t.bahe_activity_id=?", baheActivityId).
|
|
GroupBy("t.id").Find(&teams)
|
|
t.CheckErr(err)
|
|
|
|
for index := range teams {
|
|
members := make([]*models.BaheTeamMember, 0)
|
|
err = core.GetXormAuto().Where("is_delete=0 and team_id=? and rehearsal_id=?", teams[index].Id, rehearsalId).
|
|
Desc("score").Asc("sort_time").Find(&members)
|
|
t.CheckErr(err)
|
|
teams[index].Members = members
|
|
}
|
|
t.JSON(map[string]interface{}{
|
|
"total": len(teams),
|
|
"list": teams,
|
|
})
|
|
}
|
|
|
|
func (t *TugOfWarCtl) List() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
bahes := make([]*models.TugOfWar, 0)
|
|
err := core.GetXormAuto().Where("is_delete=0 and activity_id=?", activityId).
|
|
Asc("created_at").Find(&bahes)
|
|
t.CheckErr(err)
|
|
t.JSON(map[string]interface{}{
|
|
"bahe_activities": bahes,
|
|
})
|
|
}
|