special.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package special
  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`,`cover`,`scover`,`re_type`,`re_value`,`corner`,`size`,`card` FROM special_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) Card(c context.Context) (scm map[int64]*operate.Special, err error) {
  21. rows, err := d.db.Query(c, _getSQL)
  22. if err != nil {
  23. return
  24. }
  25. defer rows.Close()
  26. scm = map[int64]*operate.Special{}
  27. for rows.Next() {
  28. sc := &operate.Special{}
  29. var cardType int
  30. if err = rows.Scan(&sc.ID, &sc.Title, &sc.Desc, &sc.Cover, &sc.SingleCover, &sc.ReType, &sc.ReValue, &sc.Badge, &sc.Size, &cardType); err != nil {
  31. return
  32. }
  33. sc.Change()
  34. switch cardType {
  35. case 3:
  36. if sc.Desc == "" {
  37. sc.Desc = "立即查看"
  38. }
  39. }
  40. scm[sc.ID] = sc
  41. }
  42. return scm, err
  43. }
  44. // Close close memcache resource.
  45. func (d *Dao) Close() {
  46. if d.db != nil {
  47. d.db.Close()
  48. }
  49. }