SuggestionApi.php 936 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Models\Discussion;
  4. use App\Models\Sentence;
  5. use App\Models\SentPr;
  6. class SuggestionApi
  7. {
  8. public static function getCountBySent($book, $para, $start, $end, $channel, $type = 'suggestion')
  9. {
  10. $count['suggestion'] = SentPr::where('book_id', $book)
  11. ->where('paragraph', $para)
  12. ->where('word_start', $start)
  13. ->where('word_end', $end)
  14. ->where('channel_uid', $channel)
  15. ->count();
  16. $sentId = Sentence::where('book_id', $book)
  17. ->where('paragraph', $para)
  18. ->where('word_start', $start)
  19. ->where('word_end', $end)
  20. ->where('channel_uid', $channel)
  21. ->value('uid');
  22. if ($sentId) {
  23. $count['discussion'] = Discussion::where('res_id', $sentId)
  24. ->whereNull('parent')
  25. ->count();
  26. }
  27. return $count;
  28. }
  29. }