|
@ -106,13 +106,6 @@ func (t *OrderDrawCtl) Stop() { |
|
|
t.SUCCESS("操作成功") |
|
|
t.SUCCESS("操作成功") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type OrderListResult struct { |
|
|
|
|
|
OrderDrawActivityId int `json:"order_draw_activity_id"` |
|
|
|
|
|
OrderDrawRuleId int `json:"order_draw_rule_id"` |
|
|
|
|
|
OrderDrawActivityName string `json:"order_draw_activity_name"` |
|
|
|
|
|
OrderDrawLadders []*OrderLadderResult `json:"order_draw_ladders"` |
|
|
|
|
|
PrizeNumber int `json:"prize_number"` |
|
|
|
|
|
} |
|
|
|
|
|
type OrderLadderResult struct { |
|
|
type OrderLadderResult struct { |
|
|
OrderDrawRuleId int `json:"order_draw_rule_id"` |
|
|
OrderDrawRuleId int `json:"order_draw_rule_id"` |
|
|
OrderDrawLadderId int `json:"order_draw_ladder_id"` |
|
|
OrderDrawLadderId int `json:"order_draw_ladder_id"` |
|
@ -122,6 +115,14 @@ type OrderLadderResult struct { |
|
|
PrizeNumber int `json:"prize_number"` |
|
|
PrizeNumber int `json:"prize_number"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type OrderListResult struct { |
|
|
|
|
|
OrderDrawActivityId int `json:"order_draw_activity_id"` |
|
|
|
|
|
OrderDrawRuleId int `json:"order_draw_rule_id"` |
|
|
|
|
|
OrderDrawActivityName string `json:"order_draw_activity_name"` |
|
|
|
|
|
OrderDrawLadders []*OrderLadderResult `json:"order_draw_ladders"` |
|
|
|
|
|
PrizeNumber int `json:"prize_number"` |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//获取所有订单奖品
|
|
|
//获取所有订单奖品
|
|
|
func (t *OrderDrawCtl) List() { |
|
|
func (t *OrderDrawCtl) List() { |
|
|
activityId := t.MustGetInt("activity_id") |
|
|
activityId := t.MustGetInt("activity_id") |
|
@ -202,8 +203,9 @@ func (t *OrderDrawCtl) List() { |
|
|
func (t *OrderDrawCtl) Prize() { |
|
|
func (t *OrderDrawCtl) Prize() { |
|
|
ruleId := t.MustGetInt("order_draw_rule_id") |
|
|
ruleId := t.MustGetInt("order_draw_rule_id") |
|
|
|
|
|
|
|
|
list := make([]*models.OrderDrawRuleLadder, 0) |
|
|
|
|
|
err := core.GetXormAuto().Where("is_delete=0 and order_draw_rule_id=?", ruleId).Find(&list) |
|
|
|
|
|
|
|
|
//list := make([]*models.OrderDrawRuleLadder, 0)
|
|
|
|
|
|
//err := core.GetXormAuto().Where("is_delete=0 and order_draw_rule_id=?", ruleId).Find(&list)
|
|
|
|
|
|
list, err := models.GetOrderDrawRuleLaddersByRuleId(ruleId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
|
for index := range list { |
|
|
for index := range list { |
|
@ -226,15 +228,15 @@ func (t *OrderDrawCtl) Users() { |
|
|
activityId := t.MustGetInt("activity_id") |
|
|
activityId := t.MustGetInt("activity_id") |
|
|
ruleId := t.MustGetInt("order_draw_rule_id") |
|
|
ruleId := t.MustGetInt("order_draw_rule_id") |
|
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
|
|
exist, err := models.Get(activity, activityId) |
|
|
|
|
|
|
|
|
activity := models.Activity{} |
|
|
|
|
|
exist, err := models.Get(&activity, activityId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
|
result := make([]*OrderUsersResult, 0) |
|
|
result := make([]*OrderUsersResult, 0) |
|
|
session := core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). |
|
|
|
|
|
|
|
|
session := core.GetXormAuto().Table(&models.CustomerOrder{}).Alias("o"). |
|
|
Select("o.buyer_id as user_id, u.nickname as username, u.avatar").Distinct("o.buyer_id"). |
|
|
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"). |
|
|
|
|
|
|
|
|
Join("LEFT", (&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=? and o.arch_id=?", activityId, |
|
|
Where("o.activity_id=? and o.is_delete=0 and o.rehearsal_id=? and o.arch_id=?", activityId, |
|
|
activity.RehearsalId, activity.ArchId) |
|
|
activity.RehearsalId, activity.ArchId) |
|
|
|
|
|
|
|
@ -243,7 +245,7 @@ func (t *OrderDrawCtl) Users() { |
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块服务不存在") |
|
|
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块服务不存在") |
|
|
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { |
|
|
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT { |
|
|
recordIds := make([]int, 0) |
|
|
recordIds := make([]int, 0) |
|
|
err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Select("user_id"). |
|
|
|
|
|
|
|
|
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("user_id"). |
|
|
Where("order_draw_rule_id=? and rehearsal_id=? and arch_id=? and is_delete=0", |
|
|
Where("order_draw_rule_id=? and rehearsal_id=? and arch_id=? and is_delete=0", |
|
|
ruleId, activity.RehearsalId, activity.ArchId).Find(&recordIds) |
|
|
ruleId, activity.RehearsalId, activity.ArchId).Find(&recordIds) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
@ -266,37 +268,37 @@ func (t *OrderDrawCtl) Draw() { |
|
|
number := t.MustGetInt("number") |
|
|
number := t.MustGetInt("number") |
|
|
customerId := t.GetAccountId() |
|
|
customerId := t.GetAccountId() |
|
|
|
|
|
|
|
|
customer := new(models.Customer) |
|
|
|
|
|
exist, err := models.Get(customer, customerId) |
|
|
|
|
|
|
|
|
customer := models.Customer{} |
|
|
|
|
|
exist, err := models.Get(&customer, customerId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") |
|
|
t.Assert(exist, code.MSG_CUSTOMER_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.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
t.CheckRunning(activity.Status) |
|
|
t.CheckRunning(activity.Status) |
|
|
|
|
|
|
|
|
area := new(models.AreaStore) |
|
|
|
|
|
|
|
|
area := &models.AreaStore{} |
|
|
exist, err = area.GetByCustomerId(customerId, activityId) |
|
|
exist, err = area.GetByCustomerId(customerId, activityId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "地区不存在") |
|
|
t.Assert(exist, code.MSG_DATA_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
|
rule := new(models.OrderDrawRule) |
|
|
|
|
|
exist, err = models.Get(rule, ruleId) |
|
|
|
|
|
|
|
|
rule := models.OrderDrawRule{} |
|
|
|
|
|
exist, err = models.Get(&rule, ruleId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在") |
|
|
t.Assert(exist, code.MSG_ORDER_RULE_NOT_EXIST, "订单抽奖规则不存在") |
|
|
|
|
|
|
|
|
// 查询奖品
|
|
|
// 查询奖品
|
|
|
ladder := new(models.OrderDrawRuleLadder) |
|
|
|
|
|
exist, err = models.Get(ladder, ladderId) |
|
|
|
|
|
|
|
|
ladder := models.OrderDrawRuleLadder{} |
|
|
|
|
|
exist, err = models.Get(&ladder, ladderId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_ORDER_LADDER_NOT_EXIST, "订单抽奖等级不存在") |
|
|
t.Assert(exist, code.MSG_ORDER_LADDER_NOT_EXIST, "订单抽奖等级不存在") |
|
|
t.CheckRunning(ladder.Status) |
|
|
t.CheckRunning(ladder.Status) |
|
|
|
|
|
|
|
|
count, err := core.GetXormAuto().Where("order_draw_rule_id=? and order_draw_rule_ladder_id=? "+ |
|
|
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). |
|
|
"and rehearsal_id=? and arch_id=? and is_delete=0", ruleId, ladderId, activity.RehearsalId, activity.ArchId). |
|
|
Count(new(models.OrderDrawRecord)) |
|
|
|
|
|
|
|
|
Count(&models.OrderDrawRecord{}) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
prizeNum := ladder.PrizeNumber - int(count) |
|
|
prizeNum := ladder.PrizeNumber - int(count) |
|
|
if prizeNum <= 0 || prizeNum < number { |
|
|
if prizeNum <= 0 || prizeNum < number { |
|
@ -320,24 +322,20 @@ func (t *OrderDrawCtl) Draw() { |
|
|
winners[i].LadderId = ladder.Id |
|
|
winners[i].LadderId = ladder.Id |
|
|
winners[i].PrizeImg = ladder.PrizeImg |
|
|
winners[i].PrizeImg = ladder.PrizeImg |
|
|
winners[i].PrizeName = ladder.PrizeName |
|
|
winners[i].PrizeName = ladder.PrizeName |
|
|
// 订单抽奖 ==> 存入我的奖品
|
|
|
|
|
|
userPrize := new(models.UserPrize) |
|
|
|
|
|
userPrize.ActivityId = activityId |
|
|
|
|
|
userPrize.RehearsalId = activity.RehearsalId |
|
|
|
|
|
userPrize.ActivityName = activity.Name |
|
|
|
|
|
userPrize.UserId = winners[i].UserId |
|
|
|
|
|
userPrize.PrizeImg = ladder.PrizeImg |
|
|
|
|
|
userPrize.PrizeName = ladder.PrizeName |
|
|
|
|
|
userPrize.ArchId = activity.ArchId |
|
|
|
|
|
userPrize.PrizeType = 2 |
|
|
|
|
|
userPrize.IsDelete = false |
|
|
|
|
|
userPrize.CreatedAt = time.Now() |
|
|
|
|
|
userPrize.UpdatedAt = time.Now() |
|
|
|
|
|
_, err = core.GetXormAuto().Insert(userPrize) |
|
|
|
|
|
|
|
|
prize := models.UserPrize{} |
|
|
|
|
|
prize.ActivityId = activityId |
|
|
|
|
|
prize.RehearsalId = activity.RehearsalId |
|
|
|
|
|
prize.ActivityName = activity.Name |
|
|
|
|
|
prize.UserId = winners[i].UserId |
|
|
|
|
|
prize.PrizeImg = ladder.PrizeImg |
|
|
|
|
|
prize.PrizeName = ladder.PrizeName |
|
|
|
|
|
prize.ArchId = activity.ArchId |
|
|
|
|
|
prize.PrizeType = 2 |
|
|
|
|
|
_, err = models.Add(&prize) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
|
record := new(models.OrderDrawRecord) |
|
|
|
|
|
record.UserPrizeId = userPrize.Id |
|
|
|
|
|
|
|
|
record := models.OrderDrawRecord{} |
|
|
|
|
|
record.UserPrizeId = prize.Id |
|
|
record.ActivityId = activityId |
|
|
record.ActivityId = activityId |
|
|
record.RehearsalId = activity.RehearsalId |
|
|
record.RehearsalId = activity.RehearsalId |
|
|
record.ArchId = activity.ArchId |
|
|
record.ArchId = activity.ArchId |
|
@ -348,10 +346,7 @@ func (t *OrderDrawCtl) Draw() { |
|
|
record.PrizeName = ladder.PrizeName |
|
|
record.PrizeName = ladder.PrizeName |
|
|
record.AreaId = area.Id |
|
|
record.AreaId = area.Id |
|
|
record.AreaName = area.Name |
|
|
record.AreaName = area.Name |
|
|
record.IsDelete = false |
|
|
|
|
|
record.CreatedAt = time.Now() |
|
|
|
|
|
record.UpdatedAt = time.Now() |
|
|
|
|
|
_, err = core.GetXormAuto().InsertOne(record) |
|
|
|
|
|
|
|
|
_, err = models.Add(&record) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
} |
|
|
} |
|
|
t.JSON(winners) |
|
|
t.JSON(winners) |
|
@ -405,17 +400,17 @@ type OrdersResult struct { |
|
|
func (t *OrderDrawCtl) Orders() { |
|
|
func (t *OrderDrawCtl) Orders() { |
|
|
activityId := t.MustGetInt("activity_id") |
|
|
activityId := t.MustGetInt("activity_id") |
|
|
|
|
|
|
|
|
activity := &models.Activity{} |
|
|
|
|
|
exist, err := models.Get(activity, activityId) |
|
|
|
|
|
|
|
|
activity := models.Activity{} |
|
|
|
|
|
exist, err := models.Get(&activity, activityId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
|
orders := make([]*OrdersResult, 0) |
|
|
orders := make([]*OrdersResult, 0) |
|
|
err = core.GetXormAuto().Table(new(models.CustomerOrder)).Alias("o"). |
|
|
|
|
|
|
|
|
err = core.GetXormAuto().Table(&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"). |
|
|
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"), |
|
|
|
|
|
|
|
|
Distinct("o.id").Join("LEFT", (&models.InvitationLetter{}).Alias("l"), |
|
|
"o.buyer_id=l.user_id and o.activity_id=l.activity_id and l.arch_id=o.arch_id"). |
|
|
"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"). |
|
|
|
|
|
|
|
|
Join("LEFT", (&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=?", |
|
|
Where("o.is_delete=0 and o.activity_id=? and o.rehearsal_id=? and o.arch_id=?", |
|
|
activityId, activity.RehearsalId, activity.ArchId). |
|
|
activityId, activity.RehearsalId, activity.ArchId). |
|
|
Asc("o.created_at").Find(&orders) |
|
|
Asc("o.created_at").Find(&orders) |
|
@ -430,8 +425,7 @@ func (t *OrderDrawCtl) Orders() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 下订单人数
|
|
|
// 下订单人数
|
|
|
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)) |
|
|
|
|
|
|
|
|
buyerCount, err := (&models.CustomerOrder{}).CountCustomerOrder(activity.Id, activity.RehearsalId, activity.ArchId) |
|
|
t.CheckErr(err) |
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
|
t.JSON(map[string]interface{}{ |
|
|
t.JSON(map[string]interface{}{ |
|
|