| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace App\Jobs;
- use App\OrderPackage;
- use App\Services\OrderPackageService;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class PackageCollectingAllocation implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable;
- /** @var OrderPackage|\stdClass $orderPackage */
- private $orderPackage;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(OrderPackage $package)
- {
- $this->orderPackage = $package;
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- /** @var OrderPackageService $orderPackageService */
- $orderPackageService = app('OrderPackageService');
- DB::beginTransaction();
- try {
- $result = OrderPackage::query()->where("id",$this->orderPackage->id)
- ->where("collecting_status",0)->update(["collecting_status"=>1]);
- if ($result==1){
- $result = $orderPackageService->collectUpload([$this->orderPackage->logistic_number]);
- if (!$result["success"]){
- DB::rollBack();
- Log::warning("自动揽收失败",["message"=>$result["message"],"param"=>$this->orderPackage->logistic_number]);
- return;
- }else Log::info("揽收成功",["id"=>$this->orderPackage->id,"number"=>$this->orderPackage->logistic_number]);
- }else Log::warning("自动揽收异常",["message"=>"未能成功修改揽收标记","param"=>["id"=>$this->orderPackage->id,
- "number"=>$this->orderPackage->logistic_number],"line"=>$result]);
- DB::commit();
- }catch (\Exception $e){
- DB::rollBack();
- Log::warning("自动揽收错误",["param"=>$this->orderPackage->toJson()]);
- }
- }
- }
|