|
|
@ -131,23 +131,23 @@ func (t *OrderDrawCtl) List() { |
|
|
|
area := &models.AreaStore{} |
|
|
|
exist, err := area.GetByCustomerId(customerId, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区信息异常") |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err = models.Get(activity, activityId) |
|
|
|
activity := models.Activity{} |
|
|
|
exist, err = models.Get(&activity, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动信息异常") |
|
|
|
|
|
|
|
// 订单的开启或关闭
|
|
|
|
order := new(models.CustomerOrderOption) |
|
|
|
exist, err = order.GetByActivityId(activityId) |
|
|
|
option := &models.CustomerOrderOption{} |
|
|
|
exist, err = option.GetByActivityId(activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单活动不存在") |
|
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "订单信息异常") |
|
|
|
|
|
|
|
result := make([]*OrderListResult, 0) |
|
|
|
core.GetXormAuto().Table(new(models.OrderDrawActivity)).Alias("a"). |
|
|
|
core.GetXormAuto().Table(&models.OrderDrawActivity{}).Alias("a"). |
|
|
|
Select("a.id as order_draw_activity_id, r.id as order_draw_rule_id, a.order_draw_activity_name"). |
|
|
|
Join("LEFT", new(models.OrderDrawRule).Alias("r"), |
|
|
|
Join("LEFT", (&models.OrderDrawRule{}).Alias("r"), |
|
|
|
"a.id=r.order_draw_activity_id and r.is_delete=0"). |
|
|
|
Where("a.is_delete=0 and a.activity_id=?", activityId).Find(&result) |
|
|
|
|
|
|
@ -157,7 +157,7 @@ func (t *OrderDrawCtl) List() { |
|
|
|
} |
|
|
|
|
|
|
|
ladders := make([]*OrderLadderResult, 0) |
|
|
|
err = core.GetXormAuto().Table(new(models.OrderDrawRuleLadder)).Alias("l"). |
|
|
|
err = core.GetXormAuto().Table(&models.OrderDrawRuleLadder{}).Alias("l"). |
|
|
|
Select("id as order_draw_ladder_id, status, prize_name, prize_img, prize_number, order_draw_rule_id"). |
|
|
|
Where("is_delete=0").In("order_draw_rule_id", ruleIds).Find(&ladders) |
|
|
|
t.CheckErr(err) |
|
|
@ -168,7 +168,7 @@ func (t *OrderDrawCtl) List() { |
|
|
|
} |
|
|
|
|
|
|
|
records := make([]map[string]int, 0) |
|
|
|
err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Alias("r"). |
|
|
|
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r"). |
|
|
|
Select("r.order_draw_rule_ladder_id as ladder_id, count(id) as num"). |
|
|
|
Where("is_delete=0 and rehearsal_id=? and arch_id=? and area_id=?", |
|
|
|
activity.RehearsalId, activity.ArchId, area.Id). |
|
|
@ -195,7 +195,7 @@ func (t *OrderDrawCtl) List() { |
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"total": len(result), |
|
|
|
"list": result, |
|
|
|
"status": order.Status, |
|
|
|
"status": option.Status, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@ -263,7 +263,6 @@ func (t *OrderDrawCtl) Users() { |
|
|
|
// 订单抽奖动作
|
|
|
|
func (t *OrderDrawCtl) Draw() { |
|
|
|
activityId := t.MustGetInt("activity_id") |
|
|
|
ruleId := t.MustGetInt("order_draw_rule_id") |
|
|
|
ladderId := t.MustGetInt("order_draw_rule_ladder_id") |
|
|
|
number := t.MustGetInt("number") |
|
|
|
customerId := t.GetAccountId() |
|
|
@ -284,11 +283,6 @@ func (t *OrderDrawCtl) Draw() { |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
rule := models.OrderDrawRule{} |
|
|
|
exist, err = models.Get(&rule, ruleId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在") |
|
|
|
|
|
|
|
// 查询奖品
|
|
|
|
ladder := models.OrderDrawRuleLadder{} |
|
|
|
exist, err = models.Get(&ladder, ladderId) |
|
|
@ -296,9 +290,15 @@ func (t *OrderDrawCtl) Draw() { |
|
|
|
t.Assert(exist, code.MSG_ORDER_LADDER_NOT_EXIST, "订单抽奖等级不存在") |
|
|
|
t.CheckRunning(ladder.Status) |
|
|
|
|
|
|
|
count, err := core.GetXormAuto().Where("order_draw_rule_id=? and order_draw_rule_ladder_id=? "+ |
|
|
|
"and rehearsal_id=? and arch_id=? and is_delete=0", ruleId, ladderId, activity.RehearsalId, activity.ArchId). |
|
|
|
Count(&models.OrderDrawRecord{}) |
|
|
|
rule := models.OrderDrawRule{} |
|
|
|
exist, err = models.Get(&rule, ladder.OrderDrawRuleId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在") |
|
|
|
|
|
|
|
//count, err := core.GetXormAuto().Where("order_draw_rule_id=? and order_draw_rule_ladder_id=? "+
|
|
|
|
// "and rehearsal_id=? and arch_id=? and is_delete=0", ruleId, ladderId, activity.RehearsalId, activity.ArchId).
|
|
|
|
// Count(&models.OrderDrawRecord{})
|
|
|
|
count, err := (&models.OrderDrawRecord{}).Count(ladder.Id, activity.RehearsalId, activity.ArchId) |
|
|
|
t.CheckErr(err) |
|
|
|
prizeNum := ladder.PrizeNumber - int(count) |
|
|
|
if prizeNum <= 0 || prizeNum < number { |
|
|
|
xxxxxxxxxx