SettlementBillsAreaFeeService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerAreaReport;
  4. use App\OwnerBillReport;
  5. use App\OwnerBillReportArchive;
  6. use App\Traits\ServiceAppAop;
  7. class SettlementBillsAreaFeeService implements \App\Interfaces\SettlementBillReportInterface
  8. {
  9. /** @var $archiveService OwnerBillReportArchiveService */
  10. private $archiveService;
  11. const TYPE = '仓储费';
  12. use ServiceAppAop;
  13. use \App\Traits\SettlementBillServiceTrait;
  14. /**
  15. * @param array $kvPairs
  16. * @return array
  17. */
  18. public function get(array $kvPairs): array
  19. {
  20. $this->archiveService = app('OwnerBillReportArchiveService');
  21. $counting_month = $kvPairs['counting_month'];
  22. $owner_id = $kvPairs['owner_id'];
  23. if ($this->archiveService->isArchived($kvPairs['counting_month'], $kvPairs['owner_id'], $kvPairs['type']) == 1) {
  24. $archived = $this->archiveService->get($kvPairs);
  25. $areaReports = collect($archived->information['areaReports']);
  26. $billReport = collect($archived->information['billReport']);
  27. } else {
  28. $areaReports = OwnerAreaReport::query()
  29. ->with(['ownerStoragePriceModel' => function ($query) {
  30. $query->selectRaw("id,using_type,price,unit_id,unit_id,time_unit_id,name,minimum_area")
  31. ->with(['unit:id,name', 'timeUnit:id,name']);
  32. }])
  33. ->where('owner_id', $owner_id)
  34. ->where('counting_month', $counting_month)
  35. ->get();
  36. $billReport = OwnerBillReport::query()
  37. ->select(['storage_fee', 'id'])
  38. ->where('owner_id', $owner_id)
  39. ->where('counting_month', $counting_month)
  40. ->firstOr(function () {
  41. return new OwnerBillReport();
  42. });
  43. }
  44. return array($areaReports, $billReport);
  45. }
  46. public function getSql($owner_id, $counting_month): \Illuminate\Database\Eloquent\Builder
  47. {
  48. // TODO: Implement getSql() method.
  49. }
  50. public function getTotalFee($owner_id, $counting_month)
  51. {
  52. return OwnerBillReport::query()
  53. ->where('owner_id', $owner_id)
  54. ->where('counting_month', $counting_month)
  55. ->first();
  56. }
  57. public function switchType($type)
  58. {
  59. // TODO: Implement switchType() method.
  60. }
  61. public function buildExport($details): array
  62. {
  63. // TODO: Implement buildExport() method.
  64. }
  65. public function add(array $model)
  66. {
  67. // TODO: Implement add() method.
  68. }
  69. public function recordReport($counting_month = null,array $ownerIds = [])
  70. {
  71. // TODO: Implement recordReport() method.
  72. }
  73. public function confirmBill($counting_month, $owner_id)
  74. {
  75. list($areaReports, $billReport) = $this->get([
  76. 'owner_id' => $owner_id,
  77. 'counting_month' => $counting_month,
  78. 'type' => $this::TYPE,
  79. ]);
  80. OwnerBillReportArchive::query()->create([
  81. 'owner_bill_report_id' => $billReport->id ?? null,
  82. 'owner_id' => $owner_id,
  83. 'counting_month' => $counting_month,
  84. 'type' => $this::TYPE,
  85. 'archiver_id' => auth()->id(),
  86. 'archived_at' => now(),
  87. 'information' => [
  88. 'areaReports' => $areaReports,
  89. 'billReport' => $billReport,
  90. ],
  91. ]);
  92. $this->confirmBillFeeTotal($counting_month, $owner_id);
  93. }
  94. }