Video.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\client\controller;
  3. use think\facade\Request;
  4. use app\event\FootPrints;
  5. use app\model\VideoType;
  6. use app\model\Video as VideoModel;
  7. class Video extends Base
  8. {
  9. /**
  10. * 视频列表
  11. */
  12. public function list($page, $limit, $type = '', $label='', $keyword = '')
  13. {
  14. $condition[] = ['root_id','=',request()->token['root_org']];
  15. $condition[] = ['publish','=',1];
  16. $condition[] = ['delete_time','=',0];
  17. empty($label) ?: $condition[] = ['label', '=', $label];
  18. empty($type) ?: $condition[] = ['type', '=', $type];
  19. empty($keyword) ?: $condition[] = ['title', 'like', '%' . $keyword . '%'];
  20. // 获取数据
  21. $data = VideoModel::where($condition)->field('id,title,description,video_url,cover')->page($page , $limit)->order('uploadtime desc')->select()->toArray();
  22. $count = VideoModel::where($condition)->count();
  23. return json(['code' => 0, 'data' => $data, 'count' => $count, 'msg' => '获取成功']);
  24. }
  25. /**
  26. * 类型获取
  27. */
  28. public function type()
  29. {
  30. $type = VideoType::where(['pid'=>0 , 'type'=>'video', 'root_id' => request()->token['root_org']])->select()->toArray();
  31. $label = VideoType::where([['pid','>',0] , ['type','=','video'],['root_id','=',request()->token['root_org']]])->select()->toArray();
  32. foreach($type as &$val)
  33. {
  34. $val['sonLabel'] = [];
  35. foreach($label as $typeVal)
  36. {
  37. if($val['id'] == $typeVal['pid'])
  38. {
  39. $val['sonLabel'][] = $typeVal;
  40. }
  41. }
  42. }
  43. return json(['code' => 0, 'data' => $type, 'msg' => '获取成功']);
  44. }
  45. /**
  46. * 获取视频详情
  47. */
  48. public function info($video_id)
  49. {
  50. $video = VideoModel::where(['id'=>$video_id , 'publish'=>1 , 'delete_time'=>0])->find();
  51. // 添加足迹
  52. $token = request()->token;
  53. if (!empty($token['uid']) && !$token['isEmployee']) {
  54. event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $video));
  55. }
  56. if (!$token['isEmployee']) {
  57. VideoModel::where('id', '=', $video_id)->inc('view_times')->update();
  58. }
  59. return json(['code' => 0, 'msg' => '获取成功', 'data' => $video]);
  60. }
  61. }