| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Jobs;
- use App\Models\Order;
- use App\Models\ShopPrinter;
- use App\Servers\printer\PrinterServer;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldBeUnique;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- class PrintOrderJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- private $order_id;
- private $shop_id;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct($order_id, $shop_id)
- {
- $this->order_id = $order_id;
- $this->shop_id = $shop_id;
- }
- /**
- * Execute the job.
- *
- */
- public function handle()
- {
- $order_id = $this->order_id;
- var_dump('订单打印消息队列处理',$order_id);
- $shop_id = $this->shop_id;
- //获取商家打印机
- $printer = ShopPrinter::where('shop_id',$shop_id)->where('is_del',0)->get();
- foreach ($printer as $value){
- $res = PrinterServer::creatServer()->sendPrints($value->{'brand_id'},$value->{'sn'},$order_id);
- var_dump($res);
- if ($res){
- Order::where('id',$order_id)->where('shop_id',$shop_id)->update(['is_print'=>1]);
- }
- }
- return true;
- }
- }
|