OwnerStoragePriceModelServiceTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Tests\Services\OwnerStoragePriceModelService;
  3. use App\Owner;
  4. use App\OwnerReport;
  5. use App\OwnerStoragePriceModel;
  6. use App\Services\OwnerStoragePriceModelService;
  7. use App\Unit;
  8. use Tests\TestCase;
  9. class OwnerStoragePriceModelServiceTest extends TestCase
  10. {
  11. /** @var OwnerStoragePriceModelService */
  12. public $service;
  13. public $data;
  14. protected function setUp(): void
  15. {
  16. parent::setUp();
  17. $this->service = app(OwnerStoragePriceModelService::class);
  18. $unit = Unit::query()->where("name","月")->first();
  19. $units = [];
  20. if (!$unit){
  21. $unit = Unit::query()->create([
  22. "name" => "月",
  23. "code" => "月"
  24. ]);
  25. $units[] = $unit;
  26. }
  27. $this->data["units"] = $units;
  28. $this->data["models"] = [
  29. factory(OwnerStoragePriceModel::class)->create([
  30. "minimum_area" => 600, //最低起租面积
  31. "price" => 80.4, //单价
  32. "discount_type" => "按单减免", //减免类型
  33. "discount_value" => 0.1, //减免值
  34. "unit_id" => 1, //单位ID
  35. "time_unit_id" => $unit->id, //单位ID
  36. ])->toArray(),
  37. factory(OwnerStoragePriceModel::class)->create([
  38. "minimum_area" => 600, //最低起租面积
  39. "price" => 80.4, //单价
  40. "discount_type" => "固定减免", //减免类型
  41. "discount_value" => 3.6, //减免值
  42. "unit_id" => 1, //单位ID
  43. "time_unit_id" => $unit->id, //计时单位ID
  44. ])->toArray(),
  45. ];
  46. $this->data["owners"] = [
  47. factory(Owner::class)->create(["user_owner_group_id"=>1])->toArray()
  48. ];
  49. $this->data["reports"] = [
  50. factory(OwnerReport::class)->create([
  51. "owner_id" => $this->data["owners"][0]["id"],
  52. "owner_bill_report_id" =>1,
  53. "total" => 1587,
  54. "counting_month" => "2020-10-10"
  55. ])->toArray()
  56. ];
  57. }
  58. /**
  59. * @group customer
  60. */
  61. public function testCalculationAmount()
  62. {
  63. $model = OwnerStoragePriceModel::query()->find($this->data["models"][0]["id"]);
  64. $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
  65. $this->assertEquals(48081.3,$result);
  66. $model = OwnerStoragePriceModel::query()->find($this->data["models"][1]["id"]);
  67. $result = $this->service->calculationAmount($model,548.98,$this->data["owners"][0]["id"],"2020-10-10");
  68. $this->assertEquals(48236.4,$result);
  69. }
  70. public function tearDown(): void
  71. {
  72. OwnerStoragePriceModel::destroy(array_column($this->data["models"],"id"));
  73. Owner::destroy(array_column($this->data["owners"],"id"));
  74. OwnerReport::destroy(array_column($this->data["reports"],"id"));
  75. Unit::destroy(array_column($this->data["units"],"id"));
  76. parent::tearDown();
  77. }
  78. }