VideoController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. try{
  124. $params = request()->post();
  125. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  126. return showJson(VideoCollectService::make()->getError(), false);
  127. }else{
  128. return showJson(VideoCollectService::make()->getError(), true, $result);
  129. }
  130. }catch (\Exception $exception){
  131. return showJson(1003, false,$exception->getMessage());
  132. }
  133. }
  134. /**
  135. * 收藏
  136. * @return array|mixed
  137. */
  138. public function collect()
  139. {
  140. try{
  141. $params = request()->post();
  142. if(!$result = VideoCollectService::make()->collect($this->userId, $params)){
  143. return showJson(VideoCollectService::make()->getError(), false);
  144. }else{
  145. return showJson(VideoCollectService::make()->getError(), true, $result);
  146. }
  147. }catch (\Exception $exception){
  148. return showJson(1003, false,$exception->getMessage());
  149. }
  150. }
  151. /**
  152. * 状态
  153. * @return array|mixed
  154. */
  155. public function status()
  156. {
  157. if(!$result = VideoService::make()->status()){
  158. return showJson(VideoService::make()->getError(), false);
  159. }else{
  160. return showJson(VideoService::make()->getError(), true, $result);
  161. }
  162. }
  163. /**
  164. * 状态
  165. * @return array|mixed
  166. */
  167. public function visible()
  168. {
  169. if(!$result = VideoService::make()->visible()){
  170. return showJson(VideoService::make()->getError(), false);
  171. }else{
  172. return showJson(VideoService::make()->getError(), true, $result);
  173. }
  174. }
  175. /**
  176. * 删除
  177. * @return array|mixed
  178. */
  179. public function delete()
  180. {
  181. if(!$result = VideoService::make()->delete()){
  182. return showJson(VideoService::make()->getError(), false);
  183. }else{
  184. return showJson(VideoService::make()->getError(), true);
  185. }
  186. }
  187. }