StoreCreateInstantBill.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\StoreService;
  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 StoreCreateInstantBill implements ShouldQueue
  16. {
  17. use Dispatchable, InteractsWithQueue, Queueable, ErrorPush;
  18. protected $stores;
  19. /**
  20. * Create a new job instance.
  21. *
  22. * @param Collection $stores
  23. * @return void
  24. */
  25. public function __construct($stores)
  26. {
  27. $this->stores = $stores;
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @param StoreService $service
  33. * @return void
  34. * @throws
  35. */
  36. public function handle(StoreService $service)
  37. {
  38. if (!$this->stores)return;
  39. $errors = [];
  40. foreach ($this->stores as $store){
  41. try{
  42. if (!$service->createInstantBill($store))
  43. $this->push(__METHOD__."->".__LINE__,"订单生成即时账单",$store->toJson());
  44. }catch(QueryException $qe){
  45. if ($qe->getCode()!='23000'){
  46. $this->push(__METHOD__."->".__LINE__,"入库生成即时账单",$store->toJson()." | ".$qe->getMessage());
  47. $errors = ["store_".$store->id.":".$qe->getMessage()];
  48. }
  49. }catch (\Exception $e){
  50. $this->push(__METHOD__."->".__LINE__,"入库生成即时账单",$store->toJson()." | ".$e->getMessage());
  51. $errors = ["store_".$store->id.":".$e->getMessage()];
  52. }
  53. }
  54. if ($errors)throw new \Exception(json_encode($errors));
  55. }
  56. }