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

80 lines
4.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 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 models
  2. import (
  3. "github.com/ouxuanserver/osmanthuswine/src/core"
  4. "time"
  5. )
  6. const LotteryDrawRecordTableName = TableNamePrefix + "lottery_draw_record"
  7. type LotteryDrawRecord struct {
  8. Id int64 `json:"id" xorm:"pk autoincr"`
  9. ActivityId int64 `json:"activity_id" xorm:"not null comment('主活动id')"`
  10. RehearsalId int64 `json:"rehearsal_id" xorm:"not null comment('彩排id/0正式')"`
  11. UserPrizeId int64 `json:"user_prize_id" xorm:"not null comment('用户奖品id') INT(11)"`
  12. LotteryDrawActivityId int64 `json:"lottery_draw_activity_id" xorm:"not null comment('抽奖活动id')"`
  13. LotteryDrawRuleId int64 `json:"lottery_draw_rule_id" xorm:"not null comment('抽奖规则id') BIGINT(20)"`
  14. LotteryDrawRuleLadderId int64 `json:"lottery_draw_rule_ladder_id" xorm:"not null comment('规则阶梯id')"`
  15. UserId int64 `json:"user_id" xorm:"not null comment('用户id')"`
  16. RollNum int `json:"roll_num" xrom:"not null default 0 comment('滚动次数') INT(11)"`
  17. UserName string `json:"user_name" description:"用户名" xorm:"not null comment('用户名')"`
  18. UserPhone string `json:"user_phone" description:"电话" xorm:"not null comment('电话号码')"`
  19. PrizeName string `json:"prize_name" description:"奖品名字" xorm:"not null comment('奖品名字')"`
  20. AreaName string `json:"area_name" description:"名字" xorm:"not null comment('地区名字')"`
  21. AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id')"`
  22. Status int `json:"status" xorm:"not null default 0 comment('是否已经兑奖0否1是') TINYINT(1)"`
  23. Name string `json:"name" xorm:"not null default '' comment('姓名') VARCHAR(128)"`
  24. Phone string `json:"phone" xorm:"not null default '' comment('电话号码') VARCHAR(128)"`
  25. WxNo string `json:"wx_no" xorm:"not null default '' comment('微信号') VARCHAR(128)"`
  26. Address string `json:"address" xorm:"not null default '' comment('地址') VARCHAR(128)"`
  27. IsDelete bool `json:"-" xorm:"default(0)"`
  28. CreatedAt time.Time `json:"-" xorm:"created"`
  29. UpdatedAt time.Time `json:"-" xorm:"updated"`
  30. // 无关变量
  31. User *User `json:"user" xorm:"-"`
  32. LotteryDrawRuleLadder *LotteryDrawRuleLadder `json:"lottery_draw_rule_ladder" xorm:"-"`
  33. }
  34. func (t *LotteryDrawRecord) TableName() string {
  35. return LotteryDrawRecordTableName
  36. }
  37. func (t *LotteryDrawRecord) GetByUserIdAndLadderId(userId, ladderId interface{}, rollNum int) (bool, error) {
  38. session := core.GetXormAuto().Where("is_delete=0 and user_id=? and lottery_draw_rule_ladder_id=?", userId, ladderId)
  39. defer session.Close()
  40. if rollNum > 0 {
  41. session.Where("roll_num=?", rollNum)
  42. }
  43. return session.Get(t)
  44. }
  45. func (t *LotteryDrawRecord) GetByUserPrizeId(upId int64) (bool, error) {
  46. return core.GetXormAuto().Where("is_delete=0 and user_prize_id=?", upId).Get(t)
  47. }
  48. func GetLotteryUsersResultByLotteryDrawRecord(obj, ladderId, rehearsalId interface{}, rollNum int) error {
  49. session := core.GetXormAuto().Table(new(LotteryDrawRecord)).Alias("r").
  50. Join("LEFT", new(User).Alias("u"), "u.id=r.user_id").
  51. Where("r.is_delete=0 and r.lottery_draw_rule_ladder_id=? and "+
  52. "r.rehearsal_id=?", ladderId, rehearsalId)
  53. defer session.Close()
  54. if rollNum > 0 {
  55. session = session.Where("roll_num=?", rollNum)
  56. }
  57. return session.Find(&obj)
  58. }
  59. func GetUserIdsByLotteryDrawRuleId(ruleId, rehearsalId, areaId interface{}) ([]int64, error) {
  60. recordIds := make([]int64, 0)
  61. err := core.GetXormAuto().Table(new(LotteryDrawRecord)).Select("user_id").
  62. Where("lottery_draw_rule_id=? and rehearsal_id=? and area_id=? and is_delete=0",
  63. ruleId, rehearsalId, areaId).Find(&recordIds)
  64. return recordIds, err
  65. }
  66. func (t *LotteryDrawRecord) CountRecord(ruleId, ladderId, rehearsalId, areaId interface{}) (int64, error) {
  67. return core.GetXormAuto().Where("lottery_draw_rule_id=? and lottery_draw_rule_ladder_id=? "+
  68. "and rehearsal_id=? and area_id=? and is_delete=0", ruleId, ladderId, rehearsalId, areaId).
  69. Count(t)
  70. }