game_open_log_qp.go 2.5 KB

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