SentInChannelController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Sentence;
  4. use Illuminate\Http\Request;
  5. use App\Http\Api\ChannelApi;
  6. use Illuminate\Support\Str;
  7. class SentInChannelController extends Controller
  8. {
  9. /**
  10. * 用channel 和句子编号列表查询句子
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index(Request $request)
  15. {
  16. //
  17. }
  18. /**
  19. * Store a newly created resource in storage.
  20. *
  21. * @param \Illuminate\Http\Request $request
  22. * @return \Illuminate\Http\Response
  23. */
  24. public function store(Request $request)
  25. {
  26. //
  27. $sent = $request->get('sentences') ;
  28. $query = [];
  29. foreach ($sent as $value) {
  30. # code...
  31. $ids = explode('-',$value);
  32. if(count($ids)===4){
  33. $query[] = $ids;
  34. }
  35. }
  36. $channelsQuery = array();
  37. $channelsInput = $request->get('channels');
  38. foreach ($channelsInput as $value) {
  39. if(Str::isUuid($value)){
  40. $channelsQuery[] = $value;
  41. }else{
  42. $channelId = ChannelApi::getSysChannel($value);
  43. if($channelId){
  44. $channelsQuery[] = $channelId;
  45. }
  46. }
  47. }
  48. $table = Sentence::select(['id','book_id','paragraph',
  49. 'word_start','word_end','content','content_type',
  50. 'editor_uid','channel_uid','updated_at'])
  51. ->whereIn('channel_uid', $channelsQuery)
  52. ->whereIns(['book_id','paragraph','word_start','word_end'],$query);
  53. $result = $table->get();
  54. return $this->ok(["rows"=>$result,"count"=>count($result)]);
  55. }
  56. /**
  57. * Display the specified resource.
  58. *
  59. * @param \App\Models\Sentence $sentence
  60. * @return \Illuminate\Http\Response
  61. */
  62. public function show(Sentence $sentence)
  63. {
  64. //
  65. }
  66. /**
  67. * Update the specified resource in storage.
  68. *
  69. * @param \Illuminate\Http\Request $request
  70. * @param \App\Models\Sentence $sentence
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function update(Request $request, Sentence $sentence)
  74. {
  75. //
  76. }
  77. /**
  78. * Remove the specified resource from storage.
  79. *
  80. * @param \App\Models\Sentence $sentence
  81. * @return \Illuminate\Http\Response
  82. */
  83. public function destroy(Sentence $sentence)
  84. {
  85. //
  86. }
  87. }