36 lines
1.9 KiB
PHP
36 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\View;
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\EcommerceFinance\Services\AccessoryReshipCourierStore;
|
|
|
|
class AccessoryReshipConfigPageData
|
|
{
|
|
public function __construct(private readonly AccessoryReshipCourierStore $store) {}
|
|
|
|
public function filters(): array
|
|
{
|
|
$text = static fn (string $key): string => mb_substr(trim((string) request()->query($key, '')), 0, 191);
|
|
$filters = ['courier_name' => $text('courier_name'), 'creator' => $text('creator'), 'created_from' => $text('created_from'), 'created_to' => $text('created_to'), 'deleted_status' => $text('deleted_status') ?: 'active'];
|
|
foreach (['created_from', 'created_to'] as $key) {
|
|
$value = $filters[$key];
|
|
abort_if($value !== '' && (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) || !checkdate((int) substr($value, 5, 2), (int) substr($value, 8, 2), (int) substr($value, 0, 4))), 422, '请选择有效创建日期。');
|
|
}
|
|
abort_if($filters['created_from'] !== '' && $filters['created_to'] !== '' && $filters['created_from'] > $filters['created_to'], 422, '结束日期不能早于开始日期。');
|
|
return $filters;
|
|
}
|
|
|
|
public function page(): array
|
|
{
|
|
$companyId = (int) company_id();
|
|
$filters = $this->filters();
|
|
$page = max(1, (int) request('page', 1));
|
|
$rows = $this->store->filtered($companyId, $filters)->paginate(20, ['*'], 'page', $page)->withQueryString();
|
|
$events = DB::table(AccessoryReshipCourierStore::EVENTS)->where('company_id', $companyId)->orderByDesc('id')->paginate(20, ['*'], 'event_page')->withQueryString();
|
|
return ['view' => 'business.pages.courier-payables.accessory-reship-deductions', 'reshipView' => 'config', 'configRows' => $rows, 'configEvents' => $events, 'configFilters' => $filters];
|
|
}
|
|
}
|