|
|
@@ -3,11 +3,14 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Owner;
|
|
|
-use App\OwnerLogisticFeeReport;
|
|
|
-use App\Services\common\ExportService;
|
|
|
+use App\OwnerBillReport;
|
|
|
+use App\OwnerBillReportArchive;
|
|
|
+use App\Services\OwnerBillReportArchiveService;
|
|
|
use App\Services\OwnerLogisticFeeReportService;
|
|
|
use App\Services\UserService;
|
|
|
+use Illuminate\Http\RedirectResponse;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
use Oursdreams\Export\Export;
|
|
|
|
|
|
class OwnerLogisticFeeReportController extends Controller
|
|
|
@@ -17,6 +20,9 @@ class OwnerLogisticFeeReportController extends Controller
|
|
|
/* @var UserService $userService */
|
|
|
private $userService;
|
|
|
|
|
|
+ /** @var $archiveService OwnerBillReportArchiveService */
|
|
|
+ private $archiveService;
|
|
|
+
|
|
|
/**
|
|
|
* OwnerLogisticFeeReportController constructor.
|
|
|
*/
|
|
|
@@ -32,32 +38,59 @@ class OwnerLogisticFeeReportController extends Controller
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
$paginateParams = $request->input();
|
|
|
- list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
|
|
|
- $reports = $this->service->getRecordPagination($owner_id, $date, $paginateParams);
|
|
|
- $recordTotal = $this->service->getRecordTotal($owner_id, $date);
|
|
|
- $owner = Owner::query()->selectRaw("name")->find($owner_id);
|
|
|
+ list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
|
|
|
+ list($reports, $recordTotal) = $this->service->get([
|
|
|
+ 'owner_id' => $owner_id,
|
|
|
+ 'counting_month' => $counting_month,
|
|
|
+ 'paginateParams' => $paginateParams,
|
|
|
+ 'type' => $this->service::TYPE,
|
|
|
+ ]);
|
|
|
+ $reportPaginator = null;
|
|
|
+ if ($reports instanceof LengthAwarePaginator) {
|
|
|
+ $reportPaginator = $reports;
|
|
|
+ $reports = collect($reportPaginator->items());
|
|
|
+ }
|
|
|
+ $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
|
|
|
$owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
|
|
|
- return view('finance.settlementBills.logisticFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners', 'owner'));
|
|
|
+ $this->archiveService = app('OwnerBillReportArchiveService');
|
|
|
+ $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, OwnerBillReportArchive::$enums['type']['快递费-合计']);
|
|
|
+
|
|
|
+ $request = $request->all();
|
|
|
+ $request['year'] = \Carbon\Carbon::parse($counting_month)->year;
|
|
|
+ $request['month'] = \Carbon\Carbon::parse($counting_month)->month;
|
|
|
+ $request = collect($request);
|
|
|
+ return view('finance.settlementBills.logisticFee.report.index', compact('reports', 'recordTotal', 'paginateParams', 'owners', 'owner', 'isArchived', 'request', 'reportPaginator'));
|
|
|
}
|
|
|
|
|
|
public function export(Request $request)
|
|
|
{
|
|
|
- list($permittingOwnerIds, $date, $owner_id) = $this->getRequestParams($request);
|
|
|
- $query = $this->service->getSql($owner_id, $date);
|
|
|
- if (!$request->exists('checkAllSign')) {
|
|
|
- $query->whereIn('id', explode(',', $request['data']));
|
|
|
+ $this->archiveService = app('OwnerBillReportArchiveService');
|
|
|
+ list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
|
|
|
+ if ($this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE) == 1) {
|
|
|
+ //已确认账单导出
|
|
|
+ list($reports, $recordTotal) = $this->service->get([
|
|
|
+ 'owner_id' => $owner_id,
|
|
|
+ 'counting_month' => $counting_month,
|
|
|
+ 'type' => $this->service::TYPE,
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ //未确认账单导出
|
|
|
+ $query = $this->service->getSql($owner_id, $counting_month);
|
|
|
+ if (!$request->exists('checkAllSign')) {
|
|
|
+ $query->whereIn('id', explode(',', $request['data']));
|
|
|
+ }
|
|
|
+ $reports = $query->get();
|
|
|
}
|
|
|
- $reports = $query->get();
|
|
|
$json = [];
|
|
|
foreach ($reports as $report) {
|
|
|
$json[] = [
|
|
|
- $report->logistic->name ?? '',
|
|
|
- $report->province,
|
|
|
- $report->initial_weight,
|
|
|
- $report->initial_amount,
|
|
|
- $report->additional_weight,
|
|
|
- $report->additional_amount,
|
|
|
- $report->fee,
|
|
|
+ $report['logistic']['name'] ?? '',
|
|
|
+ $report['province'],
|
|
|
+ $report['initial_weight'],
|
|
|
+ $report['initial_amount'],
|
|
|
+ $report['additional_weight'],
|
|
|
+ $report['additional_amount'],
|
|
|
+ $report['fee'],
|
|
|
];
|
|
|
}
|
|
|
$row = ['快递公司', '地区', '首重', '订单数', '续重', '续重合计', '(省份)合计'];
|
|
|
@@ -65,24 +98,60 @@ class OwnerLogisticFeeReportController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param Request $request
|
|
|
+ * @param $year
|
|
|
+ * @param $month
|
|
|
+ * @param $owner_id
|
|
|
* @return array
|
|
|
*/
|
|
|
- private function getRequestParams(Request $request): array
|
|
|
+ private function getRequestParams($year, $month, $owner_id): array
|
|
|
{
|
|
|
$this->service = app('OwnerLogisticFeeReportService');
|
|
|
$this->userService = app('UserService');
|
|
|
$permittingOwnerIds = $this->userService->getPermittingOwnerIds(auth()->user());
|
|
|
- if (is_null($request->year) || is_null($request->month)) {
|
|
|
- $date = now()->subMonth()->startOfMonth()->toDateString();
|
|
|
- } else {
|
|
|
- $date = $request->year . '-' . $request->month . '-' . '01';
|
|
|
+ if (is_null($year)) {
|
|
|
+ $year = now()->subMonth() ->year;
|
|
|
}
|
|
|
- if (is_null($request->owner_id)) {
|
|
|
+ if (is_null($month)) {
|
|
|
+ $month = now()->subMonth()->month;
|
|
|
+ }
|
|
|
+ $counting_month = $year . '-' . $month . '-' . '01';
|
|
|
+ if (is_null($owner_id)) {
|
|
|
$owner_id = $permittingOwnerIds[0];
|
|
|
- } else {
|
|
|
- $owner_id = $request->owner_id;
|
|
|
}
|
|
|
- return array($permittingOwnerIds, $date, $owner_id);
|
|
|
+ return array($permittingOwnerIds, $counting_month, $owner_id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认账单
|
|
|
+ * @param Request $request
|
|
|
+ * @return RedirectResponse
|
|
|
+ */
|
|
|
+ public function confirmBill(Request $request)
|
|
|
+ {
|
|
|
+ $this->service = app('OwnerLogisticFeeReportService');
|
|
|
+ $this->archiveService = app('OwnerBillReportArchiveService');
|
|
|
+ list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
|
|
|
+ $billReport = OwnerBillReport::query()
|
|
|
+ ->select('storage_fee', 'id')
|
|
|
+ ->where('owner_id', $owner_id)
|
|
|
+ ->where('counting_month', $counting_month)
|
|
|
+ ->firstOr(function () {
|
|
|
+ return new OwnerBillReport();
|
|
|
+ });
|
|
|
+ $reports = $this->service->getRecords($owner_id, $counting_month);
|
|
|
+ $recordTotal = $this->service->getRecordTotal($owner_id, $counting_month);
|
|
|
+ OwnerBillReportArchive::query()->create([
|
|
|
+ 'owner_bill_report_id' => $billReport->id ?? null,
|
|
|
+ 'owner_id' => $owner_id,
|
|
|
+ 'counting_mouth' => $counting_month,
|
|
|
+ 'type' => $this->service::TYPE,
|
|
|
+ 'archiver_id' => auth()->id(),
|
|
|
+ 'archived_at' => now(),
|
|
|
+ 'information' => [
|
|
|
+ 'reports' => $reports,
|
|
|
+ 'recordTotal' => $recordTotal,
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
+ return back()->with('success', '确认成功');
|
|
|
}
|
|
|
}
|