card.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package show
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/service/main/resource/model"
  7. "go-common/library/log"
  8. )
  9. var (
  10. _appPosRecSQL = "SELECT r.id,r.tab,r.resource_id,r.type,r.title,r.cover,r.re_type,r.re_value,r.plat_ver,r.desc,r.tag_id FROM app_pos_rec AS r WHERE r.stime<? AND r.etime>? AND r.state=1 AND r.resource_id=3 ORDER BY r.weight ASC"
  11. _appContentRSQL = "SELECT c.id,c.module,c.rec_id,c.ctype,c.cvalue,c.ctitle,c.tag_id FROM app_content AS c, app_pos_rec AS r WHERE c.rec_id=r.id AND r.state=1 AND r.stime<? AND r.etime>? AND c.module=1"
  12. )
  13. // PosRecs get pos resrouce
  14. func (d *Dao) PosRecs(c context.Context, now time.Time) (res map[int8][]*model.Card, err error) {
  15. res = map[int8][]*model.Card{}
  16. rows, err := d.db.Query(c, _appPosRecSQL, now, now)
  17. if err != nil {
  18. log.Error("d.PosRecs error(%v)", err)
  19. return
  20. }
  21. defer rows.Close()
  22. for rows.Next() {
  23. card := &model.Card{}
  24. if err = rows.Scan(&card.ID, &card.Tab, &card.RegionID, &card.Type, &card.Title, &card.Cover, &card.Rtype, &card.Rvalue, &card.PlatVer, &card.Desc, &card.TagID); err != nil {
  25. log.Error("d.PosRecs rows.Scan error(%v)", err)
  26. res = nil
  27. return
  28. }
  29. for _, limit := range card.CardPlatChange() {
  30. tmpc := &model.Card{}
  31. *tmpc = *card
  32. tmpc.Plat = limit.Plat
  33. tmpc.Build = limit.Build
  34. tmpc.Condition = limit.Condition
  35. tmpc.PlatVer = ""
  36. tmpc.TypeStr = model.GotoDaily
  37. tmpc.Goto = model.GotoDaily
  38. tmpc.Param = tmpc.Rvalue
  39. tmpc.URI = model.FillURI(tmpc.Goto, tmpc.Param)
  40. res[tmpc.Plat] = append(res[tmpc.Plat], tmpc)
  41. }
  42. }
  43. err = rows.Err()
  44. return
  45. }
  46. // RecContents get resource contents
  47. func (d *Dao) RecContents(c context.Context, now time.Time) (res map[int][]*model.Content, aids map[int][]int64, err error) {
  48. res = map[int][]*model.Content{}
  49. aids = map[int][]int64{}
  50. rows, err := d.db.Query(c, _appContentRSQL, now, now)
  51. if err != nil {
  52. log.Error("d.RecContents error(%v)", err)
  53. return
  54. }
  55. defer rows.Close()
  56. for rows.Next() {
  57. card := &model.Content{}
  58. if err = rows.Scan(&card.ID, &card.Module, &card.RecID, &card.Type, &card.Value, &card.Title, &card.TagID); err != nil {
  59. log.Error("d.RecContents rows.Scan error(%v)", err)
  60. res = nil
  61. return
  62. }
  63. res[card.RecID] = append(res[card.RecID], card)
  64. if card.Type == model.CardGotoAv {
  65. aidInt, _ := strconv.ParseInt(card.Value, 10, 64)
  66. aids[card.RecID] = append(aids[card.RecID], aidInt)
  67. }
  68. }
  69. err = rows.Err()
  70. return
  71. }