Data.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace Push\Lib;
  3. use Dever;
  4. class Data
  5. {
  6. public function get($key, $name, $total = 10, $page = false, $limit = false)
  7. {
  8. $info = Dever::db('push/info')->one(array('key' => $key));
  9. if (!$info) {
  10. $insert['key'] = $key;
  11. $insert['name'] = $name;
  12. $insert['num'] = $total;
  13. $insert['col'] = '1,3';
  14. $info['id'] = Dever::db('push/info')->insert($insert);
  15. $info['num'] = $insert['num'];
  16. }
  17. $data = array();
  18. if ($info) {
  19. if (!$info['num']) {
  20. $info['num'] = 20;
  21. }
  22. if ($limit > 0) {
  23. $info['num'] = $limit;
  24. }
  25. $where = array();
  26. $where['info_id'] = $info['id'];
  27. if (checkVersion()->video == 2) {
  28. $where['type_no'] = 2;
  29. }
  30. if ($page) {
  31. $where['page'] = array($info['num'], 'list');
  32. $data = Dever::db('push/data')->getAllPage($where);
  33. } else {
  34. $where['limit'] = '0,' . $info['num'];
  35. $data = Dever::db('push/data')->getAll($where);
  36. }
  37. if ($data) {
  38. foreach ($data as $k => $v) {
  39. $data[$k] = $this->getOne($v);
  40. }
  41. }
  42. }
  43. return $data;
  44. }
  45. private function getOne($info)
  46. {
  47. $info['id'] = 0;
  48. if ($info['type'] < 10) {
  49. $table = Dever::config('base')->type_table[$info['type']];
  50. if ($info['type'] == 1) {
  51. $id = $info['article_id'];
  52. } elseif ($info['type'] == 2) {
  53. $id = $info['vod_id'];
  54. } elseif ($info['type'] == 3) {
  55. $id = $info['live_id'];
  56. } elseif ($info['type'] == 4) {
  57. $id = $info['journal_id'];
  58. }
  59. unset($info['article_id']);
  60. unset($info['vod_id']);
  61. unset($info['live_id']);
  62. unset($info['journal_id']);
  63. if ($id > 0) {
  64. $info['id'] = $id;
  65. $data = Dever::db($table)->one($id);
  66. if (isset($data) && $data) {
  67. if (isset($data['name']) && $data['name'] && !$info['name']) {
  68. $info['name'] = $data['name'];
  69. }
  70. if (isset($data['pic_cover']) && $data['pic_cover'] && !$info['pic']) {
  71. $info['pic'] = $data['pic_cover'];
  72. }
  73. if (isset($data['pic_view_cover']) && $data['pic_view_cover'] && !$info['pic']) {
  74. $info['pic'] = $data['pic_view_cover'];
  75. }
  76. if (isset($data['num_ding'])) {
  77. $info['num_ding'] = $data['num_ding'] + $data['num_add_ding'];
  78. }
  79. if (isset($data['buy'])) {
  80. $info['buy'] = $data['buy'];
  81. }
  82. if (isset($data['pdate']) && $data['pdate']) {
  83. $info['cdate'] = $data['pdate'];
  84. }
  85. if (isset($data['cate_id']) && $data['cate_id']) {
  86. $cate = Dever::db('content/cate')->one($data['cate_id']);
  87. $info['cate_name'] = $cate['name'];
  88. }
  89. if (isset($data['author_id']) && $data['author_id']) {
  90. $author = Dever::db('content/author')->one($data['author_id']);
  91. $info['author_name'] = $author['name'];
  92. }
  93. }
  94. }
  95. } else {
  96. unset($info['article_id']);
  97. unset($info['vod_id']);
  98. unset($info['live_id']);
  99. unset($info['journal_id']);
  100. }
  101. if ($info['link']) {
  102. if (!strstr($info['link'], 'http')) {
  103. $info['link'] = 'http://' . $info['link'];
  104. }
  105. }
  106. $info['cdate'] = date('Y-m-d', $info['cdate']);
  107. if (isset($info['pic']) && $info['pic']) {
  108. $info['pic'] = Dever::load('main/lib/core')->replacePic($info['pic']);
  109. }
  110. if (isset($info['name']) && $info['name']) {
  111. $info['name'] = Dever::cut($info['name'], 20, '...');
  112. }
  113. return $info;
  114. }
  115. }