|
|
@@ -5,9 +5,8 @@ namespace Tests\Services\OwnerPriceOperationService;
|
|
|
|
|
|
use App\Commodity;
|
|
|
use App\Owner;
|
|
|
-use App\OwnerInStorageRule;
|
|
|
-use App\OwnerOutStorageRule;
|
|
|
use App\OwnerPriceOperation;
|
|
|
+use App\OwnerPriceOperationItem;
|
|
|
use App\Services\FeatureService;
|
|
|
use App\Services\OwnerPriceOperationService;
|
|
|
use App\Unit;
|
|
|
@@ -59,58 +58,86 @@ class OwnerPriceOperationServiceTest extends TestCase
|
|
|
]);
|
|
|
$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,
|
|
|
+ $item1 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
+ "owner_price_operation_id" => $model1->id,
|
|
|
+ "strategy" => "默认",
|
|
|
+ "amount" => 6,
|
|
|
"unit_id" => $box->id,
|
|
|
"unit_price" => 2.22,
|
|
|
]);
|
|
|
- $out4 = factory(OwnerOutStorageRule::class)->create([
|
|
|
+ $item2 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
"owner_price_operation_id" => $model3->id,
|
|
|
- "strategy" => "默认",
|
|
|
+ "strategy" => "特征",
|
|
|
+ "amount" => 6,
|
|
|
"unit_id" => $box->id,
|
|
|
"unit_price" => 3.22,
|
|
|
]);
|
|
|
- $out5 = factory(OwnerOutStorageRule::class)->create([
|
|
|
+ $item3 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
+ "owner_price_operation_id" => $model2->id,
|
|
|
+ "strategy" =>"默认",
|
|
|
+ "amount" => 6,
|
|
|
+ "unit_id" => $box->id,
|
|
|
+ "unit_price" => 4.22,
|
|
|
+ ]);
|
|
|
+ $item4 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
+ "owner_price_operation_id" => $model2->id,
|
|
|
+ "strategy" =>"特征",
|
|
|
+ "amount" => 6,
|
|
|
+ "unit_id" => $box->id,
|
|
|
+ "unit_price" => 5.1,
|
|
|
+ ]);
|
|
|
+ $item5 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
+ "owner_price_operation_id" => $model3->id,
|
|
|
+ "strategy" => "起步",
|
|
|
+ "amount" => 6,
|
|
|
+ "unit_id" => $box->id,
|
|
|
+ "unit_price" => 5.2,
|
|
|
+ ]);
|
|
|
+ $item6 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
+ "owner_price_operation_id" => $model3->id,
|
|
|
+ "strategy" =>"默认",
|
|
|
+ "amount" => 6,
|
|
|
+ "unit_id" => $box->id,
|
|
|
+ "unit_price" => 5.3,
|
|
|
+ ]);
|
|
|
+ $item7 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
"owner_price_operation_id" => $model3->id,
|
|
|
"strategy" =>"特征",
|
|
|
+ "amount" => 6,
|
|
|
"unit_id" => $box->id,
|
|
|
- "unit_price" => 4.22,
|
|
|
+ "unit_price" => 5.4,
|
|
|
]);
|
|
|
- $out6 = factory(OwnerOutStorageRule::class)->create([
|
|
|
+ $item8 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
"owner_price_operation_id" => $model4->id,
|
|
|
- "strategy" =>"起步",
|
|
|
+ "strategy" => "起步",
|
|
|
"amount" => 6,
|
|
|
"unit_id" => $box->id,
|
|
|
- "unit_price" => 5.1,
|
|
|
+ "unit_price" => 5.5,
|
|
|
]);
|
|
|
- $out7 = factory(OwnerOutStorageRule::class)->create([
|
|
|
+ $item9 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
"owner_price_operation_id" => $model4->id,
|
|
|
- "strategy" => "默认",
|
|
|
+ "strategy" =>"默认",
|
|
|
+ "amount" => 6,
|
|
|
"unit_id" => $box->id,
|
|
|
- "unit_price" => 5.2,
|
|
|
+ "unit_price" => 5.6,
|
|
|
]);
|
|
|
- $out8 = factory(OwnerOutStorageRule::class)->create([
|
|
|
+ $item10 = factory(OwnerPriceOperationItem::class)->create([
|
|
|
"owner_price_operation_id" => $model4->id,
|
|
|
"strategy" =>"特征",
|
|
|
+ "amount" => 6,
|
|
|
"unit_id" => $box->id,
|
|
|
- "unit_price" => 5.3,
|
|
|
+ "unit_price" => 5.7,
|
|
|
]);
|
|
|
- $this->data["in"] = [$in1->toArray(),$in2->toArray()];
|
|
|
- $this->data["out"] = [$out1->toArray(),$out4->toArray(),$out5->toArray(),$out6->toArray(),$out7->toArray(),$out8->toArray()];
|
|
|
+ $this->data["item"] = [$item1->toArray(),
|
|
|
+ $item2->toArray(),
|
|
|
+ $item3->toArray(),
|
|
|
+ $item4->toArray(),
|
|
|
+ $item5->toArray(),
|
|
|
+ $item6->toArray(),
|
|
|
+ $item7->toArray(),
|
|
|
+ $item8->toArray(),
|
|
|
+ $item9->toArray(),
|
|
|
+ $item10->toArray()];
|
|
|
$owner = factory(Owner::class)->create([
|
|
|
"user_owner_group_id" => 1,
|
|
|
]);
|
|
|
@@ -131,26 +158,16 @@ class OwnerPriceOperationServiceTest extends TestCase
|
|
|
/**
|
|
|
* @group customer
|
|
|
*/
|
|
|
- public function testMatchRule()
|
|
|
+ public function testMatching()
|
|
|
{
|
|
|
$this->partialMock(FeatureService::class,function ($mock){
|
|
|
/** @var Mock $mock */
|
|
|
$mock->shouldReceive("matchFeature")->andReturn(true);
|
|
|
});
|
|
|
- $result = $this->service->matchRule(["packages"=>[["commodity"=>"测试","amount"=>55,"sku"=>$this->data["commodities"][0]["sku"]]]],[],$this->data["owners"][0]["id"],"入库");
|
|
|
- $this->assertEquals(12.88,$result);
|
|
|
- $result = $this->service->matchRule(["packages"=>[["commodity"=>"测试","amount"=>57,"sku"=>$this->data["commodities"][0]["sku"]]]],[],$this->data["owners"][0]["id"],"出库");
|
|
|
- $this->assertEquals(99.5,$result);
|
|
|
- }
|
|
|
- /**
|
|
|
- * @group customer
|
|
|
- */
|
|
|
- public function testMatchRule1()
|
|
|
- {
|
|
|
- $result = $this->service->matchRule(["packages"=>[["commodity"=>"测试","amount"=>56,"sku"=>$this->data["commodities"][0]["sku"]]]],[],$this->data["owners"][0]["id"],"入库");
|
|
|
- $this->assertEquals(26.64,$result);
|
|
|
- $result = $this->service->matchRule(["packages"=>[["commodity"=>"测试","amount"=>58,"sku"=>$this->data["commodities"][0]["sku"]]]],[],$this->data["owners"][0]["id"],"出库");
|
|
|
- $this->assertEquals(58.4,$result);
|
|
|
+ $result = $this->service->matching(["packages"=>[["commodity"=>"测试","amount"=>55,"sku"=>$this->data["commodities"][0]["sku"]]]],[],$this->data["owners"][0]["id"],"入库");
|
|
|
+ $this->assertEquals(96.9,$result);
|
|
|
+ $result = $this->service->matching(["packages"=>[["commodity"=>"测试","amount"=>57,"sku"=>$this->data["commodities"][0]["sku"]]]],[],$this->data["owners"][0]["id"],"出库");
|
|
|
+ $this->assertEquals(107.1,$result);
|
|
|
}
|
|
|
|
|
|
public function tearDown(): void
|
|
|
@@ -162,8 +179,7 @@ class OwnerPriceOperationServiceTest extends TestCase
|
|
|
$model->id = $d["id"];
|
|
|
$model->ownerPriceOperationOwners()->sync([]);
|
|
|
}
|
|
|
- OwnerInStorageRule::destroy(array_column($this->data["in"],"id"));
|
|
|
- OwnerOutStorageRule::destroy(array_column($this->data["out"],"id"));
|
|
|
+ OwnerPriceOperationItem::destroy(array_column($this->data["item"],"id"));
|
|
|
Owner::destroy(array_column($this->data["owners"],"id"));
|
|
|
Commodity::destroy(array_column($this->data["commodities"],"id"));
|
|
|
parent::tearDown();
|