PackageCollectingAllocation.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Jobs;
  3. use App\OrderPackage;
  4. use App\Services\OrderPackageService;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Log;
  11. class PackageCollectingAllocation implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable;
  14. /** @var OrderPackage|\stdClass $orderPackage */
  15. private $orderPackage;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct(OrderPackage $package)
  22. {
  23. $this->orderPackage = $package;
  24. }
  25. /**
  26. * Execute the job.
  27. *
  28. * @return void
  29. */
  30. public function handle()
  31. {
  32. /** @var OrderPackageService $orderPackageService */
  33. $orderPackageService = app('OrderPackageService');
  34. DB::beginTransaction();
  35. try {
  36. $result = OrderPackage::query()->where("id",$this->orderPackage->id)
  37. ->where("collecting_status",0)->update(["collecting_status"=>1]);
  38. if ($result==1){
  39. $result = $orderPackageService->collectUpload([$this->orderPackage->logistic_number]);
  40. if (!$result["success"]){
  41. DB::rollBack();
  42. Log::warning("自动揽收失败",["message"=>$result["message"],"param"=>$this->orderPackage->logistic_number]);
  43. return;
  44. }else Log::info("揽收成功",["id"=>$this->orderPackage->id,"number"=>$this->orderPackage->logistic_number]);
  45. }else Log::warning("自动揽收异常",["message"=>"未能成功修改揽收标记","param"=>["id"=>$this->orderPackage->id,
  46. "number"=>$this->orderPackage->logistic_number],"line"=>$result]);
  47. DB::commit();
  48. }catch (\Exception $e){
  49. DB::rollBack();
  50. Log::warning("自动揽收错误",["param"=>$this->orderPackage->toJson()]);
  51. }
  52. }
  53. }