VideoController.php 4.5 KB

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