RunBookRentention.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Jobs;
  3. use App\Modules\Book\Models\RententionBookTaskList;
  4. use App\Modules\Book\Services\RententionBookService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Queue\SerializesModels;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Foundation\Bus\Dispatchable;
  10. class RunBookRentention implements ShouldQueue
  11. {
  12. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  13. private $bid;
  14. /**
  15. * Create a new job instance.
  16. *
  17. * @return void
  18. */
  19. public function __construct(int $bid)
  20. {
  21. $this->bid = $bid;
  22. }
  23. /**
  24. * Execute the job.
  25. *
  26. * @return void
  27. */
  28. public function handle()
  29. {
  30. $task = RententionBookTaskList::where('bid', $this->bid)
  31. ->where('status', RententionBookService::ready_status)
  32. ->where('is_deleted', 0)
  33. ->orderBy('id', 'desc')
  34. ->first();
  35. if ($task) {
  36. myLog('rentention_book')->info('bid: ' . $this->bid . ' begin: ' . date('Y-m-d H:i:s'));
  37. RententionBookService::updateRententionBookTask($task->id, RententionBookService::running_status);
  38. RententionBookService::runRentention($this->bid);
  39. RententionBookService::saveRententionBook($this->bid, true);
  40. RententionBookService::updateRententionBookTask($task->id, RententionBookService::completed_status);
  41. myLog('rentention_book')->info('bid: ' . $this->bid . ' end: ' . date('Y-m-d H:i:s'));
  42. }
  43. }
  44. }