|
|
@ -111,11 +111,11 @@ type OrderLadderResult struct { |
|
|
|
func (t *OrderDrawCtl) List() { |
|
|
|
activityId := t.MustGetInt64("activity_id") |
|
|
|
customerId := t.MustGetUID() |
|
|
|
|
|
|
|
customer := new(models.Customer) |
|
|
|
exist, err := models.Get(customer, customerId) |
|
|
|
//
|
|
|
|
area := &models.AreaStore{} |
|
|
|
exist, err := area.GetByCustomerId(customerId, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err = models.Get(activity, activityId) |
|
|
@ -135,16 +135,6 @@ func (t *OrderDrawCtl) List() { |
|
|
|
"a.id=r.order_draw_activity_id and r.is_delete=0"). |
|
|
|
Where("a.is_delete=0 and a.activity_id=?", activityId).Find(&result) |
|
|
|
|
|
|
|
// 多地区的一个坑:分配给主会场的area_id不是主账号的area_id
|
|
|
|
area := new(models.AreaStore) |
|
|
|
if customer.Pid == 0 { |
|
|
|
exist, err = area.GetMainAreaById(activityId) |
|
|
|
} else { |
|
|
|
exist, err = area.GetAreaStoreById(t.MustGetAreaId()) |
|
|
|
} |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
ruleIds := make([]int64, 0) |
|
|
|
for _, v := range result { |
|
|
|
ruleIds = append(ruleIds, v.OrderDrawRuleId) |
|
|
@ -164,7 +154,8 @@ func (t *OrderDrawCtl) List() { |
|
|
|
records := make([]map[string]int64, 0) |
|
|
|
err = core.GetXormAuto().Table(new(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=?", activity.RehearsalId). |
|
|
|
Where("is_delete=0 and rehearsal_id=? and arch_id=? and area_id=?", |
|
|
|
activity.RehearsalId, activity.ArchId, area.Id). |
|
|
|
In("r.order_draw_rule_ladder_id", ladderIds).GroupBy("ladder_id").Find(&records) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
@ -229,8 +220,8 @@ func (t *OrderDrawCtl) Users() { |
|
|
|
session := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). |
|
|
|
Select("o.buyer_id as user_id, u.nickname as username, u.avatar").Distinct("o.buyer_id"). |
|
|
|
Join("LEFT", new(models.User).Alias("u"), "o.buyer_id=u.id and u.is_delete=0"). |
|
|
|
Where("o.activity_id=? and o.is_delete=0 and o.rehearsal_id=?", |
|
|
|
activityId, activity.RehearsalId) |
|
|
|
Where("o.activity_id=? and o.is_delete=0 and o.rehearsal_id=? and o.arch_id=?", activityId, |
|
|
|
activity.RehearsalId, activity.ArchId) |
|
|
|
|
|
|
|
moduleService, exist, err := activity_service.GetModuleService(define.MODULE_ORDERLY, activity.Id) |
|
|
|
t.CheckErr(err) |
|
|
@ -238,8 +229,8 @@ func (t *OrderDrawCtl) Users() { |
|
|
|
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { |
|
|
|
recordIds := make([]int64, 0) |
|
|
|
err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Select("user_id"). |
|
|
|
Where("order_draw_rule_id=? and rehearsal_id=? and is_delete=0", |
|
|
|
ruleId, activity.RehearsalId).Find(&recordIds) |
|
|
|
Where("order_draw_rule_id=? and rehearsal_id=? and arch_id=? and is_delete=0", |
|
|
|
ruleId, activity.RehearsalId, activity.ArchId).Find(&recordIds) |
|
|
|
t.CheckErr(err) |
|
|
|
session = session.NotIn("o.buyer_id", recordIds) |
|
|
|
} |
|
|
@ -359,10 +350,24 @@ type WinnerResult struct { |
|
|
|
} |
|
|
|
|
|
|
|
func (t *OrderDrawCtl) ListOfWinners() { |
|
|
|
orderDrawRuleId := t.MustGetInt64("order_draw_rule_id") |
|
|
|
rehearsalId := t.MustGetInt64("rehearsal_id") |
|
|
|
ruleId := t.MustGetInt64("order_draw_rule_id") |
|
|
|
|
|
|
|
rule := &models.OrderDrawRule{} |
|
|
|
exist, err := models.Get(rule, ruleId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在") |
|
|
|
|
|
|
|
lottery := models.OrderDrawActivity{} |
|
|
|
exist, err = models.Get(lottery, rule.OrderDrawActivityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在") |
|
|
|
|
|
|
|
activity := models.Activity{} |
|
|
|
exist, err = models.Get(activity, lottery.ActivityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
result, err := lottery_service.GetOrderWinnersResult(orderDrawRuleId, rehearsalId) |
|
|
|
result, err := lottery_service.GetOrderWinnersResult(rule.Id, activity.RehearsalId, activity.ArchId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"total": len(result), |
|
|
@ -383,15 +388,20 @@ type OrdersResult struct { |
|
|
|
|
|
|
|
func (t *OrderDrawCtl) Orders() { |
|
|
|
activityId := t.MustGetInt64("activity_id") |
|
|
|
rehearsalId := t.MustGetInt64("rehearsal_id") |
|
|
|
|
|
|
|
activity := models.Activity{} |
|
|
|
exist, err := models.Get(activity, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
orders := make([]*OrdersResult, 0) |
|
|
|
err := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). |
|
|
|
err = core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). |
|
|
|
Select("o.area_name, o.goods_name, o.buyer_id as user_id, u.nickname, l.extra_data as extra_data, o.created_at"). |
|
|
|
Distinct("o.id").Join("LEFT", new(models.InvitationLetter).Alias("l"), |
|
|
|
"o.buyer_id=l.user_id and o.activity_id=l.activity_id and l.is_delete=0"). |
|
|
|
Join("LEFT", new(models.User).Alias("u"), "u.id=o.buyer_id and u.is_delete=0"). |
|
|
|
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=?", activityId, rehearsalId). |
|
|
|
"o.buyer_id=l.user_id and o.activity_id=l.activity_id and l.arch_id=o.arch_id"). |
|
|
|
Join("LEFT", new(models.User).Alias("u"), "u.id=o.buyer_id"). |
|
|
|
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", |
|
|
|
activityId, activity.RehearsalId, activity.ArchId). |
|
|
|
Asc("o.created_at").Find(&orders) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
@ -404,8 +414,8 @@ func (t *OrderDrawCtl) Orders() { |
|
|
|
} |
|
|
|
|
|
|
|
// 下订单人数
|
|
|
|
buyerCount, err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=?", |
|
|
|
activityId, rehearsalId).Distinct("buyer_id").Count(new(models.CustomerOrder)) |
|
|
|
buyerCount, err := core.GetXormAuto().Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?", |
|
|
|
activityId, activity.RehearsalId, activity.ArchId).Distinct("buyer_id").Count(new(models.CustomerOrder)) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|