互动
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

5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package lottery_service
  2. import (
  3. "hudongzhuanjia/models"
  4. "hudongzhuanjia/utils/define"
  5. "math/rand"
  6. "time"
  7. "github.com/ouxuanserver/osmanthuswine/src/core"
  8. )
  9. type SpecialOrderLotteryUser struct {
  10. UserId int
  11. Username string
  12. UserPhone string
  13. Avatar string
  14. PrizeName string
  15. LadderId int
  16. PrizeImg string
  17. EntryPersonName string
  18. }
  19. func RandSpecialOrderLottery(orders []*models.CustomerOrder) {
  20. if len(orders) <= 0 {
  21. return
  22. }
  23. r := rand.New(rand.NewSource(time.Now().Unix()))
  24. for i := len(orders) - 1; i > 0; i-- {
  25. num := r.Intn(i + 1)
  26. orders[i], orders[num] = orders[num], orders[i]
  27. }
  28. }
  29. // 排除order_id
  30. func GetSpecialOrderLottery(repeat string, activityId, ruleId, ladderId, rehearsalId, areaId, archId interface{}) ([]*models.CustomerOrder, error) {
  31. var err error
  32. //var userIds = make([]int, 0)
  33. var orders = make([]*models.CustomerOrder, 0)
  34. var recordIds = make([]int, 0)
  35. if repeat == define.MODULE_BESIDE_REPEAT {
  36. //查询已经中奖的用户,剔除已经中奖的用户
  37. err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("customer_order_id").
  38. Where("activity_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  39. activityId, rehearsalId, archId).Find(&recordIds)
  40. } else {
  41. // 不去除
  42. //err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Select("customer_order_id").
  43. // Where("order_draw_rule_ladder_id=? and rehearsal_id=? and arch_id=? and is_delete=0",
  44. // ladderId, rehearsalId, archId).Find(&recordIds)
  45. }
  46. if err != nil {
  47. return nil, err
  48. }
  49. s := core.GetXormAuto().NoAutoCondition().Where("activity_id=? and rehearsal_id=? and area_id=? "+
  50. " and arch_id=? and is_delete=0", activityId, rehearsalId, areaId, archId)
  51. defer s.Close()
  52. if len(recordIds) > 0 {
  53. s.NotIn("id", recordIds)
  54. }
  55. err = s.Find(&orders)
  56. if err != nil {
  57. return nil, err
  58. }
  59. return orders, nil
  60. }
  61. func GetSpecialOrderWinnersResult(ruleId, rehearsalId, archId interface{}) (result []*OrderWinnersResult, err error) {
  62. err = core.GetXormAuto().Table(&models.OrderDrawRecord{}).Alias("r").
  63. Select("r.order_entry_person_name as entry_person_name, r.user_id, o.receiver as user_name, "+
  64. " o.phone as user_phone, r.prize_name").Join("LEFT",
  65. (&models.CustomerOrder{}).Alias("o"), "o.id=r.customer_order_id and o.is_delete=0").
  66. Where("r.is_delete=0 and r.order_draw_rule_id=? and r.rehearsal_id=? and r.arch_id=?",
  67. ruleId, rehearsalId, archId).Find(&result)
  68. return
  69. }