PrintOrderJob.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\ShopPrinter;
  4. use App\Servers\printer\PrinterServer;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldBeUnique;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Queue\SerializesModels;
  11. class PrintOrderJob implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. private $order_id;
  15. private $shop_id;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct($order_id, $shop_id)
  22. {
  23. $this->order_id = $order_id;
  24. $this->shop_id = $shop_id;
  25. }
  26. /**
  27. * Execute the job.
  28. *
  29. */
  30. public function handle()
  31. {
  32. $order_id = $this->order_id;
  33. var_dump('外卖订单打印消息队列处理',$order_id);
  34. $shop_id = $this->shop_id;
  35. //获取商家打印机
  36. $printer = ShopPrinter::where('shop_id',$shop_id)->where('is_del',0)->get();
  37. foreach ($printer as $value){
  38. $res = PrinterServer::creatServer()->sendPrints($value->{'brand_id'},$value->{'sn'},$order_id);
  39. var_dump($res);
  40. }
  41. return true;
  42. }
  43. }