BroadcastBatchToZhengCangJob.php 1.7 KB

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