CaiWuXiTong/modules/EcommerceFinance/View/BillOffsetPageData.php
苏木 f2e8396007 账单冲减子页面改为复用订单售后费用明细同源数据
- BillOffsetPageData 注入 OrderDataPageData,page() 改为调用 afterSales(),使账单冲减子页面与订单售后费用明细页同源取数。
- 子页面按 账单冲减.xlsx 表头展示 9 列:内部订单号、线上订单号、店铺名称、店铺编码、商品编码、款式编码、店铺商品编码、店铺款式编码、500112冲减收入。
- 新增查询、重置与“导出当前页”按钮(沿用售后页前端 CSV 导出逻辑),并展示本页 500112 冲减收入合计。
- 500112 列本地镜像暂为 null,接入真实科目来源后自动填充,无需改模板。
2026-09-08 17:33:17 +08:00

77 lines
2.4 KiB
PHP

<?php
namespace Modules\EcommerceFinance\View;
use Illuminate\Pagination\Paginator;
use Modules\EcommerceFinance\View\OrderDataPageData;
use Throwable;
class BillOffsetPageData
{
public function __construct(private readonly OrderDataPageData $orderData)
{
}
/** @return array<string,mixed> */
public function page(): array
{
$filters = [
'from' => $this->date(request('from')) ?: now()->subDays(6)->toDateString(),
'to' => $this->date(request('to')) ?: now()->toDateString(),
'order_no' => $this->text(request('order_no')),
'shop_name' => $this->text(request('shop_name')),
'sku_id' => $this->text(request('sku_id')),
];
try {
$data = $this->orderData->afterSales();
} catch (Throwable $exception) {
report($exception);
$rows = new Paginator([], 25, 1, [
'path' => request()->url(),
'query' => request()->except('page'),
]);
return [
'view' => 'business.pages.order-data.bill-offset',
'billOffsetRows' => $rows,
'billOffsetFilters' => $filters,
'billOffsetError' => '订单售后费用数据暂时无法读取,请稍后重试。',
'billOffsetStatus' => null,
'billOffsetPageAmount' => 0.0,
];
}
$rows = $data['orderDataRows'];
$pageAmount = 0.0;
foreach (($rows->items() ?? []) as $item) {
$pageAmount += (float) (data_get($item, 'account_500112') ?? 0);
}
return [
'view' => 'business.pages.order-data.bill-offset',
'billOffsetRows' => $rows,
'billOffsetFilters' => $data['orderDataFilters'] ?? $filters,
'billOffsetError' => $data['orderDataError'] ?? null,
'billOffsetStatus' => data_get($data, 'orderDataStatus.X-Caiwu-Data-Status'),
'billOffsetPageAmount' => $pageAmount,
];
}
private function text(mixed $value): string
{
return mb_substr(trim((string) $value), 0, 100);
}
private function date(mixed $value): string
{
$value = trim((string) $value);
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $value, $matches) !== 1) {
return '';
}
return checkdate((int) $matches[2], (int) $matches[3], (int) $matches[1]) ? $value : '';
}
}