CourseController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\CourseService;
  5. use App\Services\Common\VideosDatasCategoryService;
  6. use App\Services\Common\VideosDatasService;
  7. use App\Services\Common\VideosReadsService;
  8. /**
  9. * 视频课管理
  10. * @package App\Http\Controllers\Api
  11. */
  12. class CourseController extends webApp
  13. {
  14. /**
  15. * 主页列表
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. try {
  21. $params = request()->all();
  22. $datas = CourseService::make()->getListByCate($params);
  23. return message(1010, true, $datas);
  24. } catch (\Exception $exception) {
  25. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  26. return message(1009, false, $error);
  27. }
  28. }
  29. /**
  30. * 视频课列表
  31. * @return array
  32. */
  33. public function videos()
  34. {
  35. try {
  36. $params = request()->all();
  37. $pageSize = isset($params['pageSize'])? $params['pageSize'] : 10;
  38. $datas = CourseService::make()->getVideoList($params, $pageSize);
  39. return message(1010, true, $datas);
  40. } catch (\Exception $exception) {
  41. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  42. return message(1009, false, $error);
  43. }
  44. }
  45. /**
  46. * 列表
  47. * @return array
  48. */
  49. public function list()
  50. {
  51. try {
  52. $params = request()->all();
  53. $groupId = isset($params['gid']) ? $params['gid'] : 0;
  54. if (empty($groupId)) {
  55. return message(1036, false);
  56. }
  57. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  58. $datas = CourseService::make()->getListByGroup($groupId, $params, $pageSize);
  59. return message(1010, true, $datas);
  60. } catch (\Exception $exception) {
  61. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  62. return message(1009, false, $error);
  63. }
  64. }
  65. /**
  66. * 详情
  67. */
  68. public function info()
  69. {
  70. try {
  71. $params = request()->all();
  72. $id = isset($params['id']) ? intval($params['id']) : 0;
  73. if (empty($id)) {
  74. return message(1036, false);
  75. }
  76. if ($info = CourseService::make()->getInfo($this->userId, $id)) {
  77. return message(1010, true, $info);
  78. } else {
  79. return message(1009, false);
  80. }
  81. } catch (\Exception $exception) {
  82. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  83. return message(1009, false, $error);
  84. }
  85. }
  86. /**
  87. * 学习
  88. */
  89. public function learn()
  90. {
  91. try {
  92. $params = request()->all();
  93. $id = isset($params['id']) ? intval($params['id']) : 0;
  94. if (empty($id)) {
  95. return message(1036, false);
  96. }
  97. if ($info = CourseService::make()->learn($this->userId, $id)) {
  98. return message(1010, true, $info);
  99. } else {
  100. return message(1009, false);
  101. }
  102. } catch (\Exception $exception) {
  103. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  104. return message(1009, false, $error);
  105. }
  106. }
  107. /**
  108. * 视频课数据分类
  109. * @return array
  110. */
  111. public function dataCategory(){
  112. try {
  113. $datas = VideosDatasCategoryService::make()->options();
  114. return message(1010, true, $datas);
  115. } catch (\Exception $exception) {
  116. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  117. return message(1009, false, $error);
  118. }
  119. }
  120. /**
  121. * 表单数据
  122. */
  123. public function form()
  124. {
  125. try {
  126. $params = request()->all();
  127. if ($info = VideosDatasService::make()->formSubmit($this->userId, $params)) {
  128. return message(VideosDatasService::make()->getError(), true, $info);
  129. } else {
  130. return message(VideosDatasService::make()->getError(), false);
  131. }
  132. } catch (\Exception $exception) {
  133. $error = ['error' => $exception->getMessage(), 'trace' => $exception->getTrace()];
  134. return message(1046, false, $error);
  135. }
  136. }
  137. }