| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Jobs;
- use App\Services\LogService;
- use App\Services\OrderService;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Database\Eloquent\Collection;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- class OrderCreateInstantBill implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable;
- protected $orders;
- /**
- * Create a new job instance.
- *
- * @param Collection $orders
- * @return void
- */
- public function __construct($orders)
- {
- $this->orders = $orders;
- }
- /**
- *
- * @param OrderService $service
- * @return void
- * @throws
- */
- public function handle(OrderService $service)
- {
- if ($this->orders){
- $errors = [];
- foreach ($this->orders as $order){
- try{
- if (!$service->createInstantBill($order))
- LogService::log(__METHOD__,"ERROR-订单生成即时账单",$order->toJson());
- }catch (\Error|\Exception $e){
- LogService::log(__METHOD__,"ERROR-订单生成即时账单",(is_subclass_of($order,Model::class) ? $order->toJson() : json_encode($order))." | ".$e->getMessage());
- $errors = ["order_".$order->id.":".$e->getMessage()];
- }
- }
- if ($errors)throw new \Exception(json_encode($errors));
- }
- }
- }
|