OwnerBillTotalService.php 3.4 KB

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