ComplaintMessageJob.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Jobs\Info;
  3. use App\Repositories\Models\Info\Complaint;
  4. use App\Repositories\Models\Info\ComplaintMessage;
  5. use Carbon\Carbon;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Log;
  11. class ComplaintMessageJob implements ShouldQueue
  12. {
  13. use InteractsWithQueue;
  14. use Queueable;
  15. public $tries = 1;
  16. public $timeout = 1440;
  17. private $complaintId;
  18. /**
  19. * Create a new job instance.
  20. */
  21. public function __construct($complaintId)
  22. {
  23. $this->$complaintId = $complaintId;
  24. }
  25. /**
  26. * 确定任务应该超时的时间
  27. *
  28. * @return \DateTime
  29. */
  30. public function retryUntil()
  31. {
  32. return Carbon::now()->addHours(24);
  33. }
  34. /**
  35. * Execute the job.
  36. */
  37. public function handle()
  38. {
  39. $this->analysis();
  40. }
  41. /**
  42. *
  43. * @return false|void
  44. */
  45. public function analysis()
  46. {
  47. $model = Complaint::query()->where('id', $this->complaintId)->first();
  48. DB::beginTransaction();
  49. try {
  50. Log::error('*************创建数据*****************');
  51. ComplaintMessage::query()->create([
  52. 'complaint_id' => $model->id,
  53. 'complaint_status' => $model->deal_status,
  54. 'deal_admin_id' => $model->deal_admin_id,
  55. ]);
  56. DB::commit();
  57. } catch (\Exception $exception) {
  58. DB::rollBack();
  59. Log::error("
  60. **********消息创建失效*****************
  61. exception: {$exception->getMessage()}
  62. ");
  63. }
  64. Log::error("-----------完成---------------");
  65. }
  66. }