CommentService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Services\Deed;
  3. use App\Exceptions\AlertException;
  4. use App\Models\Deed\DeedCommentModel;
  5. use App\Models\Deed\DeedModel;
  6. use App\Services\Service;
  7. /**
  8. * 契约评论
  9. * Class CommentService
  10. * @package App\Services\Deed
  11. * @deprecated
  12. */
  13. class CommentService extends Service
  14. {
  15. /**
  16. * 评论契约
  17. * @param int $deed_id
  18. * @param array $comments
  19. * @return bool
  20. * @throws AlertException
  21. */
  22. public function comment(int $deed_id, array $comments)
  23. {
  24. $deed = DeedModel::findOrFail($deed_id);
  25. if (empty($deed->number)) {
  26. throw new AlertException('契约失效', 401);
  27. }
  28. if (DeedCommentModel::where([['number', $deed->number], ['uid', $deed->uid]])->exists()) {
  29. $deed->state = 5;
  30. $deed->save();
  31. throw new AlertException('契约失效', 402);
  32. }
  33. $other = DeedModel::where([['number', $deed->number], ['id', '!=', $deed_id]])->first();
  34. \DB::beginTransaction();
  35. try {
  36. \DB::table('kdgx_fpdx_deed_comment')->insert([
  37. 'created_at' => time(),
  38. 'updated_at' => time(),
  39. 'number' => $deed->number,
  40. 'uid' => $deed->uid,
  41. 'comment_uid' => $other->uid,
  42. 'speed' => $comments['speed'],
  43. 'level' => $comments['level'],
  44. ]);
  45. \DB::table('kdgx_fpdx_deed')->where('id', $deed_id)->update(['state' => 5, 'complete_at' => time()]);
  46. \DB::commit();
  47. return true;
  48. } catch (\Exception $e) {
  49. \DB::rollBack();
  50. return false;
  51. }
  52. }
  53. }