diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index b7e0073a..ab22e03b 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -2811,6 +2811,75 @@ class Pages extends Controller ]; } + /** + * 商品成本合计明细:与页面成本合计使用同一有效单价口径, + * 按发货仓库透视商品数量与商品成本。 + */ + public function productCostSummaryDetails(Request $request): \Illuminate\Http\JsonResponse + { + $month = trim((string) $request->query('month', '')); + if (preg_match('/^\d{4}-\d{2}$/', $month) !== 1) { + return response()->json(['message' => '请选择有效月份。'], 422); + } + + $filterValues = [ + 'platform' => trim((string) $request->query('platform', '')), + 'store_name' => trim((string) $request->query('store_name', '')), + 'online_order_no' => trim((string) $request->query('online_order_no', '')), + 'product_code' => trim((string) $request->query('product_code', '')), + 'warehouse_short_name' => trim((string) $request->query('warehouse_short_name', '')), + ]; + + $connection = (string) config('upstream_mirrors.connection', 'business_mirror'); + $query = DB::connection($connection) + ->table(self::PRODUCT_COST_TABLE) + ->where('report_month', $month . '-01') + ->whereNotNull('unit_price'); + + if ($filterValues['platform'] !== '') { + $query->where('platform', $filterValues['platform']); + } + foreach (['store_name', 'online_order_no', 'product_code'] as $column) { + if ($filterValues[$column] !== '') { + $query->where( + $column, + 'like', + '%' . addcslashes($filterValues[$column], '%_\\') . '%' + ); + } + } + if ($filterValues['warehouse_short_name'] !== '') { + $query->where('warehouse_short_name', $filterValues['warehouse_short_name']); + } + + $warehouseExpression = "COALESCE(NULLIF(warehouse, ''), '未填写发货仓库')"; + $rows = $query + ->selectRaw($warehouseExpression . ' as warehouse') + ->selectRaw('SUM(product_quantity) as product_quantity') + ->selectRaw('SUM(product_cost) as product_cost') + ->groupByRaw($warehouseExpression) + ->orderByDesc('product_cost') + ->orderBy('warehouse') + ->get() + ->map(static fn ($row): array => [ + 'warehouse' => (string) ($row->warehouse ?? '未填写发货仓库'), + 'quantity' => round((float) ($row->product_quantity ?? 0), 4), + 'cost' => round((float) ($row->product_cost ?? 0), 2), + ]) + ->values(); + + return response()->json([ + 'summary' => [ + 'warehouse_count' => $rows->count(), + 'quantity_total' => round((float) $rows->sum('quantity'), 4), + 'cost_total' => round((float) $rows->sum('cost'), 2), + ], + 'rows' => $rows, + ], 200, [ + 'Cache-Control' => 'private, no-store, max-age=0', + ]); + } + /** * 商品成本待核验明细:当前单价为空或仓库简称未匹配的行。 * 每次打开或刷新弹框都重新查询共享镜像,已修复的行会自然从结果中消失。 diff --git a/resources/views/business/pages/financial-operations/product-costs.blade.php b/resources/views/business/pages/financial-operations/product-costs.blade.php index ea6e30c2..fffc8604 100644 --- a/resources/views/business/pages/financial-operations/product-costs.blade.php +++ b/resources/views/business/pages/financial-operations/product-costs.blade.php @@ -22,13 +22,18 @@ : $formatted; }; $metricCards = [ - ['label' => '商品成本合计', 'value' => number_format((float) ($summary['cost_total'] ?? 0) / 10000, 2), 'unit' => '万'], + [ + 'label' => '商品成本合计', + 'value' => number_format((float) ($summary['cost_total'] ?? 0) / 10000, 2), + 'unit' => '万', + 'dialog' => 'cost_summary', + ], [ 'label' => '待核验成本', 'value' => number_format((int) ($summary['pending_rows'] ?? 0)), 'unit' => '行', 'tone' => 'warn', - 'dialog' => true, + 'dialog' => 'pending', ], ]; $tableColumns = [ @@ -49,6 +54,23 @@ ); $pendingDetailsUrl = route('business.financial-operations.product-costs.pending-details', $pendingQuery); $pendingExportUrl = route('business.financial-operations.product-costs.pending-details.export', $pendingQuery); + $costSummaryQuery = array_merge( + ['company_id' => company_id()], + request()->except([ + 'page', + 'per_page', + 'pending_page', + 'pending_type', + 'warehouse_keyword', + 'sort_by', + 'sort_direction', + ]), + ['month' => $filters['month'] ?? ''] + ); + $costSummaryDetailsUrl = route( + 'business.financial-operations.product-costs.summary-details', + $costSummaryQuery + ); @endphp
@@ -876,6 +898,135 @@ gap: .45rem; } + .product-cost-cost-summary-dialog { + width: min(56rem, calc(100vw - 2rem)); + } + + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table { + width: 100%; + min-width: 100%; + table-layout: fixed; + } + + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table th:first-child, + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table td:first-child { + width: 50%; + } + + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table th:nth-child(2), + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table td:nth-child(2) { + width: 20%; + } + + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table th:nth-child(3), + .product-cost-cost-summary-dialog .product-cost-pending-dialog__table td:nth-child(3) { + width: 30%; + } + + .product-cost-cost-summary-filter { + display: flex; + align-items: end; + gap: .5rem; + padding-bottom: .8rem; + } + + .product-cost-cost-summary-filter__field { + display: grid; + flex: 1 1 auto; + gap: .3rem; + min-width: 0; + } + + .product-cost-cost-summary-filter__field label { + color: var(--vip-content-muted, #595959); + font-size: .7rem; + font-weight: 500; + } + + .product-cost-cost-summary-filter__field input { + width: 100%; + height: 2rem; + min-width: 0; + padding: 0 .6rem; + border: 1px solid var(--vip-border, #d8d2c7); + border-radius: .5rem; + background: #fff; + color: var(--vip-content-ink, #171717); + font: inherit; + font-size: .72rem; + } + + .product-cost-cost-summary-filter__field input:focus { + border-color: var(--vip-content-accent-dark, #856632); + outline: none; + box-shadow: 0 0 0 3px rgba(133, 102, 50, .2); + } + + .product-cost-cost-summary-filter button { + display: inline-flex; + box-sizing: border-box; + height: 2rem; + align-items: center; + justify-content: center; + padding: 0 .75rem; + border: 1px solid var(--vip-border, #d8d2c7); + border-radius: .5rem; + background: #fff; + color: var(--vip-content-ink, #171717); + font: inherit; + font-size: .72rem; + cursor: pointer; + } + + .product-cost-cost-summary-filter button:hover { + border-color: var(--vip-content-accent-dark, #856632); + color: var(--vip-content-accent-dark, #856632); + } + + .product-cost-cost-summary-sort { + display: inline-flex; + align-items: center; + gap: .25rem; + padding: 0; + border: 0; + background: transparent; + color: inherit; + font: inherit; + font-weight: inherit; + cursor: pointer; + } + + .product-cost-cost-summary-sort:hover, + .product-cost-cost-summary-sort:focus-visible { + color: var(--vip-content-accent-dark, #856632); + } + + .product-cost-cost-summary-sort:focus-visible { + outline: 2px solid var(--vip-content-accent-dark, #856632); + outline-offset: 2px; + } + + .product-cost-cost-summary-sort__indicator { + min-width: .7rem; + color: var(--vip-content-muted, #595959); + font-size: .65rem; + } + + .product-cost-cost-summary-footer { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1rem; + padding-top: .75rem; + color: var(--vip-content-muted, #595959); + font-size: .72rem; + } + + .product-cost-cost-summary-footer strong { + color: var(--vip-content-ink, #171717); + font-variant-numeric: tabular-nums; + } + @media (max-width: 1100px) { .product-cost-filter-form { grid-template-columns: repeat(2, minmax(10rem, 1fr)); @@ -946,6 +1097,16 @@ .product-cost-pending-dialog__body { max-height: calc(100vh - 4rem); } + + .product-cost-cost-summary-filter, + .product-cost-cost-summary-footer { + align-items: stretch; + flex-direction: column; + } + + .product-cost-cost-summary-dialog .product-cost-pending-dialog__title { + flex: 0 0 auto; + } } @@ -1028,8 +1189,8 @@
@foreach ($metricCards as $card) - @php($opensDialog = ($card['dialog'] ?? false) === true) - @if ($opensDialog) + @php($dialog = $card['dialog'] ?? null) + @if ($dialog === 'pending')
查看明细 →
+ @elseif ($dialog === 'cost_summary') +
+ {{ $card['label'] }} + {{ $card['value'] }}{{ $card['unit'] }} + +
@else + +
+
+

商品成本合计明细

+ 按当前页面筛选条件统计,并按发货仓库透视商品数量与商品成本。 +
+
+ + +
+
+
+
+ + +
+
正在加载商品成本汇总…
+ + + +
+
+ +