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

51 lines
1.7 KiB

5 years ago
5 years ago
  1. package lottery_service
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "hudongzhuanjia/models"
  5. "hudongzhuanjia/utils/define"
  6. )
  7. func GetOrderLotteryUserIds(repeat string, activityId, ruleId, ladderId, rehearsalId, areaId interface{}) ([]int64, error) {
  8. var err error
  9. var userIds = make([]int64, 0)
  10. var recordIds = make([]int64, 0)
  11. if repeat == define.MODULE_BESIDE_REPEAT {
  12. //查询已经中奖的用户,剔除已经中奖的用户
  13. err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Select("user_id").
  14. Where("order_draw_rule_id=? and rehearsal_id=? and is_delete=0",
  15. ruleId, rehearsalId).Find(&recordIds)
  16. } else {
  17. // 不去除
  18. err = core.GetXormAuto().Table(new(models.OrderDrawRecord)).Select("user_id").
  19. Where("order_draw_rule_ladder_id=? and rehearsal_id=?",
  20. ladderId, rehearsalId).Find(&recordIds)
  21. }
  22. if err != nil {
  23. return nil, err
  24. }
  25. err = core.GetXormAuto().Table(new(models.CustomerOrder)).
  26. Select("buyer_id as user_id").Distinct("buyer_id").
  27. Where("activity_id=? and rehearsal_id=? and area_id=? and is_delete=0",
  28. activityId, rehearsalId, areaId).NotIn("buyer_id", recordIds).
  29. Find(&userIds)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return userIds, nil
  34. }
  35. func GetOrderWinnersResult(ruleId, rehearsalId interface{}) ([]*WinnersResult, error) {
  36. result := make([]*WinnersResult, 0)
  37. err := core.GetXormAuto().Table(new(models.OrderDrawRecord)).Alias("r").
  38. Select("r.user_id, u.nickname as username, u.phone as user_phone, u.avatar, r.prize_name").
  39. Join("LEFT", new(models.User).Alias("u"), "u.id=r.user_id and u.is_delete=0").
  40. Where("r.is_delete=0 and r.order_draw_rule_id=? and r.rehearsal_id=?",
  41. ruleId, rehearsalId).Find(&result)
  42. if err != nil {
  43. return nil, err
  44. }
  45. return result, nil
  46. }