CancelMergeMessageJob.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /*
  3. * This file is part of the ZhMead/laravel-logger.
  4. *
  5. * (c) Mead <751066209@qql.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Jobs\Manage;
  11. use App\Repositories\Enums\Manage\AnalysisStatusEnum;
  12. use App\Repositories\Enums\Manage\DealStatusEnum;
  13. use App\Repositories\Models\Manage\Message;
  14. use App\Repositories\Models\Manage\PreMessage;
  15. use App\Repositories\Models\Manage\Task;
  16. use Carbon\Carbon;
  17. use Illuminate\Bus\Queueable;
  18. use Illuminate\Contracts\Queue\ShouldQueue;
  19. use Illuminate\Queue\InteractsWithQueue;
  20. use Illuminate\Support\Facades\DB;
  21. use Illuminate\Support\Facades\Log;
  22. class CancelMergeMessageJob implements ShouldQueue
  23. {
  24. use InteractsWithQueue;
  25. use Queueable;
  26. private $ID;
  27. /**
  28. * Create a new job instance.
  29. */
  30. public function __construct($ID)
  31. {
  32. $this->ID = $ID;
  33. }
  34. /**
  35. * 确定任务应该超时的时间
  36. *
  37. * @return \DateTime
  38. */
  39. public function retryUntil()
  40. {
  41. return Carbon::now()->addHours(8);
  42. }
  43. /**
  44. * Execute the job.
  45. */
  46. public function handle()
  47. {
  48. $this->merge();
  49. }
  50. /**
  51. * 导入数据
  52. * @return false|void
  53. */
  54. public function merge()
  55. {
  56. $model = Task::query()->find($this->ID);
  57. $model->status = AnalysisStatusEnum::CANCEL_MERGE_IN;
  58. $model->save();
  59. DB::beginTransaction();
  60. try {
  61. Log::error('*************合并数据中*****************');
  62. Message::query()->where('task_id', $this->ID)->where('similar_pid', '>', 0)->update([
  63. 'similar_pid' => 0,
  64. 'deal_admin_id' => 0,
  65. 'deal_status' => DealStatusEnum::WAIT,
  66. 'deal_idea' => NULL,
  67. 'deal_time' => NULL,
  68. 'task_id' => 0,
  69. ]);
  70. Message::query()->where('task_id', $this->ID)->where('similar_pid', '=', 0)->update([
  71. 'similar_pid' => 0,
  72. 'similar_nums' => 0,
  73. 'task_id' => 0,
  74. ]);
  75. DB::commit();
  76. $model->status = AnalysisStatusEnum::CHECK_DATA;
  77. } catch (\Exception $exception) {
  78. DB::rollBack();
  79. Log::error($exception);
  80. $model->status = AnalysisStatusEnum::MERGE_ERROR;
  81. $model->message = $exception;
  82. }
  83. $model->save();
  84. Log::error("-----------完成---------------");
  85. }
  86. }