Zhouzhendong 4 éve
szülő
commit
d2c8b95542

+ 2 - 0
app/Http/Controllers/TestController.php

@@ -210,6 +210,8 @@ class TestController extends Controller
     }
     public function test(Request $request)
     {
+        Log::info("揽收成功",["id"=>1,"number"=>2]);
+        dd(1);
         $b = new StorageTypeController();
         $name = "test";
         $tag = "tag_name";

+ 19 - 20
app/Jobs/PackageCollectingAllocation.php

@@ -8,6 +8,7 @@ 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
@@ -17,18 +18,14 @@ class PackageCollectingAllocation implements ShouldQueue
     /** @var OrderPackage|\stdClass $orderPackage */
     private $orderPackage;
 
-    /** @var int|null|string */
-    private $lineNo;
-
     /**
      * Create a new job instance.
      *
      * @return void
      */
-    public function __construct(OrderPackage $package,int $lineNo)
+    public function __construct(OrderPackage $package)
     {
         $this->orderPackage = $package;
-        $this->lineNo = $lineNo;
     }
 
     /**
@@ -40,21 +37,23 @@ class PackageCollectingAllocation implements ShouldQueue
     {
         /** @var OrderPackageService $orderPackageService */
         $orderPackageService = app('OrderPackageService');
-        $result = $orderPackageService->collectUpload([$this->orderPackage->logistic_number]);
-        if (!$result["success"]){
-            Log::warning("自动揽收失败",["message"=>$result["message"],"param"=>$this->orderPackage->logistic_number]);
-            return;
+        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()]);
         }
-        $result = OrderPackage::query()->where("id",$this->orderPackage->id)
-            ->where("collecting_status",'0')->update(["collecting_status"=>'1']);
-        if ($result!=1)
-            Log::warning("自动揽收异常",["message"=>"未能成功修改揽收标记","param"=>["id"=>$this->orderPackage->id,"number"=>$this->orderPackage->logistic_number],"line"=>$result]);
-        else Log::info("揽收成功",["id"=>$this->orderPackage->id,"number"=>$this->orderPackage->logistic_number]);
-        /*$result = app("OrderService")->allocation($this->orderPackage->order->code,$this->lineNo);
-        if (mb_substr($result,0,3)=='000'){
-            if (OrderPackage::query()->where("id",$this->orderPackage->id)
-                ->where("collecting_status",'0')->update(["collecting_status"=>'1'])!=1)
-                Log::warning("自动揽收异常",["message"=>"未能成功修改揽收标记","param"=>$this->orderPackage->toArray()]);
-        }else Log::warning("自动揽收失败",["message"=>"分配失败:{$result}","param"=>$this->orderPackage->order->code." : {$this->lineNo}"]);*/
     }
 }

+ 3 - 4
app/Services/OrderPackageService.php

@@ -326,7 +326,7 @@ class OrderPackageService
             }
             if ($checktime) {
                 //EDISENDFLAG
-                $this->checkingAndProcess($package,$allocation->orderlineno); //检查和处理揽收
+                $this->checkingAndProcess($package); //检查和处理揽收
                 $update_params[] = [
                     'id' => $package->id,
                     'sent_at' => $checktime,
@@ -340,9 +340,8 @@ class OrderPackageService
      * 检查和处理揽收
      *
      * @param OrderPackage|\stdClass $package
-     * @param int $lineNo
      */
-    public function checkingAndProcess(OrderPackage $package, int $lineNo)
+    public function checkingAndProcess(OrderPackage $package)
     {
         //校验快递商 订单状态 复核标记 揽收标记
         if ($package->collecting_status == '1' || !$package->logistic_number)return;
@@ -358,7 +357,7 @@ class OrderPackageService
             unset($tag[$package->logistic_number]);
             Cache::put(self::CACHE_COLLECT_FLAG, $tag, self::CACHE_COLLECT_FLAG_TTL);
             $package->update(["collecting_status"=>1]);
-        }else dispatch(new PackageCollectingAllocation($package,$lineNo));
+        }else dispatch(new PackageCollectingAllocation($package));
     }
 
     /**