Browse Source

fix:bug

token_replace
黄梓健 5 years ago
parent
commit
859e2fa5d4
  1. 96
      controllers/pc/order_draw.go
  2. 13
      models/customer_order.go
  3. 5
      models/order_draw_rule_ladder.go
  4. 12
      services/lottery/order.go

96
controllers/pc/order_draw.go

@ -106,13 +106,6 @@ func (t *OrderDrawCtl) Stop() {
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 {
OrderDrawRuleId int `json:"order_draw_rule_id"`
OrderDrawLadderId int `json:"order_draw_ladder_id"`
@ -122,6 +115,14 @@ type OrderLadderResult struct {
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() {
activityId := t.MustGetInt("activity_id")
@ -202,8 +203,9 @@ func (t *OrderDrawCtl) List() {
func (t *OrderDrawCtl) Prize() {
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)
for index := range list {
@ -226,15 +228,15 @@ func (t *OrderDrawCtl) Users() {
activityId := t.MustGetInt("activity_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.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
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").
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,
activity.RehearsalId, activity.ArchId)
@ -243,7 +245,7 @@ func (t *OrderDrawCtl) Users() {
t.Assert(exist, code.MSG_MODULE_NOT_EXIST, "模块服务不存在")
if moduleService.BesideRepeat == define.MODULE_BESIDE_REPEAT {
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",
ruleId, activity.RehearsalId, activity.ArchId).Find(&recordIds)
t.CheckErr(err)
@ -266,37 +268,37 @@ func (t *OrderDrawCtl) Draw() {
number := t.MustGetInt("number")
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.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.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
t.CheckRunning(activity.Status)
area := new(models.AreaStore)
area := &models.AreaStore{}
exist, err = area.GetByCustomerId(customerId, activityId)
t.CheckErr(err)
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.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.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(new(models.OrderDrawRecord))
Count(&models.OrderDrawRecord{})
t.CheckErr(err)
prizeNum := ladder.PrizeNumber - int(count)
if prizeNum <= 0 || prizeNum < number {
@ -320,24 +322,20 @@ func (t *OrderDrawCtl) Draw() {
winners[i].LadderId = ladder.Id
winners[i].PrizeImg = ladder.PrizeImg
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)
record := new(models.OrderDrawRecord)
record.UserPrizeId = userPrize.Id
record := models.OrderDrawRecord{}
record.UserPrizeId = prize.Id
record.ActivityId = activityId
record.RehearsalId = activity.RehearsalId
record.ArchId = activity.ArchId
@ -348,10 +346,7 @@ func (t *OrderDrawCtl) Draw() {
record.PrizeName = ladder.PrizeName
record.AreaId = area.Id
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.JSON(winners)
@ -405,17 +400,17 @@ type OrdersResult struct {
func (t *OrderDrawCtl) Orders() {
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.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在")
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").
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").
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=?",
activityId, activity.RehearsalId, activity.ArchId).
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.JSON(map[string]interface{}{

13
models/customer_order.go

@ -62,12 +62,6 @@ func (t *CustomerOrder) GetByOutTradeNO(outTradeNo string) (bool, error) {
return core.GetXormAuto().Where("is_delete=0 and out_trade_no=?", outTradeNo).Get(t)
}
func (t *CustomerOrder) Count(activityId, rehearsalId int, limitTime time.Time, archId interface{}) (int64, error) {
return core.GetXormAuto().Where("user_prize_id=0 and created_at >= ? and "+
"activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
limitTime, activityId, rehearsalId, archId).Count(t)
}
func GetCustomerOrdersByActivityId(userId, activityId, rehearsalId, areaId int, status []string, page, pageSize int, archId interface{}) ([]*CustomerOrder, error) {
orders := make([]*CustomerOrder, 0)
err := core.GetXormAuto().Where("is_delete=0 and buyer_id=? and activity_id=? and "+
@ -91,3 +85,10 @@ func GetExpiredAtLiveCustomerOrder() ([]*CustomerOrder, error) {
}
return orders, nil
}
func (t *CustomerOrder) CountCustomerOrder(activityId, rehearsalId, archId interface{}) (int64, error) {
buyerCount, err := core.GetXormAuto().NoAutoCondition().
Where("is_delete=0 and activity_id=? and rehearsal_id=? and arch_id=?",
activityId, rehearsalId, archId).Distinct("buyer_id").Count(t)
return buyerCount, err
}

5
models/order_draw_rule_ladder.go

@ -37,3 +37,8 @@ func UpdateODLadderStatusByODRuleIds(ids []int) (int64, error) {
return core.GetXormAuto().Where("is_delete=0").In("order_draw_rule_id", ids).
Update(&OrderDrawRuleLadder{Status: define.StatusNotBegin})
}
func GetOrderDrawRuleLaddersByRuleId(ruleId interface{}) (list []*OrderDrawRuleLadder, err error) {
err = core.GetXormAuto().Where("is_delete=0 and order_draw_rule_id=?", ruleId).Find(&list)
return
}

12
services/lottery/order.go

@ -13,12 +13,12 @@ func GetOrderLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehears
var recordIds = make([]int, 0)
if repeat == define.MODULE_BESIDE_REPEAT {
//查询已经中奖的用户,剔除已经中奖的用户
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",
ruleId, rehearsalId, archId).Find(&recordIds)
} else {
// 不去除
err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Select("user_id").
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("user_id").
Where("order_draw_rule_ladder_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
ladderId, rehearsalId, archId).Find(&recordIds)
}
@ -26,8 +26,8 @@ func GetOrderLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehears
return nil, err
}
err = core.GetXormAuto().Table(new(models.CustomerOrder)).
Select("buyer_id as user_id").Distinct("buyer_id").
err = core.GetXormAuto().Table(&models.CustomerOrder{}).
Select("id, buyer_id as user_id").Distinct("buyer_id").
Where("activity_id=? and rehearsal_id=? and area_id=? and arch_id=? and is_delete=0",
activityId, rehearsalId, areaId, archId).NotIn("buyer_id", recordIds).
Find(&userIds)
@ -40,9 +40,9 @@ func GetOrderLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehears
func GetOrderWinnersResult(ruleId, rehearsalId, archId interface{}) ([]*WinnersResult, error) {
result := make([]*WinnersResult, 0)
err := core.GetXormAuto().Table(new(models.OrderDrawRecord)).Alias("r").
err := core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r").
Select("r.user_id, u.nickname as username, u.phone as user_phone, u.avatar, r.prize_name").
Join("LEFT", new(models.User).Alias("u"), "u.id=r.user_id and u.is_delete=0").
Join("LEFT", (&models.User{}).Alias("u"), "u.id=r.user_id and u.is_delete=0").
Where("r.is_delete=0 and r.order_draw_rule_id=? and r.rehearsal_id=? and r.arch_id=?",
ruleId, rehearsalId, archId).Find(&result)
if err != nil {

Loading…
Cancel
Save