You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.4 KiB
76 lines
2.4 KiB
package lottery_service
|
|
|
|
import (
|
|
"hudongzhuanjia/models"
|
|
"hudongzhuanjia/utils/define"
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/ouxuanserver/osmanthuswine/src/core"
|
|
)
|
|
|
|
type SpecialOrderLotteryUser struct {
|
|
UserId int
|
|
Username string
|
|
UserPhone string
|
|
Avatar string
|
|
PrizeName string
|
|
LadderId int
|
|
PrizeImg string
|
|
EntryPersonName string
|
|
}
|
|
|
|
func RandSpecialOrderLottery(orders []*models.CustomerOrder) {
|
|
if len(orders) <= 0 {
|
|
return
|
|
}
|
|
r := rand.New(rand.NewSource(time.Now().Unix()))
|
|
for i := len(orders) - 1; i > 0; i-- {
|
|
num := r.Intn(i + 1)
|
|
orders[i], orders[num] = orders[num], orders[i]
|
|
}
|
|
}
|
|
|
|
// 排除order_id
|
|
func GetSpecialOrderLottery(repeat string, activityId, ruleId, ladderId, rehearsalId, areaId, archId interface{}) ([]*models.CustomerOrder, error) {
|
|
var err error
|
|
//var userIds = make([]int, 0)
|
|
var orders = make([]*models.CustomerOrder, 0)
|
|
var recordIds = make([]int, 0)
|
|
if repeat == define.MODULE_BESIDE_REPEAT {
|
|
//查询已经中奖的用户,剔除已经中奖的用户
|
|
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("customer_order_id").
|
|
Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
|
|
activityId, rehearsalId, archId).Find(&recordIds)
|
|
} else {
|
|
// 不去除
|
|
//err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("customer_order_id").
|
|
// Where("order_draw_rule_ladder_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
|
|
// ladderId, rehearsalId, archId).Find(&recordIds)
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
s := core.GetXormAuto().NoAutoCondition().Where("activity_id=? and rehearsal_id=? and area_id=? "+
|
|
" and arch_id=? and is_delete=0", activityId, rehearsalId, areaId, archId)
|
|
defer s.Close()
|
|
if len(recordIds) > 0 {
|
|
s.NotIn("id", recordIds)
|
|
}
|
|
err = s.Find(&orders)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return orders, nil
|
|
|
|
}
|
|
|
|
func GetSpecialOrderWinnersResult(ruleId, rehearsalId, archId interface{}) (result []*OrderWinnersResult, err error) {
|
|
err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r").
|
|
Select("r.order_entry_person_name as entry_person_name, r.user_id, o.receiver as user_name, "+
|
|
" o.phone as user_phone, r.prize_name").Join("LEFT",
|
|
(&models.CustomerOrder{}).Alias("o"), "o.id=r.customer_order_id and o.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)
|
|
return
|
|
}
|