VideoController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. $datas = VideoService::make()->getDataList($params, $pageSize,'', $this->userId);
  41. return showJson(1010, true, $datas);
  42. } catch (\Exception $exception){
  43. RedisService::set("caches:request:error_video_list", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  44. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
  45. }
  46. }
  47. /**
  48. * 短剧列表
  49. * @return array
  50. */
  51. public function shortList()
  52. {
  53. try {
  54. $params = request()->post();
  55. $pageSize = request()->post('pageSize', 0);
  56. $datas = VideoService::make()->getShortlist($params, $pageSize,'', $this->userId);
  57. return showJson(1010, true, $datas);
  58. } catch (\Exception $exception){
  59. RedisService::set("caches:request:error_video_short_list", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  60. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
  61. }
  62. }
  63. /**
  64. * 详情
  65. * @return array
  66. */
  67. public function info()
  68. {
  69. $id = request()->post('id', 0);
  70. $info = VideoService::make()->getInfo($id, $this->userId);
  71. if($info){
  72. return showJson(1010, true, $info);
  73. }else{
  74. return showJson(1009, false);
  75. }
  76. }
  77. /**
  78. * 详情
  79. * @return array
  80. */
  81. public function shortInfo()
  82. {
  83. $id = request()->post('id', 0);
  84. $info = VideoService::make()->getShortInfo($id, $this->userId);
  85. if($info){
  86. return showJson(1010, true, $info);
  87. }else{
  88. return showJson(1009, false);
  89. }
  90. }
  91. /**
  92. * 发布
  93. * @return array
  94. */
  95. public function publish(Request $request)
  96. {
  97. $params = request()->all();
  98. if(!$result = VideoService::make()->publish($this->userId, $params, $request)){
  99. return showJson(VideoService::make()->getError(), false);
  100. }else{
  101. return showJson(VideoService::make()->getError(), true, $result);
  102. }
  103. }
  104. /**
  105. * 播放与浏览
  106. * @return array
  107. */
  108. public function updatePlay()
  109. {
  110. $id = request()->post('id',0);
  111. if(!$result = VideoService::make()->updatePlay($this->userId, $id)){
  112. return showJson(VideoService::make()->getError(), false);
  113. }else{
  114. return showJson(VideoService::make()->getError(), true, $result);
  115. }
  116. }
  117. /**
  118. * 点赞
  119. * @return array|mixed
  120. */
  121. public function like()
  122. {
  123. $params = request()->post();
  124. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  125. return showJson(VideoCollectService::make()->getError(), false);
  126. }else{
  127. return showJson(VideoCollectService::make()->getError(), true, $result);
  128. }
  129. }
  130. /**
  131. * 收藏
  132. * @return array|mixed
  133. */
  134. public function collect()
  135. {
  136. $params = request()->post();
  137. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  138. return showJson(VideoCollectService::make()->getError(), false);
  139. }else{
  140. return showJson(VideoCollectService::make()->getError(), true, $result);
  141. }
  142. }
  143. /**
  144. * 状态
  145. * @return array|mixed
  146. */
  147. public function status()
  148. {
  149. if(!$result = VideoService::make()->status()){
  150. return showJson(VideoService::make()->getError(), false);
  151. }else{
  152. return showJson(VideoService::make()->getError(), true, $result);
  153. }
  154. }
  155. /**
  156. * 删除
  157. * @return array|mixed
  158. */
  159. public function delete()
  160. {
  161. if(!$result = VideoService::make()->delete()){
  162. return showJson(VideoService::make()->getError(), false);
  163. }else{
  164. return showJson(VideoService::make()->getError(), true);
  165. }
  166. }
  167. }