Browse Source

客户管理-单元测试

Zhouzhendong 5 years ago
parent
commit
e3fb450952
29 changed files with 1093 additions and 144 deletions
  1. 3 2
      app/Http/Controllers/TestController.php
  2. 4 1
      app/Services/FeatureService.php
  3. 1 1
      app/Services/OwnerPriceExpressService.php
  4. 3 4
      app/Services/OwnerPriceLogisticService.php
  5. 31 15
      app/Services/OwnerPriceOperationService.php
  6. 3 3
      app/Services/OwnerStoragePriceModelService.php
  7. 3 3
      database/factories/CarTypeFactory.php
  8. 21 0
      database/factories/CommodityFactory.php
  9. 0 1
      database/factories/OwnerFactory.php
  10. 15 0
      database/factories/OwnerPriceDirectLogisticCarFactory.php
  11. 4 6
      database/factories/OwnerPriceExpressFactory.php
  12. 16 0
      database/factories/OwnerPriceExpressProvinceFactory.php
  13. 23 0
      database/factories/OwnerPriceLogisticDetailFactory.php
  14. 19 0
      database/factories/OwnerPriceLogisticFactory.php
  15. 2 1
      database/factories/OwnerReportFactory.php
  16. 0 21
      tests/Inventory/ExampleTest.php
  17. 1 1
      tests/Inventory/Services/InventoryAccountService/InventoryAccountService_CreateInventoryMissionRecordTest.php
  18. 19 1
      tests/Services/CustomerService/CustomerTest.php
  19. 16 1
      tests/Services/FeatureService/FeatureServiceTest.php
  20. 10 1
      tests/Services/OwnerAreaReportService/OwnerAreaReportServiceTest.php
  21. 10 1
      tests/Services/OwnerBillReportService/OwnerBillReportServiceTest.php
  22. 7 1
      tests/Services/OwnerFeeDetailService/OwnerFeeDetailServiceTest.php
  23. 19 1
      tests/Services/OwnerOutStorageRuleService/OwnerOutStorageRuleServiceTest.php
  24. 199 0
      tests/Services/OwnerPriceDirectLogisticService/OwnerPriceDirectLogisticServiceTest.php
  25. 0 79
      tests/Services/OwnerPriceDirectLogisticServiceTest.php
  26. 203 0
      tests/Services/OwnerPriceExpressService/OwnerPriceExpressServiceTest.php
  27. 220 0
      tests/Services/OwnerPriceLogisticService/OwnerPriceLogisticServiceTest.php
  28. 169 0
      tests/Services/OwnerPriceOperationService/OwnerPriceOperationServiceTest.php
  29. 72 0
      tests/Services/OwnerStoragePriceModelService/OwnerStoragePriceModelServiceTest.php

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

@@ -27,6 +27,7 @@ use App\RejectedBill;
 use App\RejectedBillItem;
 use App\Services\CacheService;
 use App\Services\common\DataHandlerService;
+use App\Services\FeatureService;
 use App\Services\InventoryCompareService;
 use App\Services\OracleDOCOrderHeaderService;
 use App\Services\OrderPackageService;
@@ -65,8 +66,8 @@ class TestController extends Controller
     }
 
     public function test4(){
-        $a = app('CommodityService')->isExist(["barcode"=>"XUNI02"]);
-        dd($a);
+        $a = new FeatureService();
+        dd($a->matchFeature("1&2&3",[],[]));
     }
 
     public function test2(){

+ 4 - 1
app/Services/FeatureService.php

@@ -205,6 +205,9 @@ Class FeatureService
      */
     public function matchFeature($value, $columnMapping, $matchObject) :bool
     {
+        preg_match_all('/\d+|[\&\|\(\)]/',$value,$result);
+        if (implode("",$result[0]) != $value)return false;
+
         preg_match_all('/\d+/',$value,$ids);
         if ($ids[0])$fs = Feature::query()->whereIn("id",$ids[0])->get();
         else return false;
@@ -212,7 +215,7 @@ Class FeatureService
         foreach ($fs as $f){
             $features[$f->id] = $f;
         }
-        preg_match_all('/\d+|[\&\|\(\)]/',$value,$result);
+
         foreach ($result[0] as &$str) {
             if (is_numeric($str) && isset($features[$str])) {
                 $column = $features[$str]["type"];

+ 1 - 1
app/Services/OwnerPriceExpressService.php

@@ -125,6 +125,6 @@ Class OwnerPriceExpressService
         if ($weight < $model->initial_weight)$weight = $model->initial_weight;
         $initialMoney = $model->initial_weight*$model->details[0]->initial_weight_price;
         $weight -= $model->initial_weight;
-        return ($weight*$model->details[0]->additional_weight_price)+$initialMoney;
+        return (ceil($weight/$model->additional_weight)*$model->details[0]->additional_weight_price)+$initialMoney;
     }
 }

+ 3 - 4
app/Services/OwnerPriceLogisticService.php

@@ -131,9 +131,8 @@ Class OwnerPriceLogisticService
     private function calculation($amount, $detail, $fee)
     {
         if ($amount < $detail->initial_amount)$amount = $detail->initial_amount; //小于起始数以起始数为准
-        $initialMoney = $detail->initial_amount*$detail->unit_price; //起始数计费
-        $amount -= $detail->initial_amount; //减起始数为续数
-        if ($initialMoney < $detail->initial_fee)$initialMoney = $detail->initial_fee; //小于起始计费以起始计费为准
-        return ($amount*$detail->unit_price)+$initialMoney+$detail->delivery_fee+$fee;
+        $money = $amount * $detail->unit_price;
+        if ($money < $detail->initial_fee)$money = $detail->initial_fee; //小于起始计费以起始计费为准
+        return $money+$detail->delivery_fee+$fee;
     }
 }

+ 31 - 15
app/Services/OwnerPriceOperationService.php

@@ -119,7 +119,7 @@ Class OwnerPriceOperationService
             $query->orderByRaw("CASE strategy  WHEN '默认' THEN 1 WHEN '特征' THEN 2 WHEN '起步' THEN 3 END DESC,priority DESC");
         }] : ['ownerInStorageRule'] ;
         $rules = OwnerPriceOperation::query()->with($withs)
