ChapterIndexController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Channel;
  4. use App\Models\ProgressChapter;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Response;
  7. class ChapterIndexController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return Response
  13. */
  14. public function index(Request $request)
  15. {
  16. //
  17. switch ($request->input('view')) {
  18. case 'public':
  19. $channels = Channel::where('status', 30)->select('uid');
  20. $table = ProgressChapter::whereIn('channel_id', $channels);
  21. break;
  22. }
  23. if ($request->has('updated_at')) {
  24. $table = $table->where('updated_at', '>', $request->input('updated_at'));
  25. }
  26. if ($request->has('created_at')) {
  27. $table = $table->where('created_at', '>', $request->input('created_at'));
  28. }
  29. // 获取记录总条数
  30. $count = $table->count();
  31. // 处理排序
  32. $table = $table->orderBy(
  33. $request->input('order', 'created_at'),
  34. $request->input('dir', 'desc')
  35. );
  36. // 处理分页
  37. $table = $table->skip($request->input('offset', 0))
  38. ->take($request->input('limit', 200));
  39. // 获取数据
  40. $result = $table->get();
  41. return $this->ok(['rows' => $result, 'count' => $count]);
  42. }
  43. /**
  44. * Store a newly created resource in storage.
  45. *
  46. * @return Response
  47. */
  48. public function store(Request $request)
  49. {
  50. //
  51. }
  52. /**
  53. * Display the specified resource.
  54. *
  55. * @return Response
  56. */
  57. public function show(ProgressChapter $progressChapter)
  58. {
  59. //
  60. }
  61. /**
  62. * Update the specified resource in storage.
  63. *
  64. * @return Response
  65. */
  66. public function update(Request $request, ProgressChapter $progressChapter)
  67. {
  68. //
  69. }
  70. /**
  71. * Remove the specified resource from storage.
  72. *
  73. * @return Response
  74. */
  75. public function destroy(ProgressChapter $progressChapter)
  76. {
  77. //
  78. }
  79. }