MusicController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\BaseController;
  4. use App\Services\MusicCollectService;
  5. use App\Services\MusicPlayedService;
  6. use App\Services\MusicService;
  7. use App\Services\MusicSheetsService;
  8. use Illuminate\Http\Request;
  9. /**
  10. * 佛音控制器类
  11. * @author wesmiler
  12. * @since 2020/11/10
  13. * Class MusicController
  14. * @package App\Http\Controllers
  15. */
  16. class MusicController extends BaseController
  17. {
  18. /**
  19. * 构造函数
  20. * @author wesmiler
  21. * @since 2020/11/11
  22. * MusicController constructor.
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. $this->service = new MusicService();
  28. $this->cateService = new MusicSheetsService();
  29. $this->collectService = new MusicCollectService();
  30. $this->playService = new MusicPlayedService();
  31. }
  32. /**
  33. * 列表
  34. * @return array
  35. */
  36. public function index(){
  37. $params = request()->all();
  38. $type = request()->get('type', 1);
  39. $params['user_id'] = $this->userId;
  40. if($type ==1){
  41. return $this->service->getDataList($params);
  42. }else if($type == 2){
  43. return $this->playService->getDataList($params);
  44. }else if($type == 3){
  45. return $this->collectService->getDataList($params);
  46. }
  47. return message(MESSAGE_FAILED,false, []);
  48. }
  49. /**
  50. * 详情
  51. * @return array|mixed
  52. */
  53. public function detail(){
  54. $id = request()->get('id',0);
  55. if($id<=0){
  56. return message(1006, false);
  57. }
  58. $this->service->updateVisit($this->userId);
  59. $info = $this->service->getDetail($id, $this->userId);
  60. return message(1005, true, $info);
  61. }
  62. /**
  63. * 获取分类
  64. * @return mixed
  65. */
  66. public function cates(){
  67. return $this->cateService->getOptions();
  68. }
  69. /**
  70. * 收藏
  71. * @return mixed
  72. */
  73. public function collect(){
  74. return $this->collectService->save($this->userId);
  75. }
  76. /**
  77. * 播放
  78. * @return mixed
  79. */
  80. public function play(){
  81. return $this->playService->save($this->userId);
  82. }
  83. /**
  84. * 播放
  85. * @return mixed
  86. */
  87. public function playList(){
  88. $params = request()->all();
  89. $params['user_id'] = $this->userId;
  90. return $this->playService->getDataList($params);
  91. }
  92. }