View.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. namespace Main\Src;
  3. use Dever;
  4. use Main\Lib\Core;
  5. class View extends Core
  6. {
  7. private $addView = true;
  8. public function version()
  9. {
  10. $source_type = Dever::input('source_type');
  11. $version['source_type'] = $source_type;
  12. $this->data['version'] = Dever::db('main/version')->getOne($version);
  13. if ($this->data['version']) {
  14. if (isset($this->data['version']['link'])) {
  15. $this->data['version']['link'] = str_replace('http://', 'https://', $this->data['version']['link']);
  16. }
  17. if (isset($this->data['version']['file'])) {
  18. $this->data['version']['file'] = str_replace('http://', 'https://', $this->data['version']['file']);
  19. }
  20. }
  21. return $this->data;
  22. }
  23. # 获取评论列表
  24. public function comment()
  25. {
  26. $id = Dever::input('id');
  27. if (!$id) {
  28. Dever::alert('错误的ID');
  29. }
  30. $type = Dever::input('type');
  31. if (!$type) {
  32. Dever::alert('错误的类型');
  33. }
  34. $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type, $this->data['uid']);
  35. if ($type == 3) {
  36. $this->data['live_status'] = 2;
  37. # 获取直播的状态
  38. $live = Dever::db('video/live')->one($id);
  39. if ($live && $live['stream_id']) {
  40. $this->data['live_status'] = Dever::load('live/api')->status($live['stream_id']);
  41. }
  42. }
  43. return $this->data;
  44. }
  45. private function get($method, $name, $type = 1, $key = '')
  46. {
  47. $id = Dever::input('id');
  48. if (!$id) {
  49. Dever::alert('错误的'.$name.'ID');
  50. }
  51. $this->data['info'] = Dever::load($method)->get($id, $this->data['uid']);
  52. if (!$this->data['info']) {
  53. Dever::alert('错误的'.$name.'ID');
  54. }
  55. $this->data['info'] = $this->pic($this->data['info']);
  56. if ($this->data['info']['pdate'] > 0) {
  57. $this->data['info']['pdate_time'] = date('Y-m-d H:i:s', $this->data['info']['pdate']);
  58. }
  59. /*
  60. if (isset($this->data['info']['share_content'])) {
  61. $source = Dever::db('source/info')->one(1);
  62. $this->data['info']['share_link'] = $source['code'];
  63. }
  64. */
  65. if ($this->source_type == 'ioss') {
  66. $source = Dever::db('source/info')->one(1);
  67. $this->data['info']['share_link'] = $source['code'];
  68. } else {
  69. $link = Dever::url('view.get?type=' . $type . '&id=' . $id, 'h5');
  70. $this->data['info']['share_link'] = $link;
  71. }
  72. if ($this->data['info']['num_view'] > 100000) {
  73. //$this->data['info']['num_view'] = '10w+';
  74. }
  75. if (isset($this->data['info']['cate_id']) && $this->data['info']['cate_id']) {
  76. $this->data['info']['cate'] = Dever::db('content/cate')->one($this->data['info']['cate_id']);
  77. }
  78. if (isset($this->data['info']['author_id']) && $this->data['info']['author_id']) {
  79. $this->data['info']['author'] = Dever::db('content/author')->one($this->data['info']['author_id']);
  80. }
  81. # 获取评论列表
  82. $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type, $this->data['uid']);
  83. # 获取相关推荐
  84. $this->data['relation'] = Dever::load($method)->getRelation($this->data['info']);
  85. if ($this->data['relation']) {
  86. foreach ($this->data['relation'] as $k => $v) {
  87. $this->data['relation'][$k] = $this->getInfo($type, $v);
  88. }
  89. }
  90. # 用户行为数据
  91. $this->data['user_act'] = array();
  92. # 获取当前用户分享数
  93. if ($this->data['uid'] > 0) {
  94. $this->data['user_act']['share'] = Dever::load('act/lib/share')->getRefluxNum($this->data['uid'], $id, $type);
  95. # 当前用户是否点赞
  96. $this->data['user_act']['up'] = Dever::load('act/lib/like')->get($this->data['uid'], $id, $type);
  97. Dever::score($this->data['uid'], 'view_' . $key, '浏览' . $name);
  98. } else {
  99. $this->data['user_act']['share'] = 0;
  100. $this->data['user_act']['up'] = 2;
  101. }
  102. # 用户预约
  103. if ($type == 3) {
  104. if ($this->data['uid'] > 0) {
  105. $this->data['user_act']['note'] = Dever::load('act/lib/note')->get($this->data['uid'], $id, $type);
  106. } else {
  107. $this->data['user_act']['note'] = 2;
  108. }
  109. /*
  110. if (isset($this->data['info']['status']) && $this->data['info']['status'] == 2) {
  111. # 直播中
  112. Dever::load('act/lib/watch')->submit($this->data['uid'], $id, $type);
  113. }
  114. */
  115. }
  116. /*
  117. if ($this->addView) {
  118. # 浏览量+1
  119. Dever::load($method)->addView($id);
  120. }
  121. */
  122. # 传给下一步操作的参数
  123. $this->data['end']['type'] = $type;
  124. $this->data['end']['id'] = $id;
  125. $this->data['end']['uid'] = $this->data['uid'];
  126. $this->data['end']['method'] = $method;
  127. $this->data['end']['addview'] = $this->addView;
  128. $this->data['end']['status'] = isset($this->data['info']['status']) ? $this->data['info']['status'] : false;
  129. return $this->data;
  130. }
  131. # 获取图文详情
  132. public function article()
  133. {
  134. return $this->get('content/lib/article', '图文', 1, 'article');
  135. }
  136. # 获取视频详情
  137. public function vod()
  138. {
  139. return $this->get('video/lib/vod', '视频', 2, 'vod');
  140. }
  141. # 获取直播详情
  142. public function live()
  143. {
  144. return $this->get('video/lib/live', '直播', 3, 'live');
  145. }
  146. # 获取专题详情
  147. public function feature()
  148. {
  149. return $this->get('feature/lib/info', '专题', 6, 'feature');
  150. }
  151. # 获取单页详情
  152. public function getPage()
  153. {
  154. $this->data['info'] = $this->page();
  155. return $this->data;
  156. }
  157. # 获取单页详情
  158. public function page()
  159. {
  160. $key = Dever::input('key');
  161. if (!$key) {
  162. Dever::alert('您访问的页面有误');
  163. }
  164. $info = Dever::db('content/page')->one(array('key' => $key . '_' . $this->data['system']));
  165. if (!$info) {
  166. $info = Dever::db('content/page')->one(array('key' => $key));
  167. }
  168. return $info;
  169. }
  170. # 根据类型,获取详情的html页面
  171. public function getHtml()
  172. {
  173. $this->addView = false;
  174. $type = Dever::input('type');
  175. $id = Dever::input('id');
  176. $signature = Dever::input('signature');
  177. $data = array();
  178. switch($type) {
  179. case 1:
  180. $data = $this->article();
  181. break;
  182. case 2:
  183. $data = $this->vod();
  184. break;
  185. case 3:
  186. $data = $this->live();
  187. break;
  188. case 4:
  189. # 这个有点特殊
  190. $info = Dever::db('journal/content')->one($id);
  191. if (!$info) {
  192. Dever::alert('错误的数据');
  193. }
  194. $data = Dever::load('main/journal')->readContent($info);
  195. break;
  196. case 6:
  197. $data = $this->feature();
  198. break;
  199. }
  200. if ($data) {
  201. if (isset($data['info']['content_array'])) {
  202. $data['content'] = $data['info']['content_array'];
  203. } elseif (isset($data['info']['content'])) {
  204. $data['content'][] = array
  205. (
  206. 'type' => 1,
  207. 'content' => $data['info']['content']
  208. );
  209. }
  210. if ($type == 6) {
  211. $data['css'] = 'feature';
  212. } else {
  213. $data['css'] = 'index';
  214. }
  215. return Dever::render('content', $data);
  216. } else {
  217. Dever::alert('错误的数据');
  218. }
  219. }
  220. # 获取会员的信息接口
  221. public function vip()
  222. {
  223. $this->data['vip_config'] = Dever::db('vip/config')->one(array('cate_id' => $this->data['system']));
  224. $this->data['vip_time'] = Dever::db('vip/time')->getAll(array('cate_id' => $this->data['system']));
  225. if ($this->data['uid'] > 0) {
  226. $user = Dever::load('passport/api')->info($this->data['uid']);
  227. $this->data['mobile'] = $user['mobile'];
  228. } else {
  229. $this->data['mobile'] = '';
  230. }
  231. return $this->data;
  232. }
  233. }