DrillController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Http\Controllers\Api\V1\Mentality;
  3. use App\Models\MentalityDrillsSubject;
  4. use Illuminate\Http\Request;
  5. use App\Facades\MentalityDrillFacade;
  6. use App\Http\Controllers\Api\V1\BaseController;
  7. use App\Facades\BrowseRecordFacade;
  8. use App\Models\BrowseRecord;
  9. class DrillController extends BaseController
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. *
  14. * @return \Illuminate\Http\Response
  15. */
  16. public function index()
  17. {
  18. $commentTag = request('comment_tag');
  19. if ($commentTag){
  20. $commentTag = json_decode($commentTag);
  21. }
  22. $conditions = [
  23. 'category_id' => request('category_id'),
  24. 'search' => request('search'),
  25. 'comment_tag' => $commentTag
  26. ];
  27. $fields = ['*'];
  28. switch (request('sort')) {
  29. case 1: // 最新上架
  30. $sort = '`id` desc';
  31. break;
  32. case 2: // 最受欢迎
  33. $sort = '`number_of_studies` desc';
  34. break;
  35. default:
  36. $sort = '`rank` desc, `id` desc';
  37. }
  38. $page = request('page', 1);
  39. $limit = request('limit', 20);
  40. return MentalityDrillFacade::getList($conditions, $fields, $sort, $page, $limit);
  41. }
  42. /**
  43. * Store a newly created resource in storage.
  44. *
  45. * @param \Illuminate\Http\Request $request
  46. * @return \Illuminate\Http\Response
  47. */
  48. public function store(Request $request)
  49. {
  50. //
  51. }
  52. /**
  53. * Display the specified resource.
  54. *
  55. * @param int $id
  56. * @return \Illuminate\Http\Response
  57. */
  58. public function show($id)
  59. {
  60. $conditions = [
  61. 'id' => $id
  62. ];
  63. $record = [
  64. 'uid' => $this->auth(),
  65. 'column' => BrowseRecord::COLUMN_2,
  66. 'object_id' => $id,
  67. 'repeat' => 'uid:'.$this->auth().' column:'.BrowseRecord::COLUMN_2.' object_id:'.$id
  68. ];
  69. //加入浏览记录
  70. try {
  71. BrowseRecordFacade::create($record);
  72. } catch (\Exception $e) {
  73. }
  74. return MentalityDrillFacade::findBy($conditions, ['*']);
  75. }
  76. /**
  77. * Update the specified resource in storage.
  78. *
  79. * @param \Illuminate\Http\Request $request
  80. * @param int $id
  81. * @return \Illuminate\Http\Response
  82. */
  83. public function update(Request $request, $id)
  84. {
  85. //
  86. }
  87. /**
  88. * 播放训练科目
  89. * @param int $id
  90. * @return mixed
  91. */
  92. public function playSubject(int $id)
  93. {
  94. $record = [
  95. 'uid' => $this->auth(),
  96. 'column' => BrowseRecord::COLUMN_4,
  97. 'object_id' => $id,
  98. 'repeat' => 'uid:'.$this->auth().' column:'.BrowseRecord::COLUMN_4.' object_id:'.$id
  99. ];
  100. //加入浏览记录
  101. try {
  102. BrowseRecordFacade::create($record);
  103. } catch (\Exception $e) {
  104. }
  105. return response()->horesp(1000, MentalityDrillsSubject::query()->find($id), "成功");
  106. }
  107. /**
  108. * 点赞
  109. * @param $id
  110. * @return array
  111. */
  112. public function thumbsUpNum($id)
  113. {
  114. return MentalityDrillFacade::thumbsUpNum($id,$this->auth());
  115. }
  116. /**
  117. * 喜欢
  118. * @param $id
  119. * @return array
  120. */
  121. public function loveNum($id)
  122. {
  123. return MentalityDrillFacade::loveNum($id,$this->auth());
  124. }
  125. /**
  126. * 留言
  127. * @param Request $request
  128. * @return array
  129. */
  130. public function leaveMessage(Request $request)
  131. {
  132. $id = $request->get("id",0);
  133. $message = $request->get("message",0);
  134. return MentalityDrillFacade::leaveMessage($id,$this->auth(),$message);
  135. }
  136. /**
  137. * Remove the specified resource from storage.
  138. *
  139. * @param int $id
  140. * @return \Illuminate\Http\Response
  141. */
  142. public function destroy($id)
  143. {
  144. //
  145. }
  146. }