ANG YU 5 лет назад
Родитель
Сommit
3562db0136

+ 9 - 5
app/Jobs/LogisticYDSync.php

@@ -3,6 +3,7 @@
 namespace App\Jobs;
 
 use App\Services\LogisticYDService;
+use App\Services\OrderPackageReceivedSyncService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
@@ -12,12 +13,15 @@ use Illuminate\Queue\SerializesModels;
 class LogisticYDSync implements ShouldQueue
 {
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
-
-
-    protected $logistic_number;
     /**
      * @var $logisticYDService LogisticYDService
+     * @var $orderPackageReceivedSyncService OrderPackageReceivedSyncService
+     * @var $orderPackageReceivedSyncService OrderPackageReceivedSyncService
+     * @var $logistic_number string
      */
+
+    protected $logistic_number;
+
     protected $logisticYDService;
     protected $orderPackageReceivedSyncService;
 
@@ -41,13 +45,13 @@ class LogisticYDSync implements ShouldQueue
         ini_set('max_execution_time', 10);
         $this->logisticYDService = app('LogisticYDService');
         //先订阅订单
-        $this->logisticYDService->registerApi($this->logistic_number);
+        $this->logisticYDService->registerApi([$this->logistic_number]);
         //查询订单路由信息
         $nativeResponse = $this->logisticYDService->query($this->logistic_number);
         //格式化信息
         $formattedData = $this->logisticYDService->format($nativeResponse);
         $this->orderPackageReceivedSyncService = app('OrderPackageReceivedSyncService');
         //更新数据
-        $this->orderPackageReceivedSyncService->update($formattedData);
+        $this->orderPackageReceivedSyncService->update([$formattedData]);
     }
 }

+ 1 - 1
app/Listeners/UpdateOrderPackageExceptionTypeCountingRecordListener.php

@@ -36,7 +36,7 @@ class UpdateOrderPackageExceptionTypeCountingRecordListener implements ShouldQue
          */
         $service = app('OrderPackageExceptionTypeCountingRecordService');
         foreach ($dates as $date) {
-            $service->updateOrCreateByDate($date);
+            $service->updateOrCreateByDate($date->sent_at_date);
         }
     }
 }

+ 1 - 1
app/Providers/EventServiceProvider.php

@@ -42,7 +42,7 @@ class EventServiceProvider extends ServiceProvider
             'App\Listeners\UpdateOrderPackageExceptionListener',//将对应的order_packages的数据的异常装变更为无
         ],
         'App\Events\UpdateOrderPackageExceptionListenerEvent' => [//order_packages的数据的异常数据变更时
-//            'App\Listeners\UpdateOrderPackageExceptionTypeCountingRecordListener',//更新OrderPackageExceptionTypeCountingRecord的统计信息
+            'App\Listeners\UpdateOrderPackageExceptionTypeCountingRecordListener',//更新OrderPackageExceptionTypeCountingRecord的统计信息
         ],
     ];
 

+ 4 - 2
tests/Services/LogisticYDService/FormatTest.php

@@ -37,7 +37,9 @@ class FormatTest extends TestCase
      */
     public function format_test()
     {
-       $result =$this->service->format($this->service->query('4314519335027'));
-       dd($result);
+        $this->service->registerApi(['4314543143889']);
+        $result = $this->service->format($this->service->query('4314543143889'));
+        $this->assertNotEmpty($result);
+
     }
 }

+ 42 - 0
tests/Services/LogisticYDService/LogisticYDSyncTest.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace Tests\Services\LogisticYDService;
+use App\Jobs\LogisticYDSync;
+use App\OrderPackage;
+use App\Services\LogisticYDService;
+use Tests\TestCase;
+use App\LogisticYD;
+use App\Traits\TestMockSubServices;
+
+class LogisticYDSyncTest extends TestCase
+{
+    use TestMockSubServices;
+    /** @var LogisticYDService $service */
+    public $service;
+    private $data;
+    private $amount=2;
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('LogisticYDService');
+    }
+
+    public function testReturned()
+    {
+        $this->assertTrue(true);
+    }
+
+    function tearDown(): void
+    {
+        parent::tearDown();
+    }
+
+    /**
+     * @test
+     */
+    public function sync_test()
+    {
+        LogisticYDSync::dispatch('4314543143889');
+        $this->assertTrue(OrderPackage::query()->where('logistic_number','4314543143889')->first()->transfer_status);
+    }
+}

+ 40 - 0
tests/Services/UpdateOrderPackageExceptionTypeCountingRecordListener/HandleTest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace Tests\Services\UpdateOrderPackageExceptionTypeCountingRecordListener;
+
+use App\Events\UpdateOrderPackageExceptionListenerEvent;
+use Tests\TestCase;
+use App\Traits\TestMockSubServices;
+
+class HandleTest extends TestCase
+{
+    use TestMockSubServices;
+
+    public $service;
+    private $data;
+    private $amount = 2;
+
+    function setUp(): void
+    {
+        parent::setUp();
+    }
+
+    public function testReturned()
+    {
+        $this->assertTrue(true);
+    }
+
+    function tearDown(): void
+    {
+        parent::tearDown();
+    }
+
+    /**
+     * @test
+     */
+    public function handle_test()
+    {
+        event(new  UpdateOrderPackageExceptionListenerEvent(['15970197']));
+        $this->assertTrue(true);
+    }
+}