|
|
package pc
import ( "fmt" "hudongzhuanjia/controllers" "hudongzhuanjia/models" "hudongzhuanjia/utils/code" "hudongzhuanjia/utils/define" )
//活动
type ActivityCtl struct { controllers.AuthorCtl //controllers.BaseCtl
}
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.Get(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) }
if mode == 1 { // 彩排
rehearsal := models.Rehearsal{ CustomerId: uid, ActivityId: activityId, LimitNumber: limit, Status: 1, IsDelete: false, } _, err = models.Add(&rehearsal) t.CheckErr(err) activity.RehearsalId = rehearsal.Id }
activity.Status = define.StatusRunning _, err = models.Update(activity.Id, activity, "status", "rehearsal_id") t.CheckErr(err) t.JSON(map[string]interface{}{ "rehearsal_id": activity.RehearsalId, }) }
func (t *ActivityCtl) StopActivity() { activityId := t.MustGetInt64("activity_id")
activity := new(models.Activity) exist, err := models.Get(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 { // 彩排回归最初结果
// 竞拍
_, err = models.UpdateAuctionStatusByActivityId(activityId) t.CheckErr(err)
// 抽奖 -> 抽奖活动->抽奖规则-> 抽奖阶梯
lotteryIds, err := models.GetLDActivityIdsByActivityId(activityId) t.CheckErr(err) lotteryRuleIds, err := models.GetLDRuleIdsByLDActivityId(lotteryIds) t.CheckErr(err) _, err = models.UpdateLDLadderStatusByLDRuleIds(lotteryRuleIds) t.CheckErr(err)
// 订单抽奖-> 订单抽奖活动->抽奖规则->抽奖阶梯
orderIds, err := models.GetODActivityIdsByActivityId(activityId) t.CheckErr(err) 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.UpdateVoteStatusByActivityId(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.RehearsalId = 0 _, err = models.Update(activity.Id, activity, "status", "rehearsal_id") t.CheckErr(err) t.SUCCESS("success") }
|