OwnerBillTotalService.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Services;
  3. use App\Traits\ServiceAppAop;
  4. use App\OwnerBillTotal;
  5. class OwnerBillTotalService
  6. {
  7. use ServiceAppAop;
  8. protected $modelClass = OwnerBillTotal::class;
  9. /**
  10. * 生成统计数据
  11. * @param string|null $counting_month string 统计月份默认为上一个月
  12. */
  13. public function record(string $counting_month = null)
  14. {
  15. if (is_null($counting_month)) {
  16. $counting_month = now()->subMonth()->startOfMonth()->toDateString();
  17. }
  18. /**
  19. * 1. 查询需要统计的货主
  20. * 2. 遍历货主
  21. * 3. 计算单个货主的费用
  22. * 4. 从相关表中获取总计信息,填入information
  23. * 5. 保存单个货主的信息
  24. */
  25. //查询需要统计的货主
  26. //没有删除的货主,货主删除时间晚于上个月1号的
  27. $owners = \App\Owner::query()
  28. ->where('deleted_at', '>=', now()->subMonth()->startOfMonth())
  29. ->orWhereNull('deleted_at')->get();
  30. foreach ($owners as $owner) {
  31. $information = [];
  32. //仓储费
  33. $storageFee = $this->getStorageFeeForTotal($counting_month, $owner->id);
  34. //入库费
  35. $storeFee = $this->getStoreFeeForTotal($counting_month, $owner->id);
  36. $information[] = [
  37. 'storageFee' => $storageFee,
  38. ];
  39. dd($information);
  40. }
  41. }
  42. /**
  43. * 重新统计
  44. * @param $owner_id
  45. * @param $counting_month
  46. */
  47. public function restartRecord($owner_id, $counting_month)
  48. {
  49. OwnerBillTotal::query()
  50. ->where('owner_id', $owner_id)
  51. ->where('counting_month', $counting_month)
  52. ->updateOrInsert();
  53. }
  54. public function getRecord(): array
  55. {
  56. $result = [];
  57. return $result;
  58. }
  59. /**
  60. * 仓储费
  61. * @param string|null $counting_month
  62. * @param $owner_id
  63. * @return array
  64. */
  65. private function getStorageFeeForTotal(?string $counting_month, $owner_id): array
  66. {
  67. /** @var $service SettlementBillsAreaFeeService */
  68. $service = app('SettlementBillsAreaFeeService');
  69. list($areaReports, $billReport) = $service->get([
  70. 'counting_month' => $counting_month,
  71. 'owner_id' => $owner_id,
  72. 'type' => $service::TYPE,
  73. ]);
  74. $storageFee = [
  75. 'data' => [],
  76. 'fee' => $billReport->storage_fee,
  77. ];
  78. foreach ($areaReports as $areaReport) {
  79. //起租面积:1.2元/m^3/天
  80. $remark = '起租面积:'
  81. . $areaReport->ownerStoragePriceModel->minimum_area . ','
  82. . $areaReport->ownerStoragePriceModel->price . '/'
  83. . $areaReport->ownerStoragePriceModel->unit->name .
  84. '/' . $areaReport->ownerStoragePriceModel->timeUnit->name;
  85. $storageFee['data'][] = [
  86. 'name' => $areaReport->ownerStoragePriceModel->name,
  87. 'remark' => $remark,
  88. ];
  89. }
  90. return $storageFee;
  91. }
  92. private function getStoreFeeForTotal(?string $counting_month, $id)
  93. {
  94. // $service = app('')
  95. }
  96. }