| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Services;
- use App\Traits\ServiceAppAop;
- use App\OwnerBillTotal;
- class OwnerBillTotalService
- {
- use ServiceAppAop;
- protected $modelClass = OwnerBillTotal::class;
- /**
- * 生成统计数据
- * @param string|null $counting_month string 统计月份默认为上一个月
- */
- public function record(string $counting_month = null)
- {
- if (is_null($counting_month)) {
- $counting_month = now()->subMonth()->startOfMonth()->toDateString();
- }
- /**
- * 1. 查询需要统计的货主
- * 2. 遍历货主
- * 3. 计算单个货主的费用
- * 4. 从相关表中获取总计信息,填入information
- * 5. 保存单个货主的信息
- */
- //查询需要统计的货主
- //没有删除的货主,货主删除时间晚于上个月1号的
- $owners = \App\Owner::query()
- ->where('deleted_at', '>=', now()->subMonth()->startOfMonth())
- ->orWhereNull('deleted_at')->get();
- foreach ($owners as $owner) {
- $information = [];
- //仓储费
- $storageFee = $this->getStorageFeeForTotal($counting_month, $owner->id);
- //入库费
- $storeFee = $this->getStoreFeeForTotal($counting_month, $owner->id);
- $information[] = [
- 'storageFee' => $storageFee,
- ];
- dd($information);
- }
- }
- /**
- * 重新统计
- * @param $owner_id
- * @param $counting_month
- */
- public function restartRecord($owner_id, $counting_month)
- {
- OwnerBillTotal::query()
- ->where('owner_id', $owner_id)
- ->where('counting_month', $counting_month)
- ->updateOrInsert();
- }
- public function getRecord(): array
- {
- $result = [];
- return $result;
- }
- /**
- * 仓储费
- * @param string|null $counting_month
- * @param $owner_id
- * @return array
- */
- private function getStorageFeeForTotal(?string $counting_month, $owner_id): array
- {
- /** @var $service SettlementBillsAreaFeeService */
- $service = app('SettlementBillsAreaFeeService');
- list($areaReports, $billReport) = $service->get([
- 'counting_month' => $counting_month,
- 'owner_id' => $owner_id,
- 'type' => $service::TYPE,
- ]);
- $storageFee = [
- 'data' => [],
- 'fee' => $billReport->storage_fee,
- ];
- foreach ($areaReports as $areaReport) {
- //起租面积:1.2元/m^3/天
- $remark = '起租面积:'
- . $areaReport->ownerStoragePriceModel->minimum_area . ','
- . $areaReport->ownerStoragePriceModel->price . '/'
- . $areaReport->ownerStoragePriceModel->unit->name .
- '/' . $areaReport->ownerStoragePriceModel->timeUnit->name;
- $storageFee['data'][] = [
- 'name' => $areaReport->ownerStoragePriceModel->name,
- 'remark' => $remark,
- ];
- }
- return $storageFee;
- }
- private function getStoreFeeForTotal(?string $counting_month, $id)
- {
- // $service = app('')
- }
- }
|