ChannelIOController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Channel;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Response;
  6. class ChannelIOController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return Response
  12. */
  13. public function index(Request $request)
  14. {
  15. //
  16. $table = Channel::select([
  17. 'uid',
  18. 'name',
  19. 'summary',
  20. 'type',
  21. 'owner_uid',
  22. 'lang',
  23. 'status',
  24. 'updated_at',
  25. 'created_at',
  26. ]);
  27. switch ($request->input('view')) {
  28. case 'public':
  29. $table->where('status', 30)
  30. ->where('updated_at', '>', $request->input('updated_at', '2000-1-1'));
  31. break;
  32. }
  33. $count = $table->count();
  34. // 处理排序
  35. $table->orderBy('updated_at', 'asc');
  36. // 处理分页
  37. $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(Channel $channel)
  58. {
  59. //
  60. }
  61. /**
  62. * Update the specified resource in storage.
  63. *
  64. * @return Response
  65. */
  66. public function update(Request $request, Channel $channel)
  67. {
  68. //
  69. }
  70. /**
  71. * Remove the specified resource from storage.
  72. *
  73. * @return Response
  74. */
  75. public function destroy(Channel $channel)
  76. {
  77. //
  78. }
  79. }