From 2353d8b73fa8490cfa17a0dcc9c52458d403a6ac Mon Sep 17 00:00:00 2001 From: yueyang <2495544247@qq.com> Date: Thu, 10 Sep 2026 10:38:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E8=B4=A2=E5=8A=A1?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=88=97=E8=AE=BE=E7=BD=AE=E4=B8=8E=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Business/Pages.php | 75 ++++++++++++++----- .../pages/partials/directory-table.blade.php | 20 ++++- .../finance-table-interactions.blade.php | 71 +++++++++++++++--- .../refunds/non-jingxi-refund-data.blade.php | 13 +++- .../small-payment-work-orders.blade.php | 17 ++++- resources/views/business/pages/show.blade.php | 4 +- .../Business/NonJingxiRefundPageTest.php | 28 +++++++ .../SmallPaymentWorkOrderPageTest.php | 28 +++++++ 8 files changed, 217 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index c58c2cb2..1b1108a2 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -986,6 +986,7 @@ class Pages extends Controller $this->nonJingxiRefunds->exportRows($filters), $filters, $redirectParameters, + $request->query('columns'), ); } catch (Throwable $exception) { report($exception); @@ -1018,16 +1019,16 @@ class Pages extends Controller ]; } - private function streamNonJingxiRefundCsv(iterable $rows, array $filters, array $redirectParameters) + private function streamNonJingxiRefundCsv(iterable $rows, array $filters, array $redirectParameters, mixed $requestedFields = null) { $columns = [ - ['label' => '序号/主键ID', 'field' => 'Id'], + ['label' => '序号/主键ID', 'field' => 'Id', 'identifier' => true], ['label' => '退款日期', 'field' => 'refundDate'], - ['label' => '售后单ID', 'field' => 'as_id'], - ['label' => '外部售后单号', 'field' => 'outer_as_id'], - ['label' => '订单ID', 'field' => 'o_id'], + ['label' => '售后单ID', 'field' => 'as_id', 'identifier' => true], + ['label' => '外部售后单号', 'field' => 'outer_as_id', 'identifier' => true], + ['label' => '订单ID', 'field' => 'o_id', 'identifier' => true], ['label' => '', 'field' => ''], - ['label' => '子订单ID', 'field' => 'so_id'], + ['label' => '子订单ID', 'field' => 'so_id', 'identifier' => true], ['label' => '类型', 'field' => 'type'], ['label' => '节点', 'field' => 'node'], ['label' => '是否自营', 'field' => 'isZC'], @@ -1036,10 +1037,10 @@ class Pages extends Controller ['label' => '责任部门', 'field' => 'responsibleDepartment'], ['label' => '退款总金额', 'field' => 'totalRefundMoney', 'number' => true], ['label' => '原始邮编', 'field' => 'originPostcode'], - ['label' => '店铺商品ID', 'field' => 'shop_i_id'], - ['label' => '店铺SKU编码', 'field' => 'shop_sku_id'], - ['label' => '商品ID', 'field' => 'i_id'], - ['label' => 'SKU编码', 'field' => 'sku_id'], + ['label' => '店铺商品ID', 'field' => 'shop_i_id', 'identifier' => true], + ['label' => '店铺SKU编码', 'field' => 'shop_sku_id', 'identifier' => true], + ['label' => '商品ID', 'field' => 'i_id', 'identifier' => true], + ['label' => 'SKU编码', 'field' => 'sku_id', 'identifier' => true], ['label' => '买家实付金额', 'field' => 'buyer_paid_amount', 'number' => true], ['label' => '数量', 'field' => 'qty', 'number' => true], ['label' => '商品单位成本', 'field' => 'unitCostGoods', 'number' => true], @@ -1055,6 +1056,7 @@ class Pages extends Controller ['label' => '创建记录/创建时间', 'field' => 'created'], ['label' => '确认日期', 'field' => 'confirm_date'], ]; + $columns = $this->filterExportColumns($columns, $requestedFields); $csv = null; @@ -1072,7 +1074,9 @@ class Pages extends Controller ? '' : (($column['number'] ?? false) ? data_get($row, $column['field']) - : $this->csvText(data_get($row, $column['field']))), + : (($column['identifier'] ?? false) + ? $this->csvIdentifier(data_get($row, $column['field'])) + : $this->csvText(data_get($row, $column['field'])))), $columns, )); } @@ -1178,6 +1182,7 @@ class Pages extends Controller $this->smallPaymentWorkOrders->exportRows($filters), $filters, $redirectParameters, + $request->query('columns'), ); } catch (Throwable $exception) { report($exception); @@ -1214,11 +1219,11 @@ class Pages extends Controller ]; } - private function streamSmallPaymentWorkOrderCsv(iterable $rows, array $filters, array $redirectParameters) + private function streamSmallPaymentWorkOrderCsv(iterable $rows, array $filters, array $redirectParameters, mixed $requestedFields = null) { $columns = [ - ['label' => '工单编号', 'field' => 'work_order_no'], - ['label' => '支付宝批次号', 'field' => 'alipay_batch_no'], + ['label' => '工单编号', 'field' => 'work_order_no', 'identifier' => true], + ['label' => '支付宝批次号', 'field' => 'alipay_batch_no', 'identifier' => true], ['label' => '工单状态', 'field' => 'work_order_status'], ['label' => '打款状态', 'field' => 'payment_status'], ['label' => '工单标题', 'field' => 'work_order_title'], @@ -1228,12 +1233,12 @@ class Pages extends Controller ['label' => '打款金额', 'field' => 'payment_amount', 'number' => true], ['label' => '催处理次数', 'field' => 'urging_count', 'number' => true], ['label' => '店铺名称', 'field' => 'shop_name'], - ['label' => '线上订单号', 'field' => 'online_order_no'], + ['label' => '线上订单号', 'field' => 'online_order_no', 'identifier' => true], ['label' => '买家账号', 'field' => 'buyer_account'], ['label' => '支付宝账号', 'field' => 'alipay_account'], ['label' => '支付宝姓名', 'field' => 'alipay_name'], - ['label' => '商品编码', 'field' => 'product_code'], - ['label' => 'SKU编码', 'field' => 'sku_code'], + ['label' => '商品编码', 'field' => 'product_code', 'identifier' => true], + ['label' => 'SKU编码', 'field' => 'sku_code', 'identifier' => true], ['label' => '平台', 'field' => 'platform'], ['label' => '实际已付金额', 'field' => 'actual_paid_amount', 'number' => true], ['label' => '支付时间', 'field' => 'payment_time'], @@ -1242,6 +1247,7 @@ class Pages extends Controller ['label' => '创建时间', 'field' => 'work_order_created_at'], ['label' => '完成时间', 'field' => 'completed_at'], ]; + $columns = $this->filterExportColumns($columns, $requestedFields); $csv = null; try { @@ -1256,7 +1262,9 @@ class Pages extends Controller fputcsv($csv, array_map( fn (array $column): mixed => ($column['number'] ?? false) ? data_get($row, $column['field']) - : $this->csvText(data_get($row, $column['field'])), + : (($column['identifier'] ?? false) + ? $this->csvIdentifier(data_get($row, $column['field'])) + : $this->csvText(data_get($row, $column['field']))), $columns, )); } @@ -2134,6 +2142,37 @@ class Pages extends Controller return preg_match('/^[=+\-@]/u', $text) === 1 ? "'" . $text : $text; } + /** + * Keep client-selected exports within the fields declared by the page. + * An omitted or invalid selection falls back to the complete safe schema. + * + * @param array $columns + * @return array + */ + private function filterExportColumns(array $columns, mixed $requestedFields): array + { + if (! is_string($requestedFields) || trim($requestedFields) === '') { + return $columns; + } + + $available = []; + foreach ($columns as $column) { + if ($column['field'] !== '') { + $available[$column['field']] = $column; + } + } + + $selected = []; + foreach (explode(',', $requestedFields) as $field) { + $field = trim($field); + if ($field !== '' && isset($available[$field])) { + $selected[$field] = $available[$field]; + } + } + + return $selected !== [] ? array_values($selected) : $columns; + } + /** * Export identifiers as text so Excel does not round or truncate long IDs. * Keep the formula-injection guard from csvText for values beginning with a diff --git a/resources/views/business/pages/partials/directory-table.blade.php b/resources/views/business/pages/partials/directory-table.blade.php index b84f83a6..70f37587 100644 --- a/resources/views/business/pages/partials/directory-table.blade.php +++ b/resources/views/business/pages/partials/directory-table.blade.php @@ -342,7 +342,15 @@ } -
+
@@ -444,7 +452,7 @@
- +