Data.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace Push\Lib;
  3. use Dever;
  4. class Data
  5. {
  6. public function get($key, $name, $total = 10, $page = 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 ($page) {
  23. $data = Dever::db('push/data')->getAllPage(array('info_id' => $info['id'], 'page' => array($info['num'], 'list')));
  24. } else {
  25. $data = Dever::db('push/data')->getAll(array('info_id' => $info['id'], 'limit' => $info['num']));
  26. }
  27. if ($data) {
  28. foreach ($data as $k => $v) {
  29. $data[$k] = $this->getOne($v);
  30. }
  31. }
  32. }
  33. return $data;
  34. }
  35. private function getOne($info)
  36. {
  37. $info['id'] = 0;
  38. if ($info['type'] < 10) {
  39. $table = Dever::config('base')->type_table[$info['type']];
  40. if ($info['type'] == 1) {
  41. $id = $info['article_id'];
  42. } elseif ($info['type'] == 2) {
  43. $id = $info['vod_id'];
  44. } elseif ($info['type'] == 3) {
  45. $id = $info['live_id'];
  46. } elseif ($info['type'] == 4) {
  47. $id = $info['journal_id'];
  48. }
  49. unset($info['article_id']);
  50. unset($info['vod_id']);
  51. unset($info['live_id']);
  52. unset($info['journal_id']);
  53. if ($id > 0) {
  54. $info['id'] = $id;
  55. $data = Dever::db($table)->one($id);
  56. if (isset($data) && $data) {
  57. if (isset($data['name']) && $data['name'] && !$info['name']) {
  58. $info['name'] = $data['name'];
  59. }
  60. if (isset($data['pic_cover']) && $data['pic_cover'] && !$info['pic']) {
  61. $info['pic'] = $data['pic_cover'];
  62. }
  63. if (isset($data['pic_view_cover']) && $data['pic_view_cover'] && !$info['pic']) {
  64. $info['pic'] = $data['pic_view_cover'];
  65. }
  66. if (isset($data['pdate']) && $data['pdate']) {
  67. $info['cdate'] = $data['pdate'];
  68. }
  69. }
  70. }
  71. } else {
  72. unset($info['article_id']);
  73. unset($info['vod_id']);
  74. unset($info['live_id']);
  75. unset($info['journal_id']);
  76. }
  77. $info['cdate'] = date('Y-m-d', $info['cdate']);
  78. return $info;
  79. }
  80. }