| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Traits;
- use App\OwnerBillReport;
- use App\OwnerBillReportArchive;
- use App\Services\OwnerBillReportArchiveService;
- use App\Services\OwnerFeeTotalService;
- use Carbon\Carbon;
- trait SettlementBillServiceTrait
- {
- /**
- * @param $counting_month
- * @return array
- */
- public function getStartAndEnd($counting_month): array
- {
- $start = Carbon::parse($counting_month)->startOfMonth()->startOfDay()->toDateTimeString();
- $end = Carbon::parse($counting_month)->endOfMonth()->endOfDay()->toDateTimeString();
- return array($start, $end);
- }
- /**
- * 确认账单
- * @param $counting_month
- * @param $owner_id
- */
- public function confirmBill($counting_month, $owner_id)
- {
- $billReport = OwnerBillReport::query()
- ->select('id')
- ->where('owner_id', $owner_id)
- ->where('counting_month', $counting_month)
- ->firstOr(function () {
- return new OwnerBillReport();
- });
- OwnerBillReportArchive::query()->create([
- 'owner_bill_report_id' => $billReport->id ?? null,
- 'owner_id' => $owner_id,
- 'counting_month' => $counting_month,
- 'type' => $this::TYPE,
- 'archiver_id' => auth()->id(),
- 'archived_at' => now(),
- 'information' => [],
- ]);
- $this->confirmBillFeeTotal($counting_month, $owner_id);
- }
- /**
- * 确认总账单费用
- * @param $counting_month
- * @param $owner_id
- */
- public function confirmBillFeeTotal($counting_month, $owner_id): void
- {
- if ($this::TYPE !== '总费用') {
- /**@var $archiveService OwnerBillReportArchiveService */
- $archiveService = app('OwnerBillReportArchiveService');
- if (count($archiveService->getUnAchieved($counting_month, $owner_id)) == 0) {//全部子项已经确认完成
- //确认总费用
- /**@var $totalFeeService OwnerFeeTotalService */
- $totalFeeService = app('OwnerFeeTotalService');
- $totalFeeService->confirmBill($counting_month, $owner_id);
- }
- }
- }
- }
|