ProgressChapterController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\ProgressChapter;
  4. use App\Models\Channel;
  5. use Illuminate\Http\Request;
  6. class ProgressChapterController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return \Illuminate\Http\Response
  12. */
  13. public function index(Request $request)
  14. {
  15. //
  16. $selectCol = ['progress_chapters.book','progress_chapters.para','progress_chapters.channel_id','progress_chapters.title','pali_texts.toc','progress','progress_chapters.created_at','progress_chapters.updated_at'];
  17. $chapters=false;
  18. switch ($request->get('view')) {
  19. case 'studio':
  20. #查询该studio的channel
  21. $channels = Channel::where('owner_uid',$request->get('id'))->select('uid')->get();
  22. $aChannel = [];
  23. foreach ($channels as $channel) {
  24. # code...
  25. $aChannel[] = $channel->uid;
  26. }
  27. $chapters = ProgressChapter::select($selectCol)
  28. ->whereIn('progress_chapters.channel_id', $aChannel)
  29. ->leftJoin('pali_texts', function($join)
  30. {
  31. $join->on('progress_chapters.book', '=', 'pali_texts.book');
  32. $join->on('progress_chapters.para','=','pali_texts.paragraph');
  33. })
  34. ->where('progress','>',0.85)
  35. ->orderby('progress_chapters.created_at','desc')
  36. ->get();
  37. break;
  38. case 'tag':
  39. $aChannel = [67,68,69,70];
  40. $chapters = ProgressChapter::select($selectCol)
  41. ->whereIn('progress_chapters.book', $aChannel)
  42. ->leftJoin('pali_texts', function($join)
  43. {
  44. $join->on('progress_chapters.book', '=', 'pali_texts.book');
  45. $join->on('progress_chapters.para','=','pali_texts.paragraph');
  46. })
  47. ->orderby('progress','desc')
  48. ->get();
  49. break;
  50. }
  51. if($chapters){
  52. return $this->ok(["rows"=>$chapters,"count"=>count($chapters)]);
  53. }else{
  54. return $this->error("没有查询到数据");
  55. }
  56. }
  57. /**
  58. * Show the form for creating a new resource.
  59. *
  60. * @return \Illuminate\Http\Response
  61. */
  62. public function create()
  63. {
  64. //
  65. }
  66. /**
  67. * Store a newly created resource in storage.
  68. *
  69. * @param \Illuminate\Http\Request $request
  70. * @return \Illuminate\Http\Response
  71. */
  72. public function store(Request $request)
  73. {
  74. //
  75. }
  76. /**
  77. * Display the specified resource.
  78. *
  79. * @param \App\Models\ProgressChapter $progressChapter
  80. * @return \Illuminate\Http\Response
  81. */
  82. public function show(ProgressChapter $progressChapter)
  83. {
  84. //
  85. }
  86. /**
  87. * Show the form for editing the specified resource.
  88. *
  89. * @param \App\Models\ProgressChapter $progressChapter
  90. * @return \Illuminate\Http\Response
  91. */
  92. public function edit(ProgressChapter $progressChapter)
  93. {
  94. //
  95. }
  96. /**
  97. * Update the specified resource in storage.
  98. *
  99. * @param \Illuminate\Http\Request $request
  100. * @param \App\Models\ProgressChapter $progressChapter
  101. * @return \Illuminate\Http\Response
  102. */
  103. public function update(Request $request, ProgressChapter $progressChapter)
  104. {
  105. //
  106. }
  107. /**
  108. * Remove the specified resource from storage.
  109. *
  110. * @param \App\Models\ProgressChapter $progressChapter
  111. * @return \Illuminate\Http\Response
  112. */
  113. public function destroy(ProgressChapter $progressChapter)
  114. {
  115. //
  116. }
  117. }