Просмотр исходного кода

跟踪件 除了新杰物流,都按顺丰显示应送达时间

ajun 5 лет назад
Родитель
Сommit
28c6da854f

+ 3 - 2
app/Services/CityService.php

@@ -3,6 +3,7 @@
 namespace App\Services;
 
 use App\City;
+use Illuminate\Support\Str;
 
 Class CityService
 {
@@ -33,11 +34,11 @@ Class CityService
             }
         }
         if(str_ends_with($name,'自治州')){
-            $city_name = str_split($name,strpos($name,'自治州'))[0];
+            $city_name = Str::before($name,'自治州');
             return City::query()->where('name','like',$city_name.'%')->first();
         }
         if(str_ends_with($name,'市')){
-            $city_name = str_split($name,strpos($name,'市'))[0];
+            $city_name =  Str::before($name,'市');
             return City::query()->where('name','like',$city_name.'%')->first();
         }
         return null;

+ 4 - 8
app/Services/LogisticTimingService.php

@@ -8,20 +8,16 @@ use App\Province;
 
 Class LogisticTimingService
 {
-    /**
-     * @param string $cityName
-     * @param string $provinceName
-     * @param string $logisticName
-     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
-     */
+
     public function findByParams($cityName,$provinceName,$logisticId)
     {
         $logistic = Logistic::query()->where('id',$logisticId)->first();
-        if( str_starts_with($logistic->name,'顺丰')){
+        if(!str_starts_with($logistic->name,'新杰')){
             $city = app(CityService::class)->findByName($cityName);
             $province = app(ProvinceService::class)->findByName($provinceName);
+            $logistic = Logistic::query()->where('name','顺丰特惠')->first();
             if(isset($city) && isset($province)){
-                return $this->findByCityIdAndProvinceIdAndLogisticName($city->id,$province->id,$logisticId);
+                return $this->findByCityIdAndProvinceIdAndLogisticName($city->id,$province->id,$logistic->id);
             }
             return null;
         }

+ 4 - 6
app/Services/ProvinceService.php

@@ -3,15 +3,13 @@
 namespace App\Services;
 
 use App\Province;
+use Illuminate\Support\Str;
 
 Class ProvinceService
 {
     public static $provinces = ['青海','新疆','内蒙古','广西','西藏','宁夏','北京','上海','重庆','天津'];
 
-    /**
-     * @param string $name
-     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
-     */
+
     public function findByName($name)
     {
         $province = Province::query()->where('name',$name)->first();
@@ -22,11 +20,11 @@ Class ProvinceService
             }
         }
         if(str_ends_with($name,'市')){
-            $province_name = str_split(strpos($name,'市'))[0];
+            $province_name = Str::before($name,'市');
             return   Province::query()->where('name','like',$province_name.'%')->first();
         }
         if(str_ends_with($name,'省')){
-            $province_name = str_split(strpos($name,'省'))[0];
+            $province_name = Str::before($name,'省');
             return   Province::query()->where('name','like',$province_name.'%')->first();
         }
         return null;

+ 30 - 0
tests/Services/CityService/FindByNameTest/FindByNameTest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace Tests\Services\CityService\FindByNameTest;
+
+use App\City;
+use App\Services\CityService;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Foundation\Testing\WithFaker;
+use Tests\TestCase;
+
+class FindByNameTest extends TestCase
+{
+
+    /** @var CityService $cityService */
+    public $cityService;
+
+    public function setUp(): void
+    {
+        parent::setUp(); // TODO: Change the autogenerated stub
+        $this->cityService = app(CityService::class);
+    }
+
+    public function testFindByName()
+    {
+        /** @var City $city */
+        $city = $this->cityService->findByName('南京市');
+        $_city =City::query()->where('name','南京')->first();
+        $this->assertEquals($city,$_city);
+    }
+}

+ 28 - 0
tests/Services/LogisticTimingService/FindByParamsTest/FindByParamsTest.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace Tests\CacheService\LogisticTimingService\FindByParamsTest;
+
+use App\Logistic;
+use App\Services\LogisticTimingService;
+use Tests\TestCase;
+
+class FindByParamsTest extends TestCase
+{
+    /** @var LogisticTimingService $logisticTimingService */
+    public $logisticTimingService;
+
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->logisticTimingService = app(LogisticTimingService::class);
+    }
+
+    public function testFindByParams()
+    {
+        $cityName = '江苏省';
+        $provinceName = '南京市';
+        $logistic = Logistic::query()->where('name','like','新杰物流'.'%')->first();
+        $result=$this->logisticTimingService->findByParams($cityName,$provinceName,$logistic->id);
+        $this->assertNull($result);
+    }
+}

+ 27 - 0
tests/Services/ProvinceService/FindByNameTest/FindByNameTest.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace Tests\Services\ProvinceService\FindByNameTest;
+
+use App\Province;
+use App\Services\ProvinceService;
+use Tests\TestCase;
+
+class FindByNameTest extends TestCase
+{
+    /** @var ProvinceService $provinceService */
+    public $provinceService;
+
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->provinceService = app(ProvinceService::class);
+    }
+
+    public function testFindByName()
+    {
+        $province_name = '江苏省';
+        $province = $this->provinceService->findByName($province_name);
+        $_province = Province::query()->where('name','like','江苏'.'%')->first();
+        $this->assertEquals($province,$_province);
+    }
+}