View.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace Main\Src;
  3. use Dever;
  4. use Main\Lib\Core;
  5. class View extends Core
  6. {
  7. # 获取评论列表
  8. public function comment()
  9. {
  10. $id = Dever::input('id');
  11. if (!$id) {
  12. Dever::alert('错误的ID');
  13. }
  14. $type = Dever::input('type');
  15. if (!$type) {
  16. Dever::alert('错误的类型');
  17. }
  18. $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type, $this->data['uid']);
  19. if ($type == 3) {
  20. $this->data['live_status'] = 2;
  21. # 获取直播的状态
  22. $live = Dever::db('video/live')->one($id);
  23. if ($live && $live['stream_id']) {
  24. $this->data['live_status'] = Dever::load('live/api')->status($live['stream_id']);
  25. }
  26. }
  27. return $this->data;
  28. }
  29. private function get($method, $name, $type = 1, $key = '')
  30. {
  31. $id = Dever::input('id');
  32. if (!$id) {
  33. Dever::alert('错误的'.$name.'ID');
  34. }
  35. $this->data['info'] = Dever::load($method)->get($id);
  36. if (!$this->data['info']) {
  37. Dever::alert('错误的'.$name.'ID');
  38. }
  39. $this->data['info'] = $this->pic($this->data['info']);
  40. if ($this->data['info']['pdate'] > 0) {
  41. $this->data['info']['pdate_time'] = date('Y-m-d H:i:s', $this->data['info']['pdate']);
  42. }
  43. if ($this->data['info']['num_view'] > 100000) {
  44. $this->data['info']['num_view'] = '10w+';
  45. }
  46. if (isset($this->data['info']['cate_id']) && $this->data['info']['cate_id']) {
  47. $this->data['info']['cate'] = Dever::db('content/cate')->one($this->data['info']['cate_id']);
  48. }
  49. if (isset($this->data['info']['author_id']) && $this->data['info']['author_id']) {
  50. $this->data['info']['author'] = Dever::db('content/author')->one($this->data['info']['author_id']);
  51. }
  52. # 获取评论列表
  53. $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type, $this->data['uid']);
  54. # 获取相关推荐
  55. $this->data['relation'] = Dever::load($method)->getRelation($this->data['info']);
  56. if ($this->data['relation']) {
  57. foreach ($this->data['relation'] as $k => $v) {
  58. $this->data['relation'][$k] = $this->getInfo($type, $v);
  59. }
  60. }
  61. # 用户行为数据
  62. $this->data['user_act'] = array();
  63. # 获取当前用户分享数
  64. if ($this->data['uid'] > 0) {
  65. $this->data['user_act']['share'] = Dever::load('act/lib/share')->getRefluxNum($this->data['uid'], $id, $type);
  66. # 当前用户是否点赞
  67. $this->data['user_act']['up'] = Dever::load('act/lib/like')->get($this->data['uid'], $id, $type);
  68. Dever::score($this->data['uid'], 'view_' . $key, '浏览' . $name);
  69. } else {
  70. $this->data['user_act']['share'] = 0;
  71. $this->data['user_act']['up'] = 2;
  72. }
  73. # 用户预约
  74. if ($type == 3) {
  75. if ($this->data['uid'] > 0) {
  76. $this->data['user_act']['note'] = Dever::load('act/lib/note')->get($this->data['uid'], $id, $type);
  77. } else {
  78. $this->data['user_act']['note'] = 2;
  79. }
  80. if (isset($this->data['info']['status']) && $this->data['info']['status'] == 2) {
  81. # 直播中
  82. Dever::load('act/lib/watch')->submit($this->data['uid'], $id, $type);
  83. }
  84. }
  85. # 浏览量+1
  86. Dever::load($method)->addView($id);
  87. return $this->data;
  88. }
  89. # 获取图文详情
  90. public function article()
  91. {
  92. return $this->get('content/lib/article', '图文', 1, 'article');
  93. }
  94. # 获取视频详情
  95. public function vod()
  96. {
  97. return $this->get('video/lib/vod', '视频', 2, 'vod');
  98. }
  99. # 获取直播详情
  100. public function live()
  101. {
  102. return $this->get('video/lib/live', '直播', 3, 'live');
  103. }
  104. }