game_open_log_qp.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package model
  2. import (
  3. "time"
  4. "github.com/sirupsen/logrus"
  5. "github.com/spf13/viper"
  6. "gogs.daxia.dev/huanan/pkg.daxia.dev/db"
  7. )
  8. type GameOpenLogQP struct {
  9. ID uint `gorm:"primarykey"`
  10. CreatedAt time.Time
  11. UpdatedAt time.Time
  12. Issue string `gorm:"type:varchar(25);comment:'期号'"`
  13. RoomID int32 `gorm:"type:int;comment:'房间ID'"`
  14. RoomType int32 `gorm:"type:int;comment:'房间类型'"`
  15. GameID int32 `gorm:"type:int;comment:'游戏ID'"`
  16. GameName string `gorm:"type:varchar(255);comment:'游戏名称'"`
  17. DayStr string `gorm:"type:varchar(255);comment:'日期'"`
  18. Index int32 `gorm:"type:int;comment:'开奖索引'"`
  19. OpenNumber1 string `gorm:"type:varchar(255);comment:'开奖号码1'"`
  20. OpenNumber2 string `gorm:"type:varchar(255);comment:'开奖号码2'"`
  21. OpenNumber3 string `gorm:"type:varchar(255);comment:'开奖号码3'"`
  22. OpenNumber4 string `gorm:"type:varchar(255);comment:'开奖号码4'"`
  23. OpenNumber5 string `gorm:"type:varchar(255);comment:'开奖号码5'"`
  24. Hash string `gorm:"type:varchar(255);comment:'开奖hash'"`
  25. OpenTime *time.Time
  26. IsOpen int32 `gorm:"type:int;comment:'是否开放搜索'"`
  27. }
  28. func (GameOpenLogQP) TableName() string {
  29. return "game_open_log_qp"
  30. }
  31. func (p GameOpenLogQP) Init() error {
  32. var err error
  33. if db.GetDB().Migrator().HasTable(p) {
  34. return nil
  35. }
  36. err = db.GetDB().Migrator().CreateTable(p)
  37. if err != nil {
  38. logrus.Fatal(err)
  39. return err
  40. }
  41. err = db.GetDB().Exec("create unique index idx_game_id_issue on game_open_log_qp (game_id, issue)").Error
  42. if err != nil {
  43. return err
  44. }
  45. return nil
  46. }
  47. func (p *GameOpenLogQP) GetByIssue(issueStr string) error {
  48. gameID := viper.GetInt32("game_id")
  49. err := db.GetDB().Model(p).Where("game_id = ? and issue = ?", gameID, issueStr).First(p).Error
  50. if err != nil {
  51. logrus.Error(err)
  52. return err
  53. }
  54. return nil
  55. }
  56. func (p GameOpenLogQP) GetListByIssueList(issueStrList []string) ([]GameOpenLogQP, error) {
  57. gameID := viper.GetInt32("game_id")
  58. GameOpenLogQPListModel := make([]GameOpenLogQP, 0)
  59. err := db.GetDB().Model(p).Where("game_id = ? and issue in ?", gameID, issueStrList).Scan(&GameOpenLogQPListModel).Error
  60. if err != nil {
  61. logrus.Error(err)
  62. return nil, err
  63. }
  64. return GameOpenLogQPListModel, nil
  65. }
  66. func (p GameOpenLogQP) Exists(issueStr string) (bool, error) {
  67. var err error
  68. gameID := viper.GetInt32("game_id")
  69. count := int64(0)
  70. err = db.GetDB().Model(p).Where("issue = ? and game_id = ?", issueStr, gameID).Count(&count).Error
  71. if err != nil {
  72. logrus.Error(err, issueStr)
  73. return false, err
  74. }
  75. return count != 0, nil
  76. }