BroadcastBatchToZhengCangJob.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Jobs;
  3. use App\Batch;
  4. use App\Exceptions\ErrorException;
  5. use App\Log;
  6. use App\Services\ForeignZhenCangService;
  7. use App\Services\LogService;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Queue\SerializesModels;
  13. class BroadcastBatchToZhengCangJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. private $batches;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct($batches)
  23. {
  24. $this->batches=$batches;
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. * @return void
  30. */
  31. public function handle()
  32. {
  33. /** @var ForeignZhenCangService $foreignZhenCangService */
  34. $foreignZhenCangService=app('ForeignZhenCangService');
  35. if(!$this->batches){throw new ErrorException('波次任务中波次不存在!');}
  36. $batchCollect=collect($this->batches);
  37. //暂时直接指定 375 妍柯货主
  38. $batches=Batch::query()->where('owner_id',375)->whereIn('id',data_get($batchCollect,'*.id'))->get();
  39. try {
  40. foreach ($batches as &$batch) {
  41. $batch->loadMissing([
  42. 'orders.orderCommodities.commodity.barcodes'
  43. ]);
  44. $foreignZhenCangService->broadcastBatch($batch);
  45. }
  46. } catch (\Exception $e) {
  47. LogService::log(__METHOD__,'BroadcastBatchToZhengCangJob','波次任务推送祯仓失败'.json_encode($e->getMessage()));
  48. }
  49. }
  50. }