Video.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\controller;
  3. use think\facade\Request;
  4. use app\model\Videos;
  5. class Video extends CommonController
  6. {
  7. // 视频列表
  8. public function index()
  9. {
  10. // 分页参数
  11. $pn = Request::param('pn') ?? 1;
  12. $pagesize = 10;
  13. $limit = ($pn - 1) * $pagesize;
  14. $where = ['status' => 1];
  15. $search = Request::param('search') ?? '';
  16. $field = ['id' , 'title' , 'video_url' , 'page_view'];
  17. if($search) {
  18. // 获取视频数据
  19. $list = Videos::field($field)->where($where)->where('title' , 'like' , "%$search%")->limit($limit , $pagesize)->select();
  20. $count = Videos::where($where)->where("title" , "like" , "%$search%")->count();
  21. } else {
  22. // 获取视频数据
  23. $list = Videos::field($field)->where($where)->limit($limit , $pagesize)->select();
  24. $count = Videos::where($where)->count();
  25. }
  26. foreach ($list as $key => $value) {
  27. $is_http = $_SERVER['SERVER_PORT'] == 443 ? 'https://jm.admin.jiankangche.cn' : 'http://localhost:8124';
  28. $list[$key]['video_url'] = $is_http . '/uploads/' . $value['video_url'];
  29. }
  30. return $this->_json_succ(
  31. [
  32. 'count' => $count , 'list' => $list
  33. ]
  34. );
  35. }
  36. // 更新浏览次数
  37. public function recordPv()
  38. {
  39. $id = Request::param('v_id') ?? '';
  40. if(!$id) return $this->_json_error('请求有误!');
  41. $result = Videos::where('id' , $id)->inc('page_view' , 1)->update();
  42. if($result) {
  43. return $this->_json_succ();
  44. }
  45. return $this->_json_error();
  46. }
  47. }