|
|
@@ -44,17 +44,24 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
|
|
|
$end = Carbon::parse($this->reportDate)->endOfMonth()->toDateString();
|
|
|
$details =
|
|
|
DB::table('owner_store_fee_details')
|
|
|
- ->leftJoin('owner_fee_details', 'owner_fee_detail_id', '=', 'owner_fee_details.id')
|
|
|
- ->selectRaw("DATE_FORMAT(owner_store_fee_details.created_at,'%Y-%m') as counting_month,
|
|
|
+ ->selectRaw("
|
|
|
+ DATE_FORMAT(owner_store_fee_details.created_at,'%Y-%m') as counting_month,
|
|
|
unit_id,
|
|
|
unit_price,
|
|
|
+ work_name,
|
|
|
sum(amount) as amounts ,
|
|
|
owner_store_fee_details.owner_id,
|
|
|
owner_fee_detail_id,
|
|
|
- sum(owner_fee_details.work_fee) as work_fee,
|
|
|
- owner_store_fee_details.owner_price_operation_id")
|
|
|
+ sum(owner_store_fee_details.fee) as fee
|
|
|
+ ")
|
|
|
->whereBetween('owner_store_fee_details.created_at', [$start, $end])
|
|
|
- ->groupBy('counting_month', 'owner_store_fee_details.owner_id', 'owner_store_fee_details.owner_price_operation_id', 'unit_id', 'unit_price')
|
|
|
+ ->groupBy(
|
|
|
+ 'counting_month',
|
|
|
+ 'owner_id',
|
|
|
+ 'unit_id',
|
|
|
+ 'unit_price',
|
|
|
+ 'work_name'
|
|
|
+ )
|
|
|
->get();
|
|
|
$reports = [];
|
|
|
foreach ($details as $detail) {
|
|
|
@@ -65,16 +72,16 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
|
|
|
->where('counting_month', $counting_month)->first();
|
|
|
$reports[] = [
|
|
|
'owner_bill_report_id' => $ownerBillReport->id ?? null,
|
|
|
- 'owner_price_operation_id' => $detail->owner_price_operation_id,
|
|
|
'owner_id' => $detail->owner_id,
|
|
|
'counting_month' => $counting_month,
|
|
|
'unit_id' => $detail->unit_id,
|
|
|
'unit_price' => $detail->unit_price,
|
|
|
'amount' => $detail->amounts,
|
|
|
- 'fee' => $detail->work_fee,
|
|
|
+ 'fee' => $detail->fee,
|
|
|
+ 'work_name' => $detail->work_name,
|
|
|
];
|
|
|
}
|
|
|
- $reports_chunked = array_chunk($reports,1000 );
|
|
|
+ $reports_chunked = array_chunk($reports, 1000);
|
|
|
//保证幂等性 插入前删除该月的统计数据
|
|
|
OwnerStoreFeeReport::query()->where('counting_month', $counting_month)->delete();
|
|
|
|
|
|
@@ -95,18 +102,16 @@ class OwnerStoreFeeReportService implements \App\Interfaces\SettlementBillReport
|
|
|
$totalFee = $archived->information['totalFee'];
|
|
|
$owner_price_operation_fees = collect($archived->information['owner_price_operation_fees']);
|
|
|
} else {
|
|
|
- $reports = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->orderByDesc('owner_price_operation_id')->get();
|
|
|
+ $reports = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->get();
|
|
|
$totalAmount = $reports->sum('amount');
|
|
|
- $totalFee = number_format($reports->sum('fee'),2);
|
|
|
-
|
|
|
- $owner_price_operation_fees = OwnerStoreFeeReport::query()
|
|
|
- ->with('ownerPriceOperation:id,name')
|
|
|
- ->selectRaw("sum(fee) as fee,owner_price_operation_id")
|
|
|
+ $totalFee = number_format($reports->sum('fee'), 2);
|
|
|
+ $owner_price_operation_fees = OwnerStoreFeeReport::query()
|
|
|
+ ->selectRaw("sum(fee) as fee,work_name")
|
|
|
->where('owner_id', $kvPairs['owner_id'])
|
|
|
->where('counting_month', $kvPairs['counting_month'])
|
|
|
- ->groupBy('owner_price_operation_id')->get();
|
|
|
+ ->groupBy('work_name')->get();
|
|
|
}
|
|
|
- return array($reports, $totalAmount, $totalFee,$owner_price_operation_fees);
|
|
|
+ return array($reports, $totalAmount, $totalFee, $owner_price_operation_fees);
|
|
|
}
|
|
|
|
|
|
/**
|