SentenceService.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Services;
  3. use App\Models\Sentence;
  4. use App\Models\SentHistory;
  5. use Illuminate\Support\Str;
  6. class SentenceService
  7. {
  8. public function save($data)
  9. {
  10. $row = Sentence::firstOrNew([
  11. "book_id" => $data['book_id'],
  12. "paragraph" => $data['paragraph'],
  13. "word_start" => $data['word_start'],
  14. "word_end" => $data['word_end'],
  15. "channel_uid" => $data['channel_uid'],
  16. ], [
  17. "id" => app('snowflake')->id(),
  18. "uid" => Str::uuid(),
  19. ]);
  20. $row->content = $data['content'];
  21. if (isset($data['content_type']) && !empty($data['content_type'])) {
  22. $row->content_type = $data['content_type'];
  23. }
  24. $row->strlen = mb_strlen($data['content'], "UTF-8");
  25. $row->language = $data['lang'];
  26. $row->status = $data['status'];
  27. if (isset($data['copy'])) {
  28. //复制句子,保留原作者信息
  29. $row->editor_uid = $data["editor_uid"];
  30. $row->acceptor_uid = $data["acceptor_uid"];
  31. $row->pr_edit_at = $data["updated_at"];
  32. if (isset($data['fork_from'])) {
  33. $row->fork_at = now();
  34. }
  35. } else {
  36. $row->editor_uid = $data["editor_uid"];
  37. $row->acceptor_uid = null;
  38. $row->pr_edit_at = null;
  39. }
  40. $row->create_time = time() * 1000;
  41. $row->modify_time = time() * 1000;
  42. $row->save();
  43. }
  44. }