OwnerStoragePriceModelServiceTest.php 3.5 KB

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