|
|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Services;
|
|
|
|
|
|
use App\OwnerBillReport;
|
|
|
+use App\OwnerStoreFeeDetail;
|
|
|
use App\Traits\ServiceAppAop;
|
|
|
use App\OwnerStoreFeeReport;
|
|
|
use App\Traits\SettlementBillTrait;
|
|
|
@@ -47,11 +48,15 @@ class OwnerStoreFeeReportService
|
|
|
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,
|
|
|
- owner_store_fee_details.type,unit_id,unit_price,sum(amount) as amounts ,
|
|
|
- owner_store_fee_details.owner_id,owner_fee_detail_id,
|
|
|
- sum(owner_fee_details.work_fee) as work_fee")
|
|
|
+ unit_id,
|
|
|
+ unit_price,
|
|
|
+ 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")
|
|
|
->whereBetween('owner_store_fee_details.created_at', [$start, $end])
|
|
|
- ->groupBy('counting_month', 'owner_store_fee_details.owner_id', 'owner_store_fee_details.type', 'unit_id', 'unit_price')
|
|
|
+ ->groupBy('counting_month', 'owner_store_fee_details.owner_id', 'owner_store_fee_details.owner_price_operation_id', 'unit_id', 'unit_price')
|
|
|
->get();
|
|
|
$reports = [];
|
|
|
foreach ($details as $detail) {
|
|
|
@@ -62,17 +67,19 @@ class OwnerStoreFeeReportService
|
|
|
->where('counting_month', $counting_month)->first();
|
|
|
$reports[] = [
|
|
|
'owner_bill_report_id' => $ownerBillReport->id ?? null,
|
|
|
- 'owner_price_operation_id' => null,//$detail->ownerFeeDetail->ownerPriceOperation->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,
|
|
|
- 'type' => $this->detailService->switchType($detail->type),
|
|
|
'fee' => $detail->work_fee,
|
|
|
];
|
|
|
}
|
|
|
- OwnerStoreFeeReport::query()->insertOrIgnore($reports);
|
|
|
+ $reports_chunked = array_chunk($reports,1000 );
|
|
|
+ foreach ($reports_chunked as $items) {
|
|
|
+ OwnerStoreFeeReport::query()->insertOrIgnore($items);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function get(array $kvPairs): array
|
|
|
@@ -85,27 +92,20 @@ class OwnerStoreFeeReportService
|
|
|
$reports = collect($archived->information['reports']);
|
|
|
$totalAmount = $archived->information['totalAmount'];
|
|
|
$totalFee = $archived->information['totalFee'];
|
|
|
- $newFee = $archived->information['newFee'];
|
|
|
- $backFee = $archived->information['backFee'];
|
|
|
+ $owner_price_operation_fees = collect($archived->information['owner_price_operation_fees']);
|
|
|
} else {
|
|
|
- $reports = $this->getReports($kvPairs['owner_id'], $kvPairs['counting_month']);
|
|
|
- $totalAmount = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->sum('amount');
|
|
|
- $totalFee = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->sum('fee');
|
|
|
- $newFee = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->where('type', $this->detailService->switchType('新品入库'))->sum('fee');
|
|
|
- $backFee = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->where('type', $this->detailService->switchType('退货入库'))->sum('fee');
|
|
|
- }
|
|
|
- return array($reports, $totalAmount, $totalFee, $newFee, $backFee);
|
|
|
- }
|
|
|
-
|
|
|
- public function getPaginate($owner_id, $counting_month, $paginateParams): LengthAwarePaginator
|
|
|
- {
|
|
|
- return $this->getSql($owner_id, $counting_month)
|
|
|
- ->paginate($paginateParams['paginate'] ?? 50);
|
|
|
- }
|
|
|
+ $reports = $this->getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->orderByDesc('owner_price_operation_id')->get();
|
|
|
+ $totalAmount = $reports->sum('amount');
|
|
|
+ $totalFee = number_format($reports->sum('fee'),2);
|
|
|
|
|
|
- public function getReports($owner_id, $counting_month)
|
|
|
- {
|
|
|
- return $this->getSql($owner_id, $counting_month)->orderByDesc('type')->get();
|
|
|
+ $owner_price_operation_fees = OwnerStoreFeeReport::query()
|
|
|
+ ->with('ownerPriceOperation:id,name')
|
|
|
+ ->selectRaw("sum(fee) as fee,owner_price_operation_id")
|
|
|
+ ->where('owner_id', $kvPairs['owner_id'])
|
|
|
+ ->where('counting_month', $kvPairs['counting_month'])
|
|
|
+ ->groupBy('owner_price_operation_id')->get();
|
|
|
+ }
|
|
|
+ return array($reports, $totalAmount, $totalFee,$owner_price_operation_fees);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -116,7 +116,7 @@ class OwnerStoreFeeReportService
|
|
|
public function getSql($owner_id, $counting_month): Builder
|
|
|
{
|
|
|
return OwnerStoreFeeReport::query()
|
|
|
- ->with('unit:id,name')
|
|
|
+ ->with(['unit:id,name'])
|
|
|
->where('owner_id', $owner_id)
|
|
|
->where('counting_month', $counting_month);
|
|
|
}
|