game.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package game
  2. import (
  3. "context"
  4. "go-common/app/interface/main/app-card/model/card/operate"
  5. "go-common/app/interface/main/app-channel/conf"
  6. "go-common/library/database/sql"
  7. )
  8. const (
  9. _getSQL = "SELECT `id`,`title`,`desc`,`icon`,`cover`,`url_type`,`url_value`,`btn_txt`,`re_type`,`re_value`,`number`,`double_cover` FROM download_card"
  10. )
  11. type Dao struct {
  12. db *sql.DB
  13. }
  14. func New(c *conf.Config) (d *Dao) {
  15. d = &Dao{
  16. db: sql.NewMySQL(c.MySQL.Manager),
  17. }
  18. return
  19. }
  20. func (d *Dao) DownLoad(c context.Context) (dm map[int64]*operate.Download, err error) {
  21. rows, err := d.db.Query(c, _getSQL)
  22. if err != nil {
  23. return
  24. }
  25. defer rows.Close()
  26. dm = map[int64]*operate.Download{}
  27. for rows.Next() {
  28. d := &operate.Download{}
  29. if err = rows.Scan(&d.ID, &d.Title, &d.Desc, &d.Icon, &d.Cover, &d.URLType, &d.URLValue, &d.BtnTxt, &d.ReType, &d.ReValue, &d.Number, &d.DoubleCover); err != nil {
  30. return
  31. }
  32. d.Change()
  33. dm[d.ID] = d
  34. }
  35. return
  36. }
  37. // Close close memcache resource.
  38. func (d *Dao) Close() {
  39. if d.db != nil {
  40. d.db.Close()
  41. }
  42. }