VideoController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\VideoCollectService;
  5. use App\Services\Api\VideoService;
  6. use App\Services\RedisService;
  7. use Illuminate\Http\Request;
  8. /**
  9. * 短视频服务管理
  10. * @package App\Http\Controllers\Api
  11. */
  12. class VideoController extends webApp
  13. {
  14. /**
  15. * 列表
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. // try {
  21. $params = request()->post();
  22. $pageSize = request()->post('pageSize', 0);
  23. $datas = VideoService::make()->getIndexList($params, $pageSize,'', $this->userId);
  24. return message(1010, true, $datas);
  25. // } catch (\Exception $exception){
  26. // RedisService::set("caches:request:error_video_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  27. // return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  28. // }
  29. }
  30. /**
  31. * 列表
  32. * @return array
  33. */
  34. public function list()
  35. {
  36. try {
  37. $params = request()->post();
  38. $pageSize = request()->post('pageSize', 0);
  39. $type = request()->post('type', 1);
  40. // 我的视频
  41. if($type == 1){
  42. $datas = VideoService::make()->getDataList($params, $pageSize,'', $this->userId);
  43. }
  44. // 喜欢的视频
  45. else if ($type == 2){
  46. }
  47. // 收藏的视频
  48. else if ($type == 3){
  49. }
  50. // 观看历史
  51. else if ($type == 4){
  52. }
  53. return message(1010, true, $datas);
  54. } catch (\Exception $exception){
  55. RedisService::set("caches:request:error_video_list", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  56. return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
  57. }
  58. }
  59. /**
  60. * 详情
  61. * @return array
  62. */
  63. public function info()
  64. {
  65. $id = request()->post('id', 0);
  66. $info = VideoService::make()->getInfo($id, $this->userId);
  67. return message(1010, true, $info);
  68. }
  69. /**
  70. * 发布
  71. * @return array
  72. */
  73. public function publish(Request $request)
  74. {
  75. $params = request()->all();
  76. if(!$result = VideoService::make()->publish($this->userId, $params, $request)){
  77. return message(VideoService::make()->getError(), false);
  78. }else{
  79. return message(VideoService::make()->getError(), true, $result);
  80. }
  81. }
  82. /**
  83. * 播放与浏览
  84. * @return array
  85. */
  86. public function updatePlay()
  87. {
  88. $id = request()->post('id',0);
  89. if(!$result = VideoService::make()->updatePlay($this->userId, $id)){
  90. return message(VideoService::make()->getError(), false);
  91. }else{
  92. return message(VideoService::make()->getError(), true, $result);
  93. }
  94. }
  95. /**
  96. * 点赞
  97. * @return array|mixed
  98. */
  99. public function like()
  100. {
  101. $params = request()->post();
  102. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  103. return message(VideoService::make()->getError(), false);
  104. }else{
  105. return message(VideoService::make()->getError(), true, $result);
  106. }
  107. }
  108. /**
  109. * 收藏
  110. * @return array|mixed
  111. */
  112. public function collect()
  113. {
  114. $params = request()->post();
  115. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  116. return message(VideoService::make()->getError(), false);
  117. }else{
  118. return message(VideoService::make()->getError(), true, $result);
  119. }
  120. }
  121. /**
  122. * 状态/上下架
  123. * @return array|mixed
  124. */
  125. public function status()
  126. {
  127. if(!$result = VideoService::make()->status()){
  128. return message(VideoService::make()->getError(), false);
  129. }else{
  130. return message(VideoService::make()->getError(), true, $result);
  131. }
  132. }
  133. /**
  134. * 删除
  135. * @return array|mixed
  136. */
  137. public function delete()
  138. {
  139. if(!$result = VideoService::make()->delete()){
  140. return message(VideoService::make()->getError(), false);
  141. }else{
  142. return message(VideoService::make()->getError(), true);
  143. }
  144. }
  145. }