2
0

ChapterIOController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ChapterIOController 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. $table = ProgressChapter::select([
  18. 'uid',
  19. 'book',
  20. 'para',
  21. 'channel_id',
  22. 'progress',
  23. 'lang',
  24. 'title',
  25. 'summary',
  26. 'updated_at',
  27. 'created_at',
  28. ]);
  29. switch ($request->input('view')) {
  30. case 'public':
  31. $channels = Channel::where('status', 30)->select('uid')->get();
  32. $table->whereIn('channel_id', $channels)
  33. ->where('updated_at', '>', $request->input('updated_at', '2000-1-1'));
  34. break;
  35. }
  36. $count = $table->count();
  37. // 处理排序
  38. $table->orderBy('updated_at', 'asc');
  39. // 处理分页
  40. $table->skip($request->input('offset', 0))
  41. ->take($request->input('limit', 200));
  42. // 获取数据
  43. $result = $table->get();
  44. return $this->ok(['rows' => $result, 'count' => $count]);
  45. }
  46. /**
  47. * Store a newly created resource in storage.
  48. *
  49. * @return Response
  50. */
  51. public function store(Request $request)
  52. {
  53. //
  54. }
  55. /**
  56. * Display the specified resource.
  57. *
  58. * @return Response
  59. */
  60. public function show(ProgressChapter $progressChapter)
  61. {
  62. //
  63. }
  64. /**
  65. * Update the specified resource in storage.
  66. *
  67. * @return Response
  68. */
  69. public function update(Request $request, ProgressChapter $progressChapter)
  70. {
  71. //
  72. }
  73. /**
  74. * Remove the specified resource from storage.
  75. *
  76. * @return Response
  77. */
  78. public function destroy(ProgressChapter $progressChapter)
  79. {
  80. //
  81. }
  82. }