OrderCreateInstantBill.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Jobs;
  3. use App\Components\ErrorPush;
  4. use App\Services\LogService;
  5. use App\Services\OrderService;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Database\Eloquent\Collection;
  9. use Illuminate\Database\QueryException;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. /**
  13. * @Deprecated 即时账单生成
  14. */
  15. class OrderCreateInstantBill implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, ErrorPush;
  18. protected $orders;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @param Collection $orders
  23. * @return void
  24. */
  25. public function __construct($orders)
  26. {
  27. $this->orders = $orders;
  28. }
  29. /**
  30. *
  31. * @param OrderService $service
  32. * @return void
  33. * @throws
  34. */
  35. public function handle(OrderService $service)
  36. {
  37. if ($this->orders){
  38. $errors = [];
  39. foreach ($this->orders as $order){
  40. try{
  41. if (!$service->createInstantBill($order))
  42. $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$order->toJson());
  43. }catch(QueryException $qe){
  44. if ($qe->getCode()!='23000'){
  45. $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$order->toJson()." | ".$qe->getMessage());
  46. $errors = ["order_".$order->id.":".$qe->getMessage()];
  47. }
  48. }catch (\Exception $e){
  49. $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$order->toJson()." | ".$e->getMessage());
  50. $errors = ["order_".$order->id.":".$e->getMessage()];
  51. }
  52. }
  53. if ($errors)throw new \Exception(json_encode($errors));
  54. }
  55. }
  56. }