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.
150 lines
4.1 KiB
150 lines
4.1 KiB
package pc
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
"hudongzhuanjia/controllers"
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/utils/code"
|
|
"hudongzhuanjia/utils/define"
|
|
"time"
|
|
)
|
|
|
|
//活动
|
|
type ActivityCtl struct {
|
|
controllers.AuthorCtl
|
|
}
|
|
|
|
// 废弃
|
|
func (t *ActivityCtl) List() {
|
|
customerId := t.MustGetUID()
|
|
list := make([]*models.Activity, 0)
|
|
err := core.GetXormAuto().Where("is_delete=0 and customer_id=? and status<>?",
|
|
customerId, define.StatusEnding).Find(&list)
|
|
t.CheckErr(err)
|
|
|
|
t.JSON(map[string]interface{}{
|
|
"list": list,
|
|
"total": len(list),
|
|
})
|
|
}
|
|
|
|
func (t *ActivityCtl) StartActivity() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
mode := t.MustGetInt("mode") // 标识彩排 mode=0正式 mode=1彩排
|
|
uid := t.MustGetUID()
|
|
limit := t.DefaultInt64("limit", 10)
|
|
|
|
activity := new(models.Activity)
|
|
exist, err := models.GetById(activity, activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
|
|
|
|
// 检测活动状态 ==》 必须为未开始
|
|
if activity.Status != define.StatusNotBegin {
|
|
t.ERROR(fmt.Sprintf("该活动状态%s", activity.Status), code.MSG_ERR)
|
|
}
|
|
|
|
// 检测彩排活动是否进行中
|
|
if activity.RehearsalId != 0 {
|
|
t.ERROR("该活动在彩排中", code.MSG_ERR)
|
|
}
|
|
|
|
var rehearsalId int64 = 0
|
|
if mode == 1 {
|
|
rehearsal := new(models.Rehearsal)
|
|
rehearsal.Status = 1
|
|
rehearsal.ActivityId = activityId
|
|
rehearsal.CustomerId = uid
|
|
rehearsal.LimitNumber = limit
|
|
rehearsal.IsDelete = false
|
|
rehearsal.UpdatedAt = time.Now()
|
|
rehearsal.CreatedAt = time.Now()
|
|
_, err := core.GetXormAuto().InsertOne(rehearsal)
|
|
t.CheckErr(err)
|
|
rehearsalId = rehearsal.Id
|
|
}
|
|
|
|
activity.Status = define.StatusRunning
|
|
activity.RehearsalId = rehearsalId
|
|
activity.UpdatedAt = time.Now()
|
|
// todo: 校验
|
|
err = models.Save(map[string]interface{}{
|
|
"id=": activityId,
|
|
"is_delete=": 0,
|
|
}, activity, "status", "rehearsal_id", "updated_at")
|
|
t.CheckErr(err)
|
|
t.JSON(map[string]interface{}{
|
|
"rehearsal_id": rehearsalId,
|
|
})
|
|
}
|
|
|
|
func (t *ActivityCtl) StopActivity() {
|
|
activityId := t.MustGetInt64("activity_id")
|
|
|
|
activity := new(models.Activity)
|
|
exist, err := models.GetById(activity, activityId)
|
|
t.CheckErr(err)
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
|
|
|
|
if activity.Status != define.StatusRunning {
|
|
t.ERROR(fmt.Sprintf("该活动%s", activity.Status), code.MSG_ERR)
|
|
}
|
|
|
|
if activity.RehearsalId != 0 { // 彩排回归最初结果
|
|
// todo:其他的活动也要回复到最初的状态
|
|
// 竞拍
|
|
_, err = models.UpdateAuctionStatusByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
|
|
// 抽奖
|
|
lotteryIds, err := models.GetLDActivityIdsByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
//_, err = models.UpdateLDRuleStatusByLDActiviytIds(lotteryIds)
|
|
lotteryRuleIds, err := models.GetLDRuleIdsByLDActivityId(lotteryIds)
|
|
t.CheckErr(err)
|
|
_, err = models.UpdateLDLadderStatusByLDRuleIds(lotteryRuleIds)
|
|
t.CheckErr(err)
|
|
|
|
// 订单抽奖
|
|
orderIds, err := models.GetODActivityIdsByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
//_, err = models.UpdateODRuleStatusByODActivityIds(orderIds)
|
|
orderRuleIds, err := models.GetODRuleIdsByODActivityIds(orderIds)
|
|
t.CheckErr(err)
|
|
_, err = models.UpdateODLadderStatusByODRuleIds(orderRuleIds)
|
|
t.CheckErr(err)
|
|
|
|
// 摇红包
|
|
shakeRbIds, err := models.GetSREActivityIdsByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
_, err = models.UpdateSRERuleStatusBySREActivityIds(shakeRbIds)
|
|
t.CheckErr(err)
|
|
|
|
// 拔河
|
|
_, err = models.UpdateTOWStatusByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
|
|
// 投票
|
|
_, err = models.UpdateVoteStatusByActiviytId(activityId)
|
|
t.CheckErr(err)
|
|
|
|
// 卡路里
|
|
_, err = models.UpdateCalorieStatusByActivityId(activityId)
|
|
t.CheckErr(err)
|
|
|
|
// 订单开启
|
|
_, err = new(models.CustomerOrderOption).Switch(activityId, 0)
|
|
t.CheckErr(err)
|
|
|
|
activity.Status = define.StatusNotBegin
|
|
} else {
|
|
activity.Status = define.StatusEnding
|
|
}
|
|
activity.UpdatedAt = time.Now()
|
|
activity.RehearsalId = 0
|
|
models.Save(map[string]interface{}{
|
|
"id=": activity.Id,
|
|
}, activity, "status", "rehearsal_id", "updated_at")
|
|
t.SUCCESS("success")
|
|
}
|