-            ->where("operation_type","出库")
+            ->where("operation_type",$type)
             ->whereHas("ownerPriceOperationOwners",function ($query)use($owner_id){
                 /** @var Builder $query */
                 $query->where("id",$owner_id);
@@ -128,27 +128,34 @@ Class OwnerPriceOperationService
         if (!$rules)return -2;
 
         if ($type == '入库'){
-            foreach ($rules as $rule){
+            foreach ($rules as $index => $rule){
+                $sum = $amount;
                 if (!$rule->ownerInStorageRule)continue;
                 if ($rule->strategy == '特征'){
                     $bool = app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject);
                     if ($bool === true){
                         if (!isset($units[$rule->ownerInStorageRule->unit_id])) return -3;
                         if ($units[$rule->ownerInStorageRule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
-                            $amount = $this->changeUnit($amount,$owner_id,$sku);
-                            if ($amount<0) return $amount;
+                            $sum = $this->changeUnit($sum,$owner_id,$sku);
+                            if ($sum<0){
+                                if ($index == count($rules)-1)return $sum;
+                                continue;
+                            }
                         }
-                        if ($units[$rule->ownerInStorageRule->unit_id] == '单')$amount = 1; //为单时数量设为1;
-                        return ceil($amount/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
+                        if ($units[$rule->ownerInStorageRule->unit_id] == '单')$sum = 1; //为单时数量设为1;
+                        return ceil($sum/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
                     };
                 }else{
                     if (!isset($units[$rule->ownerInStorageRule->unit_id])) return -3;
                     if ($units[$rule->ownerInStorageRule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
-                        $amount = $this->changeUnit($amount,$owner_id,$sku);
-                        if ($amount<0) return $amount;
+                        $sum = $this->changeUnit($sum,$owner_id,$sku);
+                        if ($sum<0){
+                            if ($index == count($rules)-1)return $sum;
+                            continue;
+                        }
                     }
-                    if ($units[$rule->ownerInStorageRule->unit_id] == '单')$amount = 1; //为单时数量设为1;
-                    return ceil($amount/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
+                    if ($units[$rule->ownerInStorageRule->unit_id] == '单')$sum = 1; //为单时数量设为1;
+                    return ceil($sum/$rule->ownerInStorageRule->amount)*$rule->ownerInStorageRule->unit_price;
                 };
             }
             return -7;
@@ -179,7 +186,8 @@ Class OwnerPriceOperationService
     private function matchOutStorage($amount, $rules, $columnMapping, $matchObject, $units, $owner_id, $sku)
     {
         $money = 0;
-        foreach ($rules as $rule){
+        foreach ($rules as $index => $rule){
+            $sum = $amount;
             switch ($rule->strategy){
                 case "起步":
                     $money = $rule->amount * $rule->unit_price;
@@ -197,17 +205,25 @@ Class OwnerPriceOperationService
                     if (app("FeatureService")->matchFeature($rule->feature,$columnMapping,$matchObject)){
                         if (!isset($units[$rule->unit_id]) || $units[$rule->unit_id] == '单') return -3;
                         if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
-                            $amount = $this->changeUnit($amount,$owner_id,$sku);
+                            $sum = $this->changeUnit($sum,$owner_id,$sku);
+                            if ($sum<0){
+                                if ($index == count($rules)-1)return $sum;
+                                break;
+                            }
                         }
-                        return (ceil($amount/$rule->amount)*$rule->unit_price)+$money;
+                        return (ceil($sum/$rule->amount)*$rule->unit_price)+$money;
                     };
                     break;
                 case "默认":
                     if (!isset($units[$rule->unit_id]) || $units[$rule->unit_id] == '单') return -3;
                     if ($units[$rule->unit_id] == '箱'){ //为箱时同步商品寻找箱规
-                        $amount = $this->changeUnit($amount,$owner_id,$sku);
+                        $sum = $this->changeUnit($sum,$owner_id,$sku);
+                        if ($sum<0){
+                            if ($index == count($rules)-1)return $sum;
+                            break;
+                        }
                     }
-                    return (ceil($amount/$rule->amount)*$rule->unit_price)+$money;
+                    return (ceil($sum/$rule->amount)*$rule->unit_price)+$money;
                     break;
             }
         }

+ 3 - 3
app/Services/OwnerStoragePriceModelService.php

@@ -43,10 +43,10 @@ Class OwnerStoragePriceModelService
     }
 
     //暂时不考虑单位换算问题:后期可能存在多单位换算,此处仅视为单位为 m²
-    public function calculationAmount(OwnerStoragePriceModel $model, $area, $owner_id = null, $month = null) :int
+    public function calculationAmount(OwnerStoragePriceModel $model, $area, $owner_id = null, $month = null)
     {
         if (!$model || !$area) return 0;
-        if ((int)$area < $model->minimum_area) $area = (int)$model->minimum_area;
+        if ($area < $model->minimum_area) $area = $model->minimum_area;
         $money = $area*$model->price;
         switch ($model->discount_type){
             case "按单减免":
@@ -58,7 +58,7 @@ Class OwnerStoragePriceModelService
                 }
                 break;
             case "固定减免":
-                $money -= (int)$model->discount_value;
+                $money -= $model->discount_value;
                 break;
         }
         return $money;

+ 3 - 3
database/factories/CarTypeFactory.php

@@ -9,8 +9,8 @@ $factory->define(CarType::class, function (Faker $faker) {
     return [
         'name' => $faker->name,
         'model' => $faker->name,
-        'length',
-        'load',
-        'remark'
+        'length' => mt_rand(6,250) / 4,
+        'load' => mt_rand(6,250) / 4,
+        'remark' => $faker->text(20),
     ];
 });

+ 21 - 0
database/factories/CommodityFactory.php

@@ -0,0 +1,21 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\Commodity;
+use Faker\Generator as Faker;
+
+$factory->define(Commodity::class, function (Faker $faker) {
+    $type = ["无","临时"];
+    return [
+        'name' => $faker->name,
+        'sku' => md5(date('Ymd').\Illuminate\Support\Str::random(3)),
+        'owner_id' => factory(\App\Owner::class),
+        'length' => mt_rand(1,90) / 3,
+        'width' => mt_rand(1,90) / 3,
+        'height' => mt_rand(1,90) / 3,
+        'volumn' => mt_rand(10,900) / 3,
+        "type" => $type[array_rand($type)],
+        "pack_spec" => mt_rand(1,100)
+    ];
+});

+ 0 - 1
database/factories/OwnerFactory.php

@@ -10,7 +10,6 @@ $factory->define(Owner::class, function (Faker $faker) {
         'name' => $faker->name,                 //名称
         'code' => \Illuminate\Support\Str::random(5).date('yymmdd'),                 //代码
         'checking_count' => mt_rand(0,5),       //审核数量
-        "customer_id" => factory(App\Customer::class),          //客户ID
         "tax_rate" => mt_rand(0,100) / 10,             //税率
         "contract_number" => \Illuminate\Support\Str::random(5).date('yymmdd'),      //合同号
         "salesman" => $faker->name,             //销售名称

+ 15 - 0
database/factories/OwnerPriceDirectLogisticCarFactory.php

@@ -0,0 +1,15 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerPriceDirectLogisticCar;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerPriceDirectLogisticCar::class, function (Faker $faker) {
+    return [
+        "owner_price_direct_logistic_id" => factory(\App\OwnerPriceDirectLogistic::class),   //直发车计费ID
+        "car_type_id" => factory(\App\CarType::class),                      //车型ID
+        "base_fee" => mt_rand(6,250) / 4,                         //起步费
+        "additional_fee" => mt_rand(6,250) / 4,                   //续费(元/KM)
+    ];
+});

+ 4 - 6
database/factories/OwnerPriceExpressFactory.php

@@ -5,12 +5,10 @@
 use App\OwnerPriceExpress;
 use Faker\Generator as Faker;
 
-$unit = \App\Unit::query()->first();
-$factory->define(OwnerPriceExpress::class, function (Faker $faker)use(&$unit) {
-    if (!$unit)$unit = \App\Unit::query()->first();
+$factory->define(OwnerPriceExpress::class, function (Faker $faker) {
     return [
-        "name" => $faker->name,                     //名称
-        "initial_weight_unit_id" => $unit ? $unit->id : factory(\App\Unit::class),   //首重单位
-        "additional_weight_unit_id" => $unit ? $unit->id : factory(\App\Unit::class),//续重单位
+        "name" => $faker->name,
+        "initial_weight" => mt_rand(6,260) / 5,
+        "additional_weight" => mt_rand(6,260) / 5,
     ];
 });

+ 16 - 0
database/factories/OwnerPriceExpressProvinceFactory.php

@@ -0,0 +1,16 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerPriceExpressProvince;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerPriceExpressProvince::class, function (Faker $faker) {
+    $province = \App\Province::query()->first();
+    return [
+        "owner_price_express_id" => factory(\App\OwnerPriceExpress::class),   //快递价格ID
+        "province_id" => $province->id,              //省份ID
+        "initial_weight_price" => mt_rand(6,260) / 5,     //初始单价
+        "additional_weight_price"=>mt_rand(6,260) / 5,  //续重单价
+    ];
+});

+ 23 - 0
database/factories/OwnerPriceLogisticDetailFactory.php

@@ -0,0 +1,23 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerPriceLogisticDetail;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerPriceLogisticDetail::class, function (Faker $faker) {
+    $province = \App\Province::query()->first();
+    $city = \App\City::query()->where("province_id",$province->id)->first();
+    return [
+        "owner_price_logistic_id" => factory(\App\OwnerPriceLogistic::class),  //物流计费
+        "unit_id" => factory(\App\Unit::class),                  //单位ID
+        "range" => "0-5",                    //区间
+        "province_id" => $province->id,              //省份ID
+        "city_id" => $city->id,                  //城市ID
+        "unit_price" => mt_rand(1,36) / 3,               //单价
+        "delivery_fee" => mt_rand(1,136) / 3,             //送货费
+        "initial_fee" => mt_rand(1,136) / 3,              //起始计费
+        "initial_amount" => mt_rand(1,136) / 3,           //起始计数
+        "rate" =>  mt_rand(1,136) / 3,                       //费率
+    ];
+});

+ 19 - 0
database/factories/OwnerPriceLogisticFactory.php

@@ -0,0 +1,19 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerPriceLogistic;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerPriceLogistic::class, function (Faker $faker) {
+    return [
+        "name" => $faker->name,             //名称
+        "unit_range" => "0-5,5-10,10-15,15-20",       //单价一区间
+        "unit_id" => factory(\App\Unit::class),          //单位一ID
+        "other_unit_range" => "0-5,5-10,10-15,15-20,30-", //单位二区间
+        "other_unit_id" => factory(\App\Unit::class),    //单位二ID
+        "pick_up_price" => mt_rand(2,230) / 3,    //提货费
+        "fuel_price" => mt_rand(2,230) / 3,       //燃油附加费
+        "service_price" => mt_rand(2,230) / 3,    //信息服务费
+    ];
+});

+ 2 - 1
database/factories/OwnerReportFactory.php

@@ -13,6 +13,7 @@ $factory->define(OwnerReport::class, function (Faker $faker)use($owner) {
         "daily_average_order_amount" => mt_rand(0,10000),  //日均单量
         "current_month_counting_area" => mt_rand(100,100000) / 50,  //结算月盘点面积
         "last_month_counting_area"   => mt_rand(100,100000) / 50,  //结算月上月盘点面积
-        "owner_bill_report_id"  =>factory(App\OwnerBillReport::class)        //账单ID
+        "owner_bill_report_id"  =>factory(App\OwnerBillReport::class),        //账单ID
+        "total" => mt_rand(1,2000),
     ];
 });

+ 0 - 21
tests/Inventory/ExampleTest.php

@@ -1,21 +0,0 @@
-<?php
-
-namespace Tests\Unit;
-
-use App\Authority;
-use App\Carrier;
-use App\Role;
-use App\User;
-use Illuminate\Support\Facades\DB;
-use Tests\TestCase;
-use Illuminate\Foundation\Testing\WithFaker;
-use Illuminate\Foundation\Testing\RefreshDatabase;
-
-class ExampleTest extends TestCase
-{
-
-    public function testExample(){
-        $this->assertEquals(2,1+1);
-    }
-
-}

+ 1 - 1
tests/Inventory/Services/InventoryAccountService/InventoryAccountService_CreateInventoryMissionRecordTest.php

@@ -18,7 +18,7 @@ class InventoryServiceCreateInventoryMissionRecordTest extends TestCase
     public $wmsInventoryAccounts;
     function setUp(): void
     {
-        parent::setUp(); // TODO: Change the autogenerated stub
+        parent::setUp();
         $this->inventory=factory(InventoryAccount::class)->create();
         $this->realService=new InventoryAccountService();
         $this->wmsInventoryAccounts=$this->realService->conditionPortStock('2020-08-20','2020-08-20',3);

+ 19 - 1
tests/Services/CustomerTest.php → tests/Services/CustomerService/CustomerTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Unit\Customer;
+namespace Tests\Unit\Customer\CustomerService;
 
 use App\Customer;
 use App\Services\CustomerService;
@@ -22,6 +22,9 @@ class CustomerTest extends TestCase
         ];
     }
 
+    /**
+     * @group customer
+     */
     public function testCreate(){
         $model = $this->service->create([
             "code" => date('Ymd').Str::random(4),
@@ -31,20 +34,32 @@ class CustomerTest extends TestCase
         $this->assertNotNull($model);
         $this->data["models"][] = $model->toArray();
     }
+    /**
+     * @group customer
+     */
     public function testGetSelection(){
         $models = $this->service->getSelection(["id","name","company_name"]);
         $this->assertGreaterThanOrEqual(1,count($models));
         $this->assertArrayHasKey("company_name",$models[0]);
     }
+    /**
+     * @group customer
+     */
     public function testPaginate(){
         $models = $this->service->paginate(5);
         $this->assertGreaterThanOrEqual(1,count($models));
         $this->assertLessThanOrEqual(5,count($models));
     }
+    /**
+     * @group customer
+     */
     public function testFind(){
         $model = $this->service->find($this->data["models"][0]["id"]);
         $this->assertNotNull($model);
     }
+    /**
+     * @group customer
+     */
     public function testUpdate()
     {
         $value = date('YmdH').Str::random(4);
@@ -54,6 +69,9 @@ class CustomerTest extends TestCase
         $this->data["models"][0]["name"] = $value;
         $this->assertEquals($row,1);
     }
+    /**
+     * @group customer
+     */
     public function testDestroy()
     {
         $row = $this->service->destroy($this->data["models"][0]["id"]);

+ 16 - 1
tests/Services/FeatureServiceTest.php → tests/Services/FeatureService/FeatureServiceTest.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Tests\Unit\Customer;
+namespace Tests\Unit\Customer\FeatureService;
 
 use App\Feature;
 use App\Services\FeatureService;
@@ -23,10 +23,16 @@ class FeatureServiceTest extends TestCase
         ];
     }
 
+    /**
+     * @group customer
+     */
     public function testGetMapArray(){
         $models = $this->service->getMapArray();
         $this->assertGreaterThanOrEqual(3,count($models));
     }
+    /**
+     * @group customer
+     */
     public function testTranslationFeature(){
         $str = $this->data["models"][0]["id"]."&(".$this->data["models"][1]["id"]."|".$this->data["models"][2]["id"].")";
         $result = $this->service->translationFeature($str);
@@ -38,6 +44,9 @@ class FeatureServiceTest extends TestCase
         $this->assertEquals(true,$result[2]["strategyGroupEndSign"]);
         $this->assertEquals("或",$result[2]["calculation"]);
     }
+    /**
+     * @group customer
+     */
     public function testAnalysisFeature(){
         $models = $this->data["models"];
         $params = [
@@ -71,6 +80,9 @@ class FeatureServiceTest extends TestCase
         $this->assertArrayHasKey("feature",$result);
         $this->assertEquals($expected,$result["feature"]);
     }
+    /**
+     * @group customer
+     */
     public function testFormatFeature(){
         $model1 = factory(Feature::class)->make([
             "id" => 1,
@@ -99,6 +111,9 @@ class FeatureServiceTest extends TestCase
         $expected = "commodity_name like '%衣服%' and (order_type not like '%创建%' or logistic_name = '顺丰')";
         $this->assertEquals($expected,$result);
     }
+    /**
+     * @group customer
+     */
     public function testMatchFeature(){
         $model1 = factory(Feature::class)->create([
             "type" => "商品名称",

+ 10 - 1
tests/Services/OwnerAreaReportServiceTest.php → tests/Services/OwnerAreaReportService/OwnerAreaReportServiceTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services;
+namespace Tests\Services\OwnerAreaReportService;
 
 
 use App\Owner;
@@ -43,12 +43,18 @@ class OwnerAreaReportServiceTest extends  TestCase
         ])->toArray();
     }
 
+    /**
+     * @group customer
+     */
     public function testPaginate()
     {
         $models = $this->service->paginate(array("paginate"=>5));
         $this->assertGreaterThanOrEqual(3,count($models));
         $this->assertLessThanOrEqual(5,count($models));
     }
+    /**
+     * @group customer
+     */
     public function testUpdate(){
         $model = $this->data["models"][0];
         $result = $this->service->update(["id"=>$model["id"]],[
@@ -59,6 +65,9 @@ class OwnerAreaReportServiceTest extends  TestCase
         $this->assertNotNull($area);
         $this->assertEquals(1000,$area->accounting_area);
     }
+    /**
+     * @group customer
+     */
     public function testGet(){
         $ids = implode(",",array_column($this->data["models"],"owner_id"));
         $models = $this->service->get(["owner_id"=>$ids]);

+ 10 - 1
tests/Services/OwnerBillReportServiceTest.php → tests/Services/OwnerBillReportService/OwnerBillReportServiceTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services;
+namespace Tests\Services\OwnerBillReportService;
 
 
 use App\Owner;
@@ -33,12 +33,18 @@ class OwnerBillReportServiceTest extends  TestCase
         ])->toArray();
     }
 
+    /**
+     * @group customer
+     */
     public function testPaginate()
     {
         $models = $this->service->paginate(array("paginate"=>5));
         $this->assertGreaterThanOrEqual(3,count($models));
         $this->assertLessThanOrEqual(5,count($models));
     }
+    /**
+     * @group customer
+     */
     public function testUpdate(){
         $model = $this->data["models"][0];
         $result = $this->service->update(["id"=>$model["id"]],[
@@ -49,6 +55,9 @@ class OwnerBillReportServiceTest extends  TestCase
         $this->assertNotNull($bill);
         $this->assertEquals(1000,$bill->difference);
     }
+    /**
+     * @group customer
+     */
     public function testGet(){
         $ids = implode(",",array_column($this->data["models"],"owner_id"));
         $models = $this->service->get(["owner_id"=>$ids]);

+ 7 - 1
tests/Services/OwnerFeeDetailServiceTest.php → tests/Services/OwnerFeeDetailService/OwnerFeeDetailServiceTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services;
+namespace Tests\Services\OwnerFeeDetailService;
 
 
 use App\Logistic;
@@ -53,12 +53,18 @@ class OwnerFeeDetailServiceTest extends  TestCase
         ])->toArray();
     }
 
+    /**
+     * @group customer
+     */
     public function testPaginate()
     {
         $models = $this->service->paginate(array("paginate"=>5));
         $this->assertGreaterThanOrEqual(3,count($models));
         $this->assertLessThanOrEqual(5,count($models));
     }
+    /**
+     * @group customer
+     */
     public function testGetSql()
     {
         $ids = implode(",",array_column($this->data["models"],"id"));

+ 19 - 1
tests/Services/OwnerOutStorageRuleServiceTest.php → tests/Services/OwnerOutStorageRuleService/OwnerOutStorageRuleServiceTest.php

@@ -1,7 +1,7 @@
 <?php
 
 
-namespace Tests\Services;
+namespace Tests\Services\OwnerOutStorageRuleService;
 
 
 use App\OwnerOutStorageRule;
@@ -51,11 +51,17 @@ class OwnerOutStorageRuleServiceTest extends  TestCase
         ])->toArray();
     }
 
+    /**
+     * @group customer
+     */
     public function testGet()
     {
         $models = $this->service->get(["owner_price_operation_id"=>$this->data["ownerPriceOperations"][0]["id"]]);
         $this->assertCount(2,$models);
     }
+    /**
+     * @group customer
+     */
     public function testUpdate()
     {
         $model = $this->data["models"][0];
@@ -70,6 +76,9 @@ class OwnerOutStorageRuleServiceTest extends  TestCase
         $this->assertEquals(1.33,$expected->unit_price);
         $this->assertEquals(50,$expected->amount);
     }
+    /**
+     * @group customer
+     */
     public function testCreate()
     {
         $model = $this->service->create([
@@ -84,6 +93,9 @@ class OwnerOutStorageRuleServiceTest extends  TestCase
         $this->assertNotNull($model);
         $this->data["models"][] = $model->toArray();
     }
+    /**
+     * @group customer
+     */
     public function testFindUpdate()
     {
         $model = OwnerOutStorageRule::query()->find($this->data["models"][0]["id"]);
@@ -92,11 +104,17 @@ class OwnerOutStorageRuleServiceTest extends  TestCase
         ]);
         $this->assertEquals(1,$result);
     }
+    /**
+     * @group customer
+     */
     public function testFind()
     {
         $models = $this->service->find(array_column($this->data["models"],"id"));
         $this->assertCount(2,$models);
     }
+    /**
+     * @group customer
+     */
     public function testIsExist()
     {
         $result = $this->service->isExist([

+ 199 - 0
tests/Services/OwnerPriceDirectLogisticService/OwnerPriceDirectLogisticServiceTest.php

@@ -0,0 +1,199 @@
+<?php
+
+
+namespace Tests\Services\OwnerPriceDirectLogisticService;
+
+use App\CarType;
+use App\Owner;
+use App\OwnerPriceDirectLogistic;
+use App\OwnerPriceDirectLogisticCar;
+use App\Services\OwnerPriceDirectLogisticService;
+use Ramsey\Uuid\Uuid;
+use Tests\TestCase;
+
+class OwnerPriceDirectLogisticServiceTest extends  TestCase
+{
+    /** @var OwnerPriceDirectLogisticService */
+    public $service;
+    public $data;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(OwnerPriceDirectLogisticService::class);
+
+        $this->data["models"] = factory(OwnerPriceDirectLogistic::class,3)->create()->toArray();
+    }
+
+    /**
+     * @group customer
+     */
+    public function testPaginate()
+    {
+        $models = $this->service->paginate();
+        $this->assertGreaterThanOrEqual(3,count($models));
+        $this->assertLessThanOrEqual(50,count($models));
+        $models = $this->service->paginate($this->data["models"][0]["id"]);
+        $this->assertCount(1,$models);
+    }
+    /**
+     * @group customer
+     */
+    public function testCreate()
+    {
+        $model = $this->service->create([
+            "name" => Uuid::uuid1(),
+            "base_km" => 3
+        ]);
+        $this->assertNotNull($model);
+        $this->data["models"][] = $model->toArray();
+    }
+    /**
+     * @group customer
+     */
+    public function testDestroy()
+    {
+        $result = $this->service->destroy(array_column($this->data["models"],"id"));
+        $this->assertEquals(3,$result);
+        $this->data["models"] = [];
+    }
+    /**
+     * @group customer
+     */
+    public function testFind()
+    {
+        $model = $this->service->find($this->data["models"][0]["id"]);
+        $this->assertNotNull($model);
+    }
+    /**
+     * @group customer
+     */
+    public function testUpdate()
+    {
+        $id = $this->data["models"][0]["id"];
+        $result = $this->service->update(["id"=>$id],[
+            "base_km" => 3
+        ]);
+        $this->assertEquals(1,$result);
+        $model = OwnerPriceDirectLogistic::query()->find($id);
+        $this->assertEquals(3,$model->base_km);
+    }
+    /**
+     * @group customer
+     */
+    public function testUpdateDetail()
+    {
+        $car = factory(\App\CarType::class)->create();
+        $model = factory(OwnerPriceDirectLogisticCar::class)->create([
+            "owner_price_direct_logistic_id" => $this->data["models"][0]["id"],   //直发车计费ID
+            "car_type_id" => $car->id,                      //车型ID
+        ]);
+        $result = $this->service->updateDetail(["id"=>$model->id],["base_fee"=>0.01]);
+        $this->assertEquals(1,$result);
+        OwnerPriceDirectLogisticCar::destroy($model->id);
+        CarType::destroy($car->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testIsExistDetail()
+    {
+        $car = factory(\App\CarType::class)->create();
+        $model = factory(OwnerPriceDirectLogisticCar::class)->create([
+            "owner_price_direct_logistic_id" => $this->data["models"][0]["id"],   //直发车计费ID
+            "car_type_id" => $car->id,                      //车型ID
+        ]);
+        $result = $this->service->isExistDetail(["owner_price_direct_logistic_id"=>$this->data["models"][0]["id"]]);
+        $this->assertGreaterThan(0,$result);
+        OwnerPriceDirectLogisticCar::destroy($model->id);
+        CarType::destroy($car->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testCreatedDetail()
+    {
+        $model = $this->service->createDetail([
+            "owner_price_direct_logistic_id" => $this->data["models"][0]["id"],   //直发车计费ID
+            "car_type_id" => 1,
+            "base_fee" => 1,
+            "additional_fee" => 1,
+        ]);
+        $this->assertNotNull($model);
+        OwnerPriceDirectLogisticCar::destroy($model->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testDestroyDetail()
+    {
+        $car = factory(\App\CarType::class)->create();
+        $model = factory(OwnerPriceDirectLogisticCar::class)->create([
+            "owner_price_direct_logistic_id" => $this->data["models"][0]["id"],   //直发车计费ID
+            "car_type_id" => $car->id,                      //车型ID
+        ]);
+        $result = $this->service->destroyDetail($model->id);
+        $this->assertEquals(1,$result);
+        CarType::destroy($car->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testGetExistOwnerName()
+    {
+        $owner = factory(Owner::class)->create([
+            "user_owner_group_id" => 1,
+        ]);
+        /** @var OwnerPriceDirectLogistic $model */
+        $model = OwnerPriceDirectLogistic::query()->find($this->data["models"][0]["id"]);
+        $model->owners()->sync([$owner->id]);
+        $result = $this->service->getExistOwnerName($owner->id,$this->data["models"][0]["id"]);
+        $this->assertCount(0,$result);
+        $result = $this->service->getExistOwnerName($owner->id,null);
+        $this->assertCount(1,$result);
+        $this->assertEquals($owner->name,$result[0]);
+        Owner::destroy($owner->id);
+        $model->owners()->sync([]);
+    }
+    /**
+     * @group customer
+     */
+    public function testMatching()
+    {
+        $model = factory(OwnerPriceDirectLogistic::class)->create([
+            "base_km" => 2,
+        ]);
+        $this->data["models"][] = $model->toArray();
+        $owner = factory(Owner::class)->create([
+            "user_owner_group_id" => 1,
+        ]);
+        $model->owners()->sync([$owner->id]);
+        $cars = factory(\App\CarType::class,2)->create();
+        $item1 = factory(OwnerPriceDirectLogisticCar::class)->create([
+            "owner_price_direct_logistic_id" => $model->id,   //直发车计费ID
+            "car_type_id" => $cars[0]->id,                      //车型ID
+            "base_fee" => 1.5,                         //起步费
+            "additional_fee" =>2.5,                   //续费(元/KM)
+        ]);
+        $item2 = factory(OwnerPriceDirectLogisticCar::class)->create([
+            "owner_price_direct_logistic_id" => $model->id,   //直发车计费ID
+            "car_type_id" => $cars[1]->id,                      //车型ID
+            "base_fee" =>1.3,                         //起步费
+            "additional_fee" =>1.6,                   //续费(元/KM)
+        ]);
+        $result = $this->service->matching(10,$owner->id,$cars[0]->id);
+        $this->assertEquals(23,$result);
+        $result = $this->service->matching(10,$owner->id,$cars[1]->id);
+        $this->assertEquals(15.4,$result);
+        $model->owners()->sync([]);
+        Owner::destroy($owner->id);
+        CarType::destroy(array_column($cars->toArray(),"id"));
+        OwnerPriceDirectLogisticCar::destroy([$item1->id,$item2->id]);
+    }
+
+    public function tearDown(): void
+    {
+        OwnerPriceDirectLogistic::destroy(array_column($this->data["models"],"id"));
+        parent::tearDown();
+    }
+}

+ 0 - 79
tests/Services/OwnerPriceDirectLogisticServiceTest.php

@@ -1,79 +0,0 @@
-<?php
-
-
-namespace Tests\Services;
-
-use App\OwnerPriceDirectLogistic;
-use App\OwnerPriceDirectLogisticCar;
-use App\Services\OwnerPriceDirectLogisticService;
-use Ramsey\Uuid\Uuid;
-use Tests\TestCase;
-
-class OwnerPriceDirectLogisticServiceTest extends  TestCase
-{
-    /** @var OwnerPriceDirectLogisticService */
-    public $service;
-    public $data;
-
-    protected function setUp(): void
-    {
-        parent::setUp();
-        $this->service = app(OwnerPriceDirectLogisticService::class);
-
-        $this->data["models"] = factory(OwnerPriceDirectLogistic::class,3)->create()->toArray();
-    }
-
-    public function testPaginate()
-    {
-        $models = $this->service->paginate();
-        $this->assertGreaterThanOrEqual(3,count($models));
-        $this->assertLessThanOrEqual(50,count($models));
-        $models = $this->service->paginate($this->data["models"][0]["id"]);
-        $this->assertCount(1,$models);
-    }
-    public function testCreate()
-    {
-        $model = $this->service->create([
-            "name" => Uuid::uuid1(),
-            "base_km" => 3
-        ]);
-        $this->assertNotNull($model);
-        $this->data["models"][] = $model->toArray();
-    }
-    public function testDestroy()
-    {
-        $result = $this->service->destroy(array_column($this->data["models"],"id"));
-        $this->assertEquals(3,$result);
-        $this->data["models"] = [];
-    }
-    public function testFind()
-    {
-        $model = $this->service->find($this->data["models"][0]["id"]);
-        $this->assertNotNull($model);
-    }
-    public function testUpdate()
-    {
-        $id = $this->data["models"][0]["id"];
-        $result = $this->service->update(["id"=>$id],[
-            "base_km" => 3
-        ]);
-        $this->assertEquals(1,$result);
-        $model = OwnerPriceDirectLogistic::query()->find($id);
-        $this->assertEquals(3,$model->base_km);
-    }
-    public function testUpdateDetail()
-    {
-        OwnerPriceDirectLogisticCar::query()->create([
-            "owner_price_direct_logistic_id" => $this->data["models"][0]["id"],   //直发车计费ID
-            "car_type_id",                      //车型ID
-            "base_fee",                         //起步费
-            "additional_fee",                   //续费(元/KM)
-        ]);
-    }
-
-    public function tearDown(): void
-    {
-        OwnerPriceDirectLogistic::destroy(array_column($this->data["models"],"id"));
-        parent::tearDown();
-    }
-}

+ 203 - 0
tests/Services/OwnerPriceExpressService/OwnerPriceExpressServiceTest.php

@@ -0,0 +1,203 @@
+<?php
+
+
+namespace Tests\Services\OwnerPriceExpressService;
+
+
+use App\Logistic;
+use App\Owner;
+use App\OwnerPriceExpress;
+use App\OwnerPriceExpressProvince;
+use App\Province;
+use App\Services\OwnerPriceExpressService;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+class OwnerPriceExpressServiceTest extends  TestCase
+{
+    /** @var OwnerPriceExpressService */
+    public $service;
+    public $data;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(OwnerPriceExpressService::class);
+
+        $this->data["models"] = factory(OwnerPriceExpress::class,2)->create()->toArray();
+    }
+
+    /**
+     * @group customer
+     */
+    public function testPaginate()
+    {
+        $models = $this->service->paginate();
+        $this->assertGreaterThanOrEqual(2,count($models));
+        $models = $this->service->paginate($this->data["models"][0]["id"]);
+        $this->assertCount(1,$models);
+    }
+    /**
+     * @group customer
+     */
+    public function testFind()
+    {
+        $model = $this->service->find($this->data["models"][0]["id"]);
+        $this->assertNotNull($model);
+    }
+    /**
+     * @group customer
+     */
+    public function testUpdateDetail()
+    {
+        $detail = factory(OwnerPriceExpressProvince::class)->create([
+            "owner_price_express_id" => $this->data["models"][0]["id"],   //快递价格ID
+        ]);
+        $result = $this->service->updateDetail(["id"=>$detail->id],["initial_weight_price"=>5]);
+        $this->assertEquals(1,$result);
+        OwnerPriceExpressProvince::destroy($detail->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testCreate()
+    {
+        $model = $this->service->create([
+            "name" => md5(Str::random(8)),
+            "initial_weight" => mt_rand(6,260) / 5,
+            "additional_weight" => mt_rand(6,260) / 5,
+        ]);
+        $this->assertNotNull($model);
+        $this->data["models"][] = $model->toArray();
+    }
+    /**
+     * @group customer
+     */
+    public function testCreateDetail()
+    {
+        $model = $this->service->createDetail([
+            "owner_price_express_id" => $this->data["models"][0]["id"],
+            "province_id" => 1,
+            "initial_weight_price" => mt_rand(6,260) / 5,
+            "additional_weight_price"=>mt_rand(6,260) / 5,
+        ]);
+        $this->assertNotNull($model);
+        $this->assertNotNull($model->id);
+        OwnerPriceExpressProvince::destroy($model->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testIsExistDetail()
+    {
+        $province = Province::query()->first();
+        $detail = factory(OwnerPriceExpressProvince::class)->create([
+            "owner_price_express_id" => $this->data["models"][0]["id"],
+            "province_id" => $province->id
+        ]);
+        $result = $this->service->isExistDetail([
+            "owner_price_express_id"=>$this->data["models"][0]["id"],
+            "province_id" => $province->id
+        ]);
+        $this->assertGreaterThan(0,$result);
+        OwnerPriceExpressProvince::destroy($detail->id);
+    }
+    /**
+     * @group customer
+     */
+    public function testDestroyDetail()
+    {
+        $detail = factory(OwnerPriceExpressProvince::class)->create([
+            "owner_price_express_id" => $this->data["models"][0]["id"],
+        ]);
+        $result = $this->service->destroyDetail($detail->id);
+        $this->assertEquals(1,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testGetExistOwnerName()
+    {
+        $owner = factory(Owner::class)->create([
+            "user_owner_group_id" => 1,
+        ]);
+        /** @var OwnerPriceExpress $model */
+        $model = OwnerPriceExpress::query()->find($this->data["models"][0]["id"]);
+        $model->owners()->sync([$owner->id]);
+        $result = $this->service->getExistOwnerName([$owner->id],$this->data["models"][0]["id"]);
+        $this->assertCount(0,$result);
+        $result = $this->service->getExistOwnerName([$owner->id]);
+        $this->assertCount(1,$result);
+        $this->assertEquals($owner->name,$result[0]);
+        Owner::destroy($owner->id);
+        $model->owners()->sync([]);
+    }
+    /**
+     * @group customer
+     */
+    public function testGetExistLogisticName()
+    {
+        $logistic = factory(Logistic::class)->create();
+        /** @var OwnerPriceExpress $model */
+        $model = OwnerPriceExpress::query()->find($this->data["models"][0]["id"]);
+        $model->logistics()->sync([$logistic->id]);
+
+        $result = $this->service->getExistLogisticName([$logistic->id],$this->data["models"][0]["id"]);
+        $this->assertCount(0,$result);
+        $result = $this->service->getExistLogisticName([$logistic->id]);
+        $this->assertCount(1,$result);
+        $this->assertEquals($logistic->name,$result[0]);
+
+        Logistic::destroy($logistic->id);
+        $model->logistics()->sync([]);
+    }
+    /**
+     * @group customer
+     */
+    public function testDestroy()
+    {
+        $result = $this->service->destroy($this->data["models"][0]["id"]);
+        $this->assertEquals(1,$result);
+        unset($this->data["models"][0]);
+    }
+    /**
+     * @group customer
+     */
+    public function testUpdate()
+    {
+        $result = $this->service->update(["id"=>$this->data["models"][0]["id"]],["initial_weight"=>3]);
+        $this->assertEquals(1,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testMatching()
+    {
+        /** @var OwnerPriceExpress $model */
+        $model = factory(OwnerPriceExpress::class)->create([
+            "initial_weight" => 2.4,
+            "additional_weight" => 3.1,//16.2
+        ]);
+        $this->data["models"][] = $model->toArray();
+        $detail = factory(OwnerPriceExpressProvince::class)->create([
+            "owner_price_express_id" => $model->id,
+            "province_id" => 1,
+            "initial_weight_price" => 2,     //初始单价 4.8
+            "additional_weight_price"=>2.2,  //续重单价
+        ]);
+        $model->owners()->sync([1]);
+        $model->logistics()->sync([1]);
+        $result = $this->service->matching(18.6,1,1,1);
+        $this->assertEquals(18,$result);
+        $model->owners()->sync([]);
+        $model->logistics()->sync([]);
+        OwnerPriceExpressProvince::destroy($detail->id);
+    }
+
+
+    public function tearDown(): void
+    {
+        OwnerPriceExpress::destroy(array_column($this->data["models"],"id"));
+        parent::tearDown();
+    }
+}

+ 220 - 0
tests/Services/OwnerPriceLogisticService/OwnerPriceLogisticServiceTest.php

@@ -0,0 +1,220 @@
+<?php
+
+
+namespace Tests\Services\OwnerPriceLogisticService;
+
+use App\Logistic;
+use App\Owner;
+use App\OwnerPriceLogistic;
+use App\OwnerPriceLogisticDetail;
+use App\Services\OwnerPriceLogisticService;
+use App\Unit;
+use Illuminate\Support\Str;
+use Tests\TestCase;
+
+class OwnerPriceLogisticServiceTest extends  TestCase
+{
+    /** @var OwnerPriceLogisticService */
+    public $service;
+    public $data;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(OwnerPriceLogisticService::class);
+
+        $units = factory(Unit::class,2)->create();
+        $this->data["units"] = $units->toArray();
+        $this->data["details"] = [];
+        $this->data["owners"] = [];
+        $this->data["logistics"] = [];
+        $this->data["models"] = factory(OwnerPriceLogistic::class,3)->create([
+            "unit_id" => $units[0]->id,
+            "other_unit_id" => $units[1]->id,
+        ])->toArray();
+    }
+
+    /**
+     * @group customer
+     */
+    public function testPaginate()
+    {
+        $models = $this->service->paginate();
+        $this->assertGreaterThanOrEqual(3,count($models));
+        $this->assertLessThanOrEqual(50,count($models));
+    }
+    /**
+     * @group customer
+     */
+    public function create()
+    {
+        $model = $this->service->create([
+            "name" => md5(Str::random(7)),
+            "unit_range" => "0-5,5-10,10-15,15-20",
+            "unit_id" => $this->data["units"][0]["id"],
+            "other_unit_range" => "0-5,5-10,10-15,15-20,30-",
+            "other_unit_id" => $this->data["units"][1]["id"],
+            "pick_up_price" => mt_rand(2,230) / 3,
+            "fuel_price" => mt_rand(2,230) / 3,
+            "service_price" => mt_rand(2,230) / 3,
+        ]);
+        $this->assertNotNull($model);
+        $this->data["models"][] = $model->toArray();
+    }
+    /**
+     * @group customer
+     */
+    public function testFind()
+    {
+        $model = $this->service->find($this->data["models"][0]["id"]);
+        $this->assertNotNull($model);
+    }
+    /**
+     * @group customer
+     */
+    public function testUpdate()
+    {
+        $result = $this->service->update(["id"=>$this->data["models"][0]["id"]],[
+            "fuel_price" => 2.222,
+        ]);
+        $this->assertEquals(1,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testUpdateDetail()
+    {
+        $province = \App\Province::query()->first();
+        $city = \App\City::query()->where("province_id",$province->id)->first();
+        $detail = factory(OwnerPriceLogisticDetail::class)->create([
+            "owner_price_logistic_id" => $this->data["models"][0]["id"],  //物流计费
+            "unit_id" => 1,                  //单位ID
+            "range" => "0-5",                    //区间
+            "province_id" => $province->id,              //省份ID
+            "city_id" => $city->id,
+        ]);
+        $this->assertNotNull($detail);
+        $this->data["details"][] = $detail->toArray();
+        $result = $this->service->updateDetail(["id"=>$detail->id],["range"=>"30-"]);
+        $this->assertEquals(1,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testIsExistDetail()
+    {
+        $detail = factory(OwnerPriceLogisticDetail::class)->create([
+            "owner_price_logistic_id" => $this->data["models"][0]["id"],  //物流计费
+            "unit_id" => 1,                  //单位ID
+        ]);
+        $this->data["details"][] = $detail->toArray();
+        $result = $this->service->isExistDetail(["unit_id"=>1,"owner_price_logistic_id"=> $this->data["models"][0]["id"]]);
+        $this->assertGreaterThan(0,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testCreateDetail()
+    {
+        $detail = $this->service->createDetail([
+            "owner_price_logistic_id" => 1,
+            "unit_id" => 1,
+            "range" => "0-5",
+            "province_id" => 1,
+            "city_id" => 1,
+            "unit_price" => mt_rand(1,36) / 3,
+            "delivery_fee" => mt_rand(1,136) / 3,
+            "initial_fee" => mt_rand(1,136) / 3,
+            "initial_amount" => mt_rand(1,136) / 3,
+            "rate" =>  mt_rand(1,136) / 3,
+        ]);
+        $this->assertNotNull($detail);
+        $this->data["details"][] = $detail->toArray();
+    }
+    /**
+     * @group customer
+     */
+    public function testDestroyDetail()
+    {
+        $detail = factory(OwnerPriceLogisticDetail::class)->create([
+            "owner_price_logistic_id" => $this->data["models"][0]["id"],  //物流计费
+            "unit_id" => 1,                  //单位ID
+        ]);
+        $this->data["details"][] = $detail->toArray();
+        $result = $this->service->destroyDetail($detail->id);
+        $this->assertEquals(1,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testCheckRange()
+    {
+        $result = $this->service->checkRange("0-5,5-10,10-15,15-30,30-");
+        $this->assertEquals(true,$result);
+        $result = $this->service->checkRange("0-5,5-10,10-15,15-30");
+        $this->assertEquals(false,$result);
+        $result = $this->service->checkRange("0-5,5-10,10-15,16-30,30-");
+        $this->assertEquals(false,$result);
+        $result = $this->service->checkRange("0-55-10,10-15,16-30,30-");
+        $this->assertEquals(false,$result);
+    }
+    /**
+     * @group customer
+     */
+    public function testMatching()
+    {
+        /** @var OwnerPriceLogistic $model */
+        $model = factory(OwnerPriceLogistic::class)->create([
+            "name" => md5(date('Ymd')).Str::random(4),             //名称
+            "unit_range" => "0-5,5-10,10-15,15-20",       //单价一区间
+            "unit_id" => 1,          //单位一ID
+            "other_unit_range" => "0-5,5-10,10-15,15-20,30-", //单位二区间
+            "other_unit_id" => 2,    //单位二ID
+            "pick_up_price" => 1.5,    //提货费
+            "fuel_price" => 2.5,       //燃油附加费
+            "service_price" => 3.5,    //信息服务费
+        ]);
+        $this->data["models"][] = $model->toArray();
+        $owner = factory(Owner::class)->create([
+            "user_owner_group_id" => 1
+        ]);
+        $this->data["owners"][] = $owner->toArray();
+        $logistic = factory(Logistic::class)->create();
+        $this->data["logistics"][] = $owner->toArray();
+        $model->owners()->sync([$owner->id]);
+        $model->logistics()->sync([$logistic->id]);
+        $detail = factory(OwnerPriceLogisticDetail::class)->create([
+            "owner_price_logistic_id" => $model->id,  //物流计费
+            "unit_id" => 1,                  //单位ID
+            "range" => "10-30",                    //区间
+            "province_id" => 1,              //省份ID
+            "city_id" => 1,                  //城市ID
+            "unit_price" => 32.6,               //单价
+            "delivery_fee" => 123,             //送货费
+            "initial_fee" => 500,              //起始计费
+            "initial_amount" => 6,           //起始计数
+            "rate" =>  0,                       //费率
+        ]);//7.5
+        $this->data["details"][] = $detail->toArray();
+        $result = $this->service->matching(20,$owner->id,$logistic->id,1,1,1);
+        $this->assertEquals(782.5,$result);
+        $result = $this->service->matching(31,$owner->id,$logistic->id,1,1,1);
+        $this->assertEquals(-1,$result);
+    }
+
+    public function tearDown(): void
+    {
+        Unit::destroy(array_column($this->data["units"],"id"));
+        foreach ($this->data["models"] as $model){
+            /** @var OwnerPriceLogistic $item */
+            $item = OwnerPriceLogistic::query()->find($model["id"]);
+            $item->owners()->sync([]);
+            $item->logistics()->sync([]);
+        }
+        OwnerPriceLogistic::destroy(array_column($this->data["models"],"id"));
+        OwnerPriceLogisticDetail::destroy(array_column($this->data["details"],"id"));
+        Owner::destroy(array_column($this->data["owners"],"id"));
+        Logistic::destroy(array_column($this->data["logistics"],"id"));
+        parent::tearDown();
+    }
+}

+ 169 - 0
tests/Services/OwnerPriceOperationService/OwnerPriceOperationServiceTest.php

@@ -0,0 +1,169 @@
+<?php
+
+
+namespace Tests\Services\OwnerPriceOperationService;
+
+use App\Commodity;
+use App\Owner;
+use App\OwnerInStorageRule;
+use App\OwnerOutStorageRule;
+use App\OwnerPriceOperation;
+use App\Services\FeatureService;
+use App\Services\OwnerPriceOperationService;
+use App\Unit;
+use Mockery\Mock;
+use Tests\TestCase;
+
+class OwnerPriceOperationServiceTest extends  TestCase
+{
+    /** @var OwnerPriceOperationService */
+    public $service;
+    public $data;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(OwnerPriceOperationService::class);
+
+        $this->data["units"] = [];
+        $pieces = Unit::query()->where("name","件")->first();
+        $box = Unit::query()->where("name","箱")->first();
+        $single = Unit::query()->where("name","单")->first();
+        if (!$pieces){
+            $pieces = factory(Unit::class)->create(["name"=>"件"]);
+            $this->data["units"][] = $pieces->toArray();
+        }
+        if (!$box){
+            $box = factory(Unit::class)->create(["name"=>"箱"]);
+            $this->data["units"][] = $box->toArray();
+        }
+        if (!$single){
+            $single = factory(Unit::class)->create(["name"=>"单"]);
+            $this->data["units"][] = $single->toArray();
+        }
+        $model1 = factory(OwnerPriceOperation::class)->create([
+            "operation_type"=>"入库",   //操作类型
+            "strategy"      =>"默认",         //策略
+        ]);
+        $model2 = factory(OwnerPriceOperation::class)->create([
+            "operation_type"=>"入库",   //操作类型
+            "strategy"      =>"特征",         //策略
+        ]);
+        $model3 = factory(OwnerPriceOperation::class)->create([
+            "operation_type"=>"出库",   //操作类型
+            "strategy"      =>"默认",         //策略
+        ]);
+        $model4 = factory(OwnerPriceOperation::class)->create([
+            "operation_type"=>"出库",   //操作类型
+            "strategy"      =>"特征",         //策略
+        ]);
+        $this->data["models"] = [$model1->toArray(),$model2->toArray(),$model3->toArray(),$model4->toArray()];
+
+        $in1 = factory(OwnerInStorageRule::class)->create([
+            "owner_price_operation_id"  => $model1->id, //作业计费ID
+            "amount"                    => 5,                   //计量
+            "unit_id"                   => $pieces->id,//单位ID
+            "unit_price"                => 2.22,               //单价
+        ]);
+        $in2 = factory(OwnerInStorageRule::class)->create([
+            "owner_price_operation_id"  => $model2->id, //作业计费ID
+            "amount"                    => 5,                   //计量
+            "unit_id"                   => $box->id,//单位ID
+            "unit_price"                => 3.22,               //单价
+        ]);
+        $out1 = factory(OwnerOutStorageRule::class)->create([
+            "owner_price_operation_id"          => $model3->id,
+            "strategy"                          =>"起步",
+            "amount"                            =>6,
+            "unit_id"                           => $pieces->id,
+            "unit_price"                        => 2.22,
+        ]);
+        $out4 = factory(OwnerOutStorageRule::class)->create([
+            "owner_price_operation_id"          => $model3->id,
+            "strategy"                          => "默认",
+            "amount"                            => 6,
+            "unit_id"                           => $box->id,
+            "unit_price"                        => 3.22,
+        ]);
+        $out5 = factory(OwnerOutStorageRule::class)->create([
+            "owner_price_operation_id"          => $model3->id,
+            "strategy"                          =>"特征",
+            "amount"                            => 6,
+            "unit_id"                           => $single->id,
+            "unit_price"                        => 4.22,
+        ]);
+        $out6 = factory(OwnerOutStorageRule::class)->create([
+            "owner_price_operation_id"          => $model4->id,
+            "strategy"                          =>"起步",
+            "amount"                            => 6,
+            "unit_id"                           => $pieces->id,
+            "unit_price"                        => 5.1,
+        ]);
+        $out7 = factory(OwnerOutStorageRule::class)->create([
+            "owner_price_operation_id"          => $model4->id,
+            "strategy"                          => "默认",
+            "amount"                            => 6,
+            "unit_id"                           => $pieces->id,
+            "unit_price"                        => 5.2,
+        ]);
+        $out8 = factory(OwnerOutStorageRule::class)->create([
+            "owner_price_operation_id"          => $model4->id,
+            "strategy"                          =>"特征",
+            "amount"                            => 6,
+            "unit_id"                           => $box->id,
+            "unit_price"                        => 5.3,
+        ]);
+        $this->data["in"] = [$in1->toArray(),$in2->toArray()];
+        $this->data["out"] = [$out1->toArray(),$out4->toArray(),$out5->toArray(),$out6->toArray(),$out7->toArray(),$out8->toArray()];
+        $owner = factory(Owner::class)->create([
+            "user_owner_group_id" => 1,
+        ]);
+        $model1->ownerPriceOperationOwners()->sync([$owner->id]);
+        $model2->ownerPriceOperationOwners()->sync([$owner->id]);
+        $model3->ownerPriceOperationOwners()->sync([$owner->id]);
+        $model4->ownerPriceOperationOwners()->sync([$owner->id]);
+        $this->data["owners"] = [$owner->toArray()];
+        $this->data["commodities"] = [];
+        $commodity = factory(Commodity::class)->create([
+            'sku' => md5(date('Ymd').\Illuminate\Support\Str::random(3)),
+            'owner_id' => $owner->id,
+            "pack_spec" => 3
+        ]);
+        $this->data["commodities"][] = $commodity->toArray();
+    }
+
+    /**
+     * @group customer
+     */
+    public function testMatchRule()
+    {
+        $this->partialMock(FeatureService::class,function ($mock){
+            /** @var Mock $mock */
+            $mock->shouldReceive("matchFeature")->andReturn(true);
+        });
+        $result = $this->service->matchRule(55,[],[],$this->data["owners"][0]["id"],$this->data["commodities"][0]["sku"],"入库");
+        $this->assertEquals(12.88,$result);
+        $result = $this->service->matchRule(56,[],[],$this->data["owners"][0]["id"],null,"入库");
+        $this->assertEquals(26.64,$result);
+        $result = $this->service->matchRule(57,[],[],$this->data["owners"][0]["id"],$this->data["commodities"][0]["sku"],"出库");
+        $this->assertEquals(46.5,$result);
+        $result = $this->service->matchRule(58,[],[],$this->data["owners"][0]["id"],null,"出库");
+        $this->assertEquals(77.4,$result);
+    }
+
+    public function tearDown(): void
+    {
+        Unit::destroy(array_column($this->data["units"],"id"));
+        OwnerPriceOperation::destroy(array_column($this->data["models"],"id"));
+        foreach ($this->data["models"] as $d){
+            $model = new OwnerPriceOperation();
+            $model->id = $d["id"];
+            $model->ownerPriceOperationOwners()->sync([]);
+        }
+        OwnerInStorageRule::destroy(array_column($this->data["in"],"id"));
+        OwnerOutStorageRule::destroy(array_column($this->data["out"],"id"));
+        Owner::destroy(array_column($this->data["owners"],"id"));
+        Commodity::destroy(array_column($this->data["commodities"],"id"));
+        parent::tearDown();
+    }
+}

+ 72 - 0
tests/Services/OwnerStoragePriceModelService/OwnerStoragePriceModelServiceTest.php

@@ -0,0 +1,72 @@
+<?php
+
+
+namespace Tests\Services\OwnerStoragePriceModelService;
+
+use App\Owner;
+use App\OwnerReport;
+use App\OwnerStoragePriceModel;
+use App\Services\OwnerStoragePriceModelService;
+use Tests\TestCase;
+
+class OwnerStoragePriceModelServiceTest extends  TestCase
+{
+    /** @var OwnerStoragePriceModelService */
+    public $service;
+    public $data;
+
+    protected function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app(OwnerStoragePriceModelService::class);
+
+        $this->data["models"] = [
+            factory(OwnerStoragePriceModel::class)->create([
+                "minimum_area" => 600,     //最低起租面积
+                "price" => 80.4,            //单价
+                "discount_type" => "按单减免",    //减免类型
+                "discount_value" => 0.1,   //减免值
+                "unit_id" => 1,          //单位ID
+            ])->toArray(),
+            factory(OwnerStoragePriceModel::class)->create([
+                "minimum_area" => 600,     //最低起租面积
+                "price" => 80.4,            //单价
+                "discount_type" => "固定减免",    //减免类型
+                "discount_value" => 3.6,   //减免值
+                "unit_id" => 1,          //单位ID
+            ])->toArray(),
+        ];
+        $this->data["owners"] = [
+            factory(Owner::class)->create(["user_owner_group_id"=>1])->toArray()
+        ];
+        $this->data["reports"] = [
+            factory(OwnerReport::class)->create([
+                "owner_id" => $this->data["owners"][0]["id"],
+                "owner_bill_report_id"  =>1,
+                "total" => 1587,
+                "counting_month" => "2020-10-10"
+            ])->toArray()
+        ];
+    }
+
+    /**
+     * @group customer
+     */
+    public function testCalculationAmount()
+    {
+        $model = OwnerStoragePriceModel::query()->find($this->data["models"][0]["id"]);
+        $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
+        $this->assertEquals(48081.3,$result);
+        $model = OwnerStoragePriceModel::query()->find($this->data["models"][1]["id"]);
+        $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
+        $this->assertEquals(48236.4,$result);
+    }
+
+    public function tearDown(): void
+    {
+        OwnerStoragePriceModel::destroy(array_column($this->data["models"],"id"));
+        Owner::destroy(array_column($this->data["owners"],"id"));
+        OwnerReport::destroy(array_column($this->data["reports"],"id"));
+        parent::tearDown();
+    }
+}