PrintOrderJob.php 1.4 KB

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