2
0

SentInChannelController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Api\ChannelApi;
  4. use App\Models\Sentence;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Response;
  7. use Illuminate\Support\Str;
  8. class SentInChannelController extends Controller
  9. {
  10. /**
  11. * 用channel 和句子编号列表查询句子
  12. *
  13. * @return Response
  14. */
  15. public function index(Request $request)
  16. {
  17. //
  18. }
  19. /**
  20. * Store a newly created resource in storage.
  21. *
  22. * @return Response
  23. */
  24. public function store(Request $request)
  25. {
  26. //
  27. $sent = $request->input('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 = [];
  37. $channelsInput = $request->input('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([
  49. 'id',
  50. 'book_id',
  51. 'paragraph',
  52. 'word_start',
  53. 'word_end',
  54. 'content',
  55. 'content_type',
  56. 'editor_uid',
  57. 'channel_uid',
  58. 'updated_at',
  59. ])
  60. ->whereIn('channel_uid', $channelsQuery)
  61. ->whereIns(['book_id', 'paragraph', 'word_start', 'word_end'], $query);
  62. $result = $table->get();
  63. return $this->ok(['rows' => $result, 'count' => count($result)]);
  64. }
  65. /**
  66. * Display the specified resource.
  67. *
  68. * @return Response
  69. */
  70. public function show(Sentence $sentence)
  71. {
  72. //
  73. }
  74. /**
  75. * Update the specified resource in storage.
  76. *
  77. * @return Response
  78. */
  79. public function update(Request $request, Sentence $sentence)
  80. {
  81. //
  82. }
  83. /**
  84. * Remove the specified resource from storage.
  85. *
  86. * @return Response
  87. */
  88. public function destroy(Sentence $sentence)
  89. {
  90. //
  91. }
  92. }