View.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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);
  19. return $this->data;
  20. }
  21. private function get($method, $name, $type = 1)
  22. {
  23. $id = Dever::input('id');
  24. if (!$id) {
  25. Dever::alert('错误的'.$name.'ID');
  26. }
  27. $this->data['info'] = Dever::load($method)->get($id);
  28. if (!$this->data['info']) {
  29. Dever::alert('错误的'.$name.'ID');
  30. }
  31. # 获取评论列表
  32. $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type);
  33. # 获取相关推荐
  34. $this->data['relation'] = Dever::load($method)->getRelation($this->data['info']);
  35. if ($this->data['relation']) {
  36. foreach ($this->data['relation'] as $k => $v) {
  37. $this->data['relation'][$k] = $this->getInfo($type, $v);
  38. }
  39. }
  40. # 获取当前用户分享数
  41. if ($this->data['uid'] > 0) {
  42. $this->data['share'] = Dever::load('act/lib/share')->getRefluxNum($this->data['uid'], $id, $type);
  43. } else {
  44. $this->data['share'] = 0;
  45. }
  46. # 浏览量+1
  47. Dever::load($method)->addView($id);
  48. return $this->data;
  49. }
  50. # 获取图文详情
  51. public function article()
  52. {
  53. return $this->get('content/lib/article', '图文', 1);
  54. }
  55. # 获取视频详情
  56. public function vod()
  57. {
  58. return $this->get('video/lib/vod', '视频', 2);
  59. }
  60. # 获取直播详情
  61. public function live()
  62. {
  63. return $this->get('video/lib/live', '直播', 3);
  64. }
  65. }