From 205cdfe50e071eaff13ffd3e06b5df235ff1afc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E6=9C=A8?= <594326199@qq.com> Date: Sat, 21 Nov 2026 15:59:27 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BE=9B=E5=BA=94=E5=95=86=E8=B4=A7?= =?UTF-8?q?=E6=AC=BE=E9=A2=84=E4=BC=B0):=20=E6=8E=A5=E5=85=A5=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=85=A5=E5=BA=93=E4=B8=8E=E5=8F=98=E4=BB=B7=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=20(#1347)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 接入聚水潭采购入库明细、固定剔除规则和工作平台最新变价后采购价。 Co-authored-by: 苏木 <594326199@qq.com> Co-committed-by: 苏木 <594326199@qq.com> --- app/Http/Controllers/Business/Pages.php | 2 + config/business_data.php | 3 + config/upstream_mirrors.php | 48 +++ docs/上游业务镜像清单.md | 1 + .../SupplierPayableForecastRepository.php | 274 ++++++++++++++++++ .../View/SupplierPayableForecastPageData.php | 117 ++++++++ .../supplier-payable-forecast.blade.php | 268 ++++++++++++++++- .../Business/NegativeAlertPagesTest.php | 116 +++++++- .../SupplierPayableForecastRepositoryTest.php | 159 ++++++++++ 9 files changed, 972 insertions(+), 16 deletions(-) create mode 100644 modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php create mode 100644 modules/EcommerceFinance/View/SupplierPayableForecastPageData.php create mode 100644 tests/Unit/EcommerceFinance/SupplierPayableForecastRepositoryTest.php diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index e625f75e..79bb09b7 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -105,6 +105,7 @@ use Modules\EcommerceFinance\Services\SupplierFreeShippingStore; use Modules\EcommerceFinance\View\PlatformPromotionAccountPageData; use Modules\EcommerceFinance\View\OrderDataPageData; use Modules\EcommerceFinance\View\SupplierNegativeAlertPageData; +use Modules\EcommerceFinance\View\SupplierPayableForecastPageData; use RuntimeException; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -5469,6 +5470,7 @@ class Pages extends Controller if ($page === 'supplier-negative-alert') { return $tab === 'payable-forecast' ? ['view' => 'business.pages.negative-alerts.supplier-payable-forecast'] + + app(SupplierPayableForecastPageData::class)->page(request()) : app(SupplierNegativeAlertPageData::class)->page(); } diff --git a/config/business_data.php b/config/business_data.php index 82869b64..2c033b34 100644 --- a/config/business_data.php +++ b/config/business_data.php @@ -159,6 +159,9 @@ return [ 'jiansun.dbo.fys_supplierGoods_sttlement_purchase' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '货款采购对账'], 'jiansun.dbo.fys_supplierGoods_sttlement_sale' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '货款销售对账'], 'jiansun.dbo.pm_purchaseIn' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '采购入库'], + 'jiansun.dbo.jst_purchaseReceiving' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '供应商货款预估/货款明细'], + 'jiansun.dbo.jst_purchaseReceivingItem' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '供应商货款预估/货款明细'], + 'jiansun.dbo.pm_priceAdjustment_log' => ['role' => 'serving_fact', 'target_store' => 'mariadb', 'consumer' => '供应商货款预估/变价后采购价'], 'jiansun.dbo.js_supplier_View' => ['role' => 'dimension', 'target_store' => 'mariadb', 'consumer' => '供应商管理'], 'jiansun.dbo.js_supplier_contract_View' => ['role' => 'operational', 'target_store' => 'mariadb', 'consumer' => '供应商管理/合同信息'], 'jiansun.dbo.js_supplier_linkers' => ['role' => 'dimension', 'target_store' => 'mariadb', 'consumer' => '供应商管理/联系信息'], diff --git a/config/upstream_mirrors.php b/config/upstream_mirrors.php index 099fdb6b..23ab1cfe 100644 --- a/config/upstream_mirrors.php +++ b/config/upstream_mirrors.php @@ -906,6 +906,54 @@ return [ 'jiansun.dbo.fys_supplierGoods_sttlement_purchase' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_supplierGoods_sttlement_purchase', 'target' => 'js_supplier_goods_purchase', 'keys' => ['Id'], 'watermark' => 'createTime'], 'jiansun.dbo.fys_supplierGoods_sttlement_sale' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_supplierGoods_sttlement_sale', 'target' => 'js_supplier_goods_sale', 'keys' => ['Id'], 'watermark' => 'createTime'], 'jiansun.dbo.pm_purchaseIn' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'pm_purchaseIn', 'target' => 'js_pm_purchase_in', 'keys' => ['id'], 'watermark' => 'updateTime'], + // 供应商货款预估:聚水潭采购入库头表与明细,按入库日期从 2026-10-01 起接入。 + 'jiansun.dbo.jst_purchaseReceiving' => [ + 'source_key' => 'jiansun', + 'schema' => 'dbo', + 'object' => 'jst_purchaseReceiving', + 'target' => 'js_jst_purchase_receiving', + 'keys' => ['Id'], + 'watermark' => 'updateTime', + 'minimum_datetime' => ['column' => 'io_date', 'value' => '2026-10-01 00:00:00'], + 'full_reconcile_hours' => 168, + 'columns' => [ + 'Id', 'io_id', 'po_id', 'io_date', 'remark', 'warehouse', 'type', + 'supplier_name', 'supplier_id', 'logistics_company', 'status', + 'wms_co_name', 'created', 'updateTime', + ], + 'indexes' => [ + ['io_date', 'Id'], + ['po_id', 'Id'], + ['warehouse', 'io_date', 'Id'], + ['supplier_name', 'io_date', 'Id'], + ['updateTime', 'Id'], + ], + ], + 'jiansun.dbo.jst_purchaseReceivingItem' => [ + 'source_key' => 'jiansun', + 'schema' => 'dbo', + 'object' => 'jst_purchaseReceivingItem', + 'target' => 'js_jst_purchase_receiving_item', + 'keys' => ['Id'], + 'watermark' => null, + 'parent_minimum_datetime' => [ + 'column' => 'io_date', + 'value' => '2026-10-01 00:00:00', + 'parent_dataset' => 'jiansun.dbo.jst_purchaseReceiving', + 'child_key' => 'io_id', + 'parent_key' => 'io_id', + ], + 'full_reconcile_hours' => 168, + 'columns' => [ + 'Id', 'io_id', 'ioi_id', 'sku_id', 'i_id', 'name', 'qty', + 'cost_price', 'cost_amount', 'remark', 'tax_rate', 'unit', + ], + 'indexes' => [ + ['io_id', 'Id'], + ['sku_id', 'Id'], + ['i_id', 'Id'], + ], + ], // 工作平台采购价格:skuCode 对应 ops_jst_sku.sku_id。源表没有可靠更新时间, // 以 Id 稳定追加,页面按 effectTime 取当前已生效的最新价格。 'jiansun.dbo.pm_priceAdjustment' => [ diff --git a/docs/上游业务镜像清单.md b/docs/上游业务镜像清单.md index 61db10c5..70d4b607 100644 --- a/docs/上游业务镜像清单.md +++ b/docs/上游业务镜像清单.md @@ -112,6 +112,7 @@ | 板材 | `dbo.finance_boardDeduction`、`dbo.pm_plainPlateData`、`dbo.pm_boardPurchasePrice`、`dbo.pm_boardPriceChangeImport`、`dbo.pm_boardApplyDetail` | | 封边条 | `dbo.pm_edgeBandData`、`dbo.pm_edgeBandApplyDetail`、`dbo.pm_edgeBandProfitInfo`、`dbo.finance_edgeBandDeductio`、`dbo.pm_averageUnitPrice` | | 库存与货款对账 | `dbo.pm_boardInventoryDetail_snapshot`、`dbo.fys_supplierGoods_sttlement_purchase`、`dbo.fys_supplierGoods_sttlement_sale`、`dbo.pm_purchaseIn` | +| 供应商货款预估 | `dbo.jst_purchaseReceiving`(`io_date >= 2026-10-01`,`Id` 稳定键、`updateTime` 增量)与 `dbo.jst_purchaseReceivingItem`(按 `io_id` 关联父表,`Id` 稳定键,按父表日期下限断点同步);页面固定剔除仓库“配件单仓”、采购单号为空、供应商“虚拟/简尚送货”及商品编码 `DF-` 前缀。单价取 `dbo.pm_priceAdjustment_log` 同 SKU 最新 `priceType=1` 的 `afterPrice`,未匹配按 0 展示。 | | 采购单价 | `dbo.jst_purchase`、`dbo.jst_purchaseItem`(受控字段联表镜像,不复制其他采购业务字段) | | 工作平台采购价格 | `dbo.pm_priceAdjustment`(`Id` 稳定键;按 `skuCode` 匹配 `jst_sku.sku_id`,页面取当前已生效的最新 `purchasePrice` / `effectTime`) | | 快递资料 | `dbo.wp_express`、`dbo.wp_express_expNet`、`dbo.wp_express_account`、`dbo.wp_express_extension`。`wp_express.tradebody` 为合作合同乙方(合同主体),`signcom` 为甲方(签订公司),主资料列表与导出读取这两个原始镜像字段。协议签署选择快递后按确切名称带入唯一乙方主体,缺失或同名主体冲突时保留空值并提示核对,不以快递简称替代,也不改写已签归档合同。 | diff --git a/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php b/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php new file mode 100644 index 00000000..54fcabbe --- /dev/null +++ b/modules/EcommerceFinance/Repositories/SupplierPayableForecastRepository.php @@ -0,0 +1,274 @@ +connectionName = (string) config('upstream_mirrors.connection', 'business_mirror'); + $this->connection = $database->connection($this->connectionName); + } + + /** + * @return array{ + * ready:bool, + * code:string, + * initialized_at:?string, + * last_succeeded_at:?string, + * states:array + * } + */ + public function syncStatus(): array + { + $schema = Schema::connection($this->connectionName); + foreach ([self::HEAD_TABLE, self::ITEM_TABLE, self::PRICE_TABLE, 'business_mirror_table_states'] as $table) { + if (! $schema->hasTable($table)) { + return [ + 'ready' => false, + 'code' => 'unavailable', + 'initialized_at' => null, + 'last_succeeded_at' => null, + 'states' => [], + ]; + } + } + + $keys = [self::HEAD_DATASET, self::ITEM_DATASET, self::PRICE_DATASET]; + $rows = $this->connection->table('business_mirror_table_states') + ->whereIn('dataset_key', $keys) + ->get(['dataset_key', 'status', 'initial_completed_at', 'last_succeeded_at']) + ->keyBy('dataset_key'); + + $states = []; + $ready = $rows->count() === count($keys); + $initializedAt = null; + $lastSucceededAt = null; + + foreach ($keys as $key) { + $row = $rows->get($key); + $initialized = $row !== null && ($row->initial_completed_at ?? null) !== null; + $ready = $ready && $initialized; + $states[$key] = $initialized ? (string) ($row->status ?? 'ready') : (string) ($row->status ?? 'pending'); + if ($initialized) { + $completedAt = (string) $row->initial_completed_at; + if ($initializedAt === null || $completedAt > $initializedAt) { + $initializedAt = $completedAt; + } + } + if (($row->last_succeeded_at ?? null) !== null) { + $succeededAt = (string) $row->last_succeeded_at; + if ($lastSucceededAt === null || $succeededAt > $lastSucceededAt) { + $lastSucceededAt = $succeededAt; + } + } + } + + return [ + 'ready' => $ready, + 'code' => $ready ? 'ready' : ($rows->contains(static fn (object $row): bool => $row->status === 'running') + ? 'initializing' + : 'pending'), + 'initialized_at' => $initializedAt, + 'last_succeeded_at' => $lastSucceededAt, + 'states' => $states, + ]; + } + + /** + * @param array{date_from:string,date_to:string,keyword:string} $filters + * @return array{ + * total:int, + * quantity:float, + * supplier_count:int, + * rows:list>, + * page:int, + * per_page:int + * } + */ + public function goodsDetails(array $filters, int $page, int $perPage = 20): array + { + $query = $this->filteredGoodsQuery($filters); + $total = (clone $query)->count(); + $aggregate = (clone $query) + ->selectRaw('COALESCE(SUM(qty), 0) AS quantity, COUNT(DISTINCT supplier_name) AS supplier_count') + ->first(); + + $perPage = min(max($perPage, 1), 100); + $page = max($page, 1); + $sourceRows = (clone $query) + ->orderByDesc('h.io_date') + ->orderByDesc('h.Id') + ->orderByDesc('i.Id') + ->forPage($page, $perPage) + ->get([ + 'h.Id as receiving_id', + 'h.io_id', + 'h.po_id', + 'h.io_date', + 'h.remark as head_remark', + 'h.warehouse', + 'h.logistics_company', + 'h.status', + 'i.Id as item_id', + 'i.sku_id', + 'i.i_id', + 'i.name', + 'i.qty', + 'i.cost_price', + 'i.cost_amount', + 'i.remark as item_remark', + ]); + + $priceMap = $this->latestChangePrices( + $sourceRows->pluck('sku_id')->filter()->map(static fn (mixed $value): string => trim((string) $value))->unique()->values()->all() + ); + + $rows = $sourceRows->map( + fn (object $row): array => $this->formatGoodsRow($row, $priceMap->get($this->normalizeSku($row->sku_id))) + )->values()->all(); + + return [ + 'total' => $total, + 'quantity' => (float) ($aggregate->quantity ?? 0), + 'supplier_count' => (int) ($aggregate->supplier_count ?? 0), + 'rows' => $rows, + 'page' => $page, + 'per_page' => $perPage, + ]; + } + + /** + * @param array{date_from:string,date_to:string,keyword:string} $filters + */ + private function filteredGoodsQuery(array $filters): \Illuminate\Database\Query\Builder + { + $from = Carbon::parse($filters['date_from'] ?: self::DEFAULT_FROM)->startOfDay(); + $to = trim((string) ($filters['date_to'] ?? '')); + $keyword = trim((string) ($filters['keyword'] ?? '')); + + $query = $this->connection->table(self::HEAD_TABLE . ' as h') + ->join(self::ITEM_TABLE . ' as i', 'i.io_id', '=', 'h.io_id') + ->where('h.io_date', '>=', $from->format('Y-m-d H:i:s')) + ->whereRaw("TRIM(COALESCE(warehouse, '')) <> ?", ['配件单仓']) + ->whereRaw("NULLIF(TRIM(CAST(po_id AS CHAR)), '') IS NOT NULL") + ->whereRaw("TRIM(COALESCE(supplier_name, '')) NOT IN (?, ?)", ['虚拟', '简尚送货']) + ->whereRaw("TRIM(COALESCE(sku_id, '')) NOT LIKE ?", ['DF-%']); + + if ($to !== '') { + $query->where('h.io_date', '<', Carbon::parse($to)->addDay()->startOfDay()->format('Y-m-d H:i:s')); + } + + if ($keyword !== '') { + $like = '%' . $keyword . '%'; + $query->where(static function ($nested) use ($like): void { + foreach ([ + 'h.io_id', + 'h.po_id', + 'h.supplier_name', + 'h.warehouse', + 'i.sku_id', + 'i.i_id', + 'i.name', + ] as $column) { + $nested->orWhere($column, 'like', $like); + } + }); + } + + return $query; + } + + /** @param list $skuIds */ + private function latestChangePrices(array $skuIds): Collection + { + if ($skuIds === []) { + return collect(); + } + + return $this->connection->table(self::PRICE_TABLE) + ->whereIn('skucode', $skuIds) + ->whereRaw("TRIM(COALESCE(priceType, '')) = ?", ['1']) + ->whereNotNull('afterPrice') + ->orderByDesc('effectStartTime') + ->orderByDesc('Id') + ->get(['skucode', 'afterPrice', 'effectStartTime', 'Id']) + ->unique(fn (object $price): string => $this->normalizeSku($price->skucode)) + ->keyBy(fn (object $price): string => $this->normalizeSku($price->skucode)); + } + + /** @return array */ + private function formatGoodsRow(object $row, ?object $price): array + { + $occurredAt = Carbon::parse((string) $row->io_date); + $quantity = (float) ($row->qty ?? 0); + $afterPrice = $price?->afterPrice; + $unitPrice = $afterPrice === null ? 0.0 : (float) $afterPrice; + $amount = round($quantity * $unitPrice, 2); + $costPrice = $row->cost_price === null ? null : (float) $row->cost_price; + $costAmount = $row->cost_amount === null + ? ($costPrice === null ? null : round($quantity * $costPrice, 2)) + : (float) $row->cost_amount; + $remark = trim(implode(' ', array_filter([ + trim((string) ($row->head_remark ?? '')), + trim((string) ($row->item_remark ?? '')), + ]))); + + return [ + 'receivingId' => (int) $row->receiving_id, + 'itemId' => (int) $row->item_id, + 'month' => $occurredAt->format('Y-m'), + 'stockNo' => (string) ($row->io_id ?? ''), + 'purchaseNo' => (string) ($row->po_id ?? ''), + 'date' => $occurredAt->format('Y-m-d'), + 'supplier' => (string) ($row->supplier_name ?? ''), + 'skuCode' => (string) ($row->i_id ?? ''), + 'productCode' => (string) ($row->sku_id ?? ''), + 'skuName' => (string) ($row->name ?? ''), + 'qty' => $quantity, + 'unitPrice' => $unitPrice, + 'amount' => $amount, + 'guessUnitPrice' => $costPrice, + 'guessAmount' => $costAmount, + 'supplierGoodsCode' => '', + 'remark' => $remark, + 'warehouse' => (string) ($row->warehouse ?? ''), + 'expressName' => (string) ($row->logistics_company ?? ''), + 'expressNo' => '', + 'unsent' => '', + 'reconciler' => '', + 'priceMatched' => $afterPrice !== null, + 'priceEffectTime' => $price?->effectStartTime, + 'sourceStatus' => $row->status, + ]; + } + + private function normalizeSku(mixed $value): string + { + return mb_strtolower(trim((string) $value), 'UTF-8'); + } +} diff --git a/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php b/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php new file mode 100644 index 00000000..f75eda4d --- /dev/null +++ b/modules/EcommerceFinance/View/SupplierPayableForecastPageData.php @@ -0,0 +1,117 @@ + */ + public function page(Request $request): array + { + $activeView = in_array($request->query('forecast_view'), ['goods', 'returns', 'summary'], true) + ? (string) $request->query('forecast_view') + : 'goods'; + $filters = $this->goodsFilters($request); + $syncStatus = $this->repository->syncStatus(); + $result = [ + 'total' => 0, + 'quantity' => 0.0, + 'supplier_count' => 0, + 'rows' => [], + 'page' => max((int) $request->query('goods_page', 1), 1), + 'per_page' => 20, + ]; + + if ($syncStatus['ready']) { + $result = $this->repository->goodsDetails( + $filters, + max((int) $request->query('goods_page', 1), 1), + 20, + ); + } + + $paginationQuery = array_filter([ + 'goods_date_from' => $filters['date_from'] === SupplierPayableForecastRepository::DEFAULT_FROM + ? null + : $filters['date_from'], + 'goods_date_to' => $filters['date_to'] !== '' ? $filters['date_to'] : null, + 'goods_keyword' => $filters['keyword'] !== '' ? $filters['keyword'] : null, + ], static fn (mixed $value): bool => $value !== null && $value !== ''); + + $rows = new LengthAwarePaginator( + $result['rows'], + $result['total'], + $result['per_page'], + $result['page'], + [ + 'path' => $request->url(), + 'query' => $paginationQuery, + ], + ); + + return [ + 'activeForecastView' => $activeView, + 'goodsForecastFields' => $this->registry->fields( + PayablesFinalRegistry::SECTION_SUPPLIER, + 'payment-reconciliation', + ), + 'goodsForecastFilters' => $filters, + 'goodsForecastRows' => $rows, + 'goodsForecastSummary' => [ + 'quantity' => $result['quantity'], + 'supplier_count' => $result['supplier_count'], + 'matched_price_rows' => collect($result['rows'])->where('priceMatched', true)->count(), + 'missing_price_rows' => collect($result['rows'])->where('priceMatched', false)->count(), + ], + 'goodsForecastSyncStatus' => $syncStatus, + ]; + } + + /** @return array{date_from:string,date_to:string,keyword:string} */ + private function goodsFilters(Request $request): array + { + $minimum = Carbon::createFromFormat('!Y-m-d', SupplierPayableForecastRepository::DEFAULT_FROM); + $from = $this->validDate($request->query('goods_date_from')); + if ($from === null || $from->lt($minimum)) { + $from = $minimum; + } + + $to = $this->validDate($request->query('goods_date_to')); + if ($to !== null && $to->lt($from)) { + $to = $from->copy(); + } + + return [ + 'date_from' => $from->format('Y-m-d'), + 'date_to' => $to?->format('Y-m-d') ?? '', + 'keyword' => mb_substr(trim((string) $request->query('goods_keyword', '')), 0, 120), + ]; + } + + private function validDate(mixed $value): ?Carbon + { + if (! is_string($value) || preg_match('/^\d{4}-\d{2}-\d{2}$/D', $value) !== 1) { + return null; + } + + $date = Carbon::createFromFormat('!Y-m-d', $value); + $errors = Carbon::getLastErrors(); + + return $date !== false + && ($errors === false || ($errors['warning_count'] === 0 && $errors['error_count'] === 0)) + && $date->format('Y-m-d') === $value + ? $date + : null; + } +} diff --git a/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php b/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php index 2df4a8cc..8d7909b2 100644 --- a/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php +++ b/resources/views/business/pages/negative-alerts/supplier-payable-forecast.blade.php @@ -212,12 +212,142 @@ line-height: 1.7; } + .supplier-payable-forecast .npf-data-overview { + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: 9px; + } + + .supplier-payable-forecast .npf-data-metric { + display: grid; + gap: 3px; + min-width: 0; + padding: 10px 12px; + border: 1px solid #EEE8DC; + border-radius: 8px; + background: #FCFBF8; + } + + .supplier-payable-forecast .npf-data-metric span { + color: var(--npf-muted); + font-size: 11px; + } + + .supplier-payable-forecast .npf-data-metric strong { + overflow-wrap: anywhere; + font-size: 13px; + font-weight: 600; + font-variant-numeric: tabular-nums; + } + + .supplier-payable-forecast .npf-filter { + display: grid; + grid-template-columns: minmax(140px, .8fr) minmax(140px, .8fr) minmax(240px, 1.8fr) auto; + align-items: end; + gap: 10px; + padding: 12px; + border: 1px solid #EEE8DC; + border-radius: 9px; + background: #FCFBF8; + } + + .supplier-payable-forecast .npf-field { display: grid; gap: 4px; min-width: 0; } + .supplier-payable-forecast .npf-field span { color: var(--npf-muted); font-size: 11px; font-weight: 600; } + .supplier-payable-forecast .npf-field input { + width: 100%; + min-width: 0; + height: 34px; + padding: 0 9px; + border: 1px solid var(--npf-border); + border-radius: 8px; + background: #FFFFFF; + color: var(--npf-ink); + font-size: 12px; + } + + .supplier-payable-forecast .npf-field input:focus { + border-color: var(--npf-gold); + outline: 0; + box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.20); + } + + .supplier-payable-forecast .npf-filter-actions { display: flex; flex-wrap: wrap; gap: 7px; } + .supplier-payable-forecast .npf-button { + display: inline-flex; + min-height: 34px; + align-items: center; + justify-content: center; + padding: 0 12px; + border: 1px solid var(--npf-border); + border-radius: 8px; + background: #FFFFFF; + color: var(--npf-ink); + font-size: 12px; + font-weight: 600; + text-decoration: none; + cursor: pointer; + white-space: nowrap; + } + + .supplier-payable-forecast .npf-button:hover { border-color: var(--npf-gold); background: #FCFAF5; } + .supplier-payable-forecast .npf-button:focus-visible { outline: 0; box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.20); } + .supplier-payable-forecast .npf-button.is-primary { border-color: var(--npf-gold); background: var(--npf-gold); color: #FFFFFF; } + .supplier-payable-forecast .npf-button.is-primary:hover { border-color: #6A5129; background: #6A5129; } + + .supplier-payable-forecast .npf-table-shell { + max-width: 100%; + overflow: auto; + border: 1px solid var(--npf-border); + border-radius: 9px; + scrollbar-gutter: stable; + } + + .supplier-payable-forecast .npf-table { + width: max-content; + min-width: 100%; + border-collapse: collapse; + background: #FFFFFF; + font-size: 12px; + } + + .supplier-payable-forecast .npf-table th { + position: sticky; + top: 0; + z-index: 2; + padding: 9px 10px; + border-bottom: 1px solid var(--npf-border); + background: var(--npf-gold-soft); + color: #5B5343; + font-size: 11px; + font-weight: 600; + text-align: left; + white-space: nowrap; + } + + .supplier-payable-forecast .npf-table td { + padding: 9px 10px; + border-bottom: 1px solid #F0EBE2; + vertical-align: top; + white-space: nowrap; + } + + .supplier-payable-forecast .npf-table tr:last-child td { border-bottom: 0; } + .supplier-payable-forecast .npf-table tbody tr:hover td { background: #FCFAF5; } + .supplier-payable-forecast .npf-table .is-num { text-align: right; font-variant-numeric: tabular-nums; } + .supplier-payable-forecast .npf-price-note { display: block; margin-top: 2px; color: var(--npf-warning); font-size: 10px; } + .supplier-payable-forecast .npf-data-note { color: var(--npf-muted); font-size: 11px; line-height: 1.7; } + .supplier-payable-forecast .npf-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; color: var(--npf-muted); font-size: 11px; } + .supplier-payable-forecast .npf-pagination-links { display: flex; gap: 7px; } + @media (max-width: 760px) { .supplier-payable-forecast .npf-notice { margin-inline: 12px; } .supplier-payable-forecast .npf-tabs { padding-inline: 12px; } .supplier-payable-forecast .npf-panel { padding: 16px 14px; } .supplier-payable-forecast .npf-panel-head { display: grid; } .supplier-payable-forecast .npf-scope { grid-template-columns: minmax(0, 1fr); } + .supplier-payable-forecast .npf-data-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); } + .supplier-payable-forecast .npf-filter { grid-template-columns: minmax(0, 1fr); } + .supplier-payable-forecast .npf-filter-actions { grid-column: 1; } } @media (prefers-reduced-motion: reduce) { @@ -232,10 +362,18 @@

- 供应商货款预估口径待接入 - 待接入 + {{ $goodsForecastSyncStatus['ready'] ? '供应商货款明细已接入' : '供应商货款明细镜像初始化中' }} + + {{ $goodsForecastSyncStatus['ready'] ? '共享镜像' : ($goodsForecastSyncStatus['code'] === 'initializing' ? '同步中' : '待同步') }} + +

+

+ @if ($goodsForecastSyncStatus['ready']) + 采购入库数据与工作平台变价后价格已接入共享镜像;退货明细和汇总仍待接入。 + @else + 采购入库与工作平台价格数据源已确定,共享镜像完成首次同步后自动展示明细。 + @endif

-

页面结构已建立,待确认预估月份、供应商范围、货款统计口径及数据来源后接入真实数据。

@@ -295,20 +433,122 @@ 货款明细 -

按供应商查看当月入库与代发明细;接入后支持明细查询、分页和导出。

+

采购入库数据从 2026-10-01 起展示,按供应商应付(终版)货款对账表头输出,并匹配工作平台最新变价后采购价。

- 数据待接入 + {{ $goodsForecastSyncStatus['ready'] ? '数据已接入' : '数据待同步' }} -
-
业务范围当月入库 / 当月代发
-
核对字段单号、商品、数量、单价、金额
-
页面状态待接入
-
-
- - 货款明细待接入 - 接入后将在这里展示入库厂家的采购单号、代发厂家的快递单号,以及未定价商品的明细。 + +
+
+ 筛选结果 + {{ number_format($goodsForecastRows->total()) }} 行 +
+
+ 数量合计 + {{ number_format($goodsForecastSummary['quantity'], 2) }} +
+
+ 供应商数 + {{ number_format($goodsForecastSummary['supplier_count']) }} +
+
+ 本页匹配变价 + {{ number_format($goodsForecastSummary['matched_price_rows']) }} / {{ $goodsForecastRows->count() }} +
+ +
+ + + + +
+ + 重置 +
+
+ + @if (! $goodsForecastSyncStatus['ready']) +
+ + 采购入库共享镜像尚未就绪 + 首次同步完成前不会展示第一页或局部数据,避免把不完整结果误认为全量。 +
+ @elseif ($goodsForecastRows->isEmpty()) +
+ + 没有符合当前条件的货款明细 + 可调整入库日期或关键字后重新查询。 +
+ @else +
+ + + + @foreach ($goodsForecastFields as $field) + + @endforeach + + + + @foreach ($goodsForecastRows as $row) + + @foreach ($goodsForecastFields as $key => $field) + @php($value = $row[$key] ?? null) + + @endforeach + + @endforeach + +
$field['type'] === 'number'])>{{ $field['label'] }}
$field['type'] === 'number'])> + @if ($field['type'] === 'number') + @if ($key === 'qty') + {{ number_format((float) $value, 2) }} + @else + {{ number_format((float) ($value ?? 0), 2) }} + @endif + @if ($key === 'unitPrice' && ! ($row['priceMatched'] ?? false)) + 未匹配变价,按 0 计 + @endif + @else + {{ $value !== null && $value !== '' ? $value : '—' }} + @endif +
+
+ +
+ + 第 {{ $goodsForecastRows->currentPage() }} / {{ $goodsForecastRows->lastPage() }} 页, + 每页 {{ $goodsForecastRows->perPage() }} 行;最近同步 + {{ $goodsForecastSyncStatus['last_succeeded_at'] ?? '—' }} + + @if ($goodsForecastRows->lastPage() > 1) + + @endif +
+ +
+ 固定剔除:仓库“配件单仓”、采购单号为空、供应商“虚拟/简尚送货”、商品编码以“DF-”开头。 + 单价取工作平台 pm_priceAdjustment_log 中该商品最新一条 priceType=1 的变价后价格; + 预估单价和预估金额取聚水潭采购入库明细的成本价与成本金额。 +
+ @endif
assertOk() ->assertSeeText('供应商负数预警') ->assertSeeText('供应商货款预估') - ->assertSeeText('供应商货款预估口径待接入') + ->assertSeeText('供应商货款明细镜像初始化中') + ->assertSeeText('采购入库共享镜像尚未就绪') ->assertSeeText('供应商货款预估数据待接入') ->assertSeeText('货款明细') ->assertSeeText('退货明细') @@ -275,7 +280,7 @@ class NegativeAlertPagesTest extends FeatureTestCase 'forecast_view' => 'returns', ])) ->assertOk() - ->assertSeeText('入库与代发明细') + ->assertSeeText('采购入库数据') ->assertSeeText('关联维度') ->assertSeeText('余额口径'); @@ -364,6 +369,113 @@ class NegativeAlertPagesTest extends FeatureTestCase ->assertRedirect(); } + public function test_goods_details_render_payment_reconciliation_headers_from_shared_mirror(): void + { + $this->createSupplierPayableForecastTables(); + $now = now(); + DB::connection('business_mirror')->table('business_mirror_table_states')->insert([ + ['dataset_key' => SupplierPayableForecastRepository::HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ['dataset_key' => SupplierPayableForecastRepository::ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ['dataset_key' => SupplierPayableForecastRepository::PRICE_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([ + 'Id' => 1, + 'io_id' => 'IN-20261001', + 'po_id' => 20261001, + 'io_date' => '2026-10-01 10:00:00', + 'warehouse' => '简尚-崔桥工厂仓进货仓', + 'supplier_name' => '测试供应商', + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([ + 'Id' => 1, + 'io_id' => 'IN-20261001', + 'ioi_id' => 'ITEM-1', + 'sku_id' => 'SKU-20261001', + 'i_id' => 'STYLE-20261001', + 'name' => '测试商品', + 'qty' => 2, + 'cost_price' => 10, + 'cost_amount' => 20, + ]); + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([ + 'Id' => 1, + 'skucode' => 'SKU-20261001', + 'priceType' => '1', + 'afterPrice' => 12, + 'effectStartTime' => '2026-10-01 08:00:00', + ]); + + $response = $this->loginAs()->get(route('business.pages.show', [ + 'section' => 'negative-alerts', + 'page' => 'supplier-negative-alert', + 'tab' => 'payable-forecast', + ]))->assertOk() + ->assertSeeText('供应商货款明细已接入') + ->assertSeeText('IN-20261001') + ->assertSeeText('20261001') + ->assertSeeText('STYLE-20261001') + ->assertSeeText('SKU-20261001') + ->assertSeeText('24.00'); + + $html = (string) $response->getContent(); + $tableStart = strpos($html, '', $tableStart); + $this->assertNotFalse($tableStart); + $this->assertNotFalse($tableEnd); + preg_match_all('/]*>(.*?)<\/th>/s', substr($html, $tableStart, $tableEnd - $tableStart), $headers); + $labels = array_map( + static fn (string $label): string => trim(html_entity_decode(strip_tags($label), ENT_QUOTES | ENT_HTML5, 'UTF-8')), + $headers[1], + ); + $this->assertSame([ + '月份', '入库单号', '采购单号', '日期', '供应商', '货号', '商品编码', '规格名称', + '数量', '单价', '金额', '预估单价', '预估金额', '供应商商品编码', '备注', + '仓库名称', '快递名称', '快递单号', '未发出', '对账人', + ], $labels); + } + + private function createSupplierPayableForecastTables(): void + { + $schema = Schema::connection('business_mirror'); + $schema->create('business_mirror_table_states', function (Blueprint $table): void { + $table->id(); + $table->string('dataset_key')->unique(); + $table->string('status', 32); + $table->dateTime('initial_completed_at')->nullable(); + $table->dateTime('last_succeeded_at')->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::HEAD_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('io_id', 100); + $table->unsignedBigInteger('po_id')->nullable(); + $table->dateTime('io_date'); + $table->text('remark')->nullable(); + $table->string('warehouse', 255)->nullable(); + $table->string('logistics_company', 255)->nullable(); + $table->string('status', 50)->nullable(); + $table->string('supplier_name', 255)->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::ITEM_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('io_id', 100); + $table->string('ioi_id', 100)->nullable(); + $table->string('sku_id', 100)->nullable(); + $table->string('i_id', 100)->nullable(); + $table->string('name', 255)->nullable(); + $table->integer('qty')->nullable(); + $table->decimal('cost_price', 18, 2)->nullable(); + $table->decimal('cost_amount', 18, 2)->nullable(); + $table->text('remark')->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::PRICE_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('skucode', 100)->nullable(); + $table->string('priceType', 20)->nullable(); + $table->decimal('afterPrice', 18, 2)->nullable(); + $table->dateTime('effectStartTime')->nullable(); + }); + } + private function saveSupplierPayable( string $key, string $supplier, diff --git a/tests/Unit/EcommerceFinance/SupplierPayableForecastRepositoryTest.php b/tests/Unit/EcommerceFinance/SupplierPayableForecastRepositoryTest.php new file mode 100644 index 00000000..e596ec23 --- /dev/null +++ b/tests/Unit/EcommerceFinance/SupplierPayableForecastRepositoryTest.php @@ -0,0 +1,159 @@ +createTables(); + $this->seedRows(); + + $result = app(SupplierPayableForecastRepository::class)->goodsDetails([ + 'date_from' => '2026-10-01', + 'date_to' => '', + 'keyword' => '', + ], 1); + + $this->assertSame(2, $result['total']); + $this->assertSame(3.0, $result['quantity']); + $this->assertSame(2, $result['supplier_count']); + $this->assertSame(['SKU-B', 'SKU-A'], array_column($result['rows'], 'productCode')); + + $priced = collect($result['rows'])->firstWhere('productCode', 'SKU-A'); + $this->assertSame('STYLE-A', $priced['skuCode']); + $this->assertSame(2.0, $priced['qty']); + $this->assertSame(12.0, $priced['unitPrice']); + $this->assertSame(24.0, $priced['amount']); + $this->assertSame(10.0, $priced['guessUnitPrice']); + $this->assertSame(20.0, $priced['guessAmount']); + $this->assertTrue($priced['priceMatched']); + + $unpriced = collect($result['rows'])->firstWhere('productCode', 'SKU-B'); + $this->assertSame(0.0, $unpriced['unitPrice']); + $this->assertSame(0.0, $unpriced['amount']); + $this->assertSame(6.0, $unpriced['guessAmount']); + $this->assertFalse($unpriced['priceMatched']); + + $keyword = app(SupplierPayableForecastRepository::class)->goodsDetails([ + 'date_from' => '2026-10-01', + 'date_to' => '', + 'keyword' => 'SKU-A', + ], 1); + $this->assertSame(1, $keyword['total']); + $this->assertSame('SKU-A', $keyword['rows'][0]['productCode']); + } + + private function createTables(): void + { + $schema = Schema::connection('business_mirror'); + $schema->create('business_mirror_table_states', function (Blueprint $table): void { + $table->id(); + $table->string('dataset_key')->unique(); + $table->string('status', 32); + $table->dateTime('initial_completed_at')->nullable(); + $table->dateTime('last_succeeded_at')->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::HEAD_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('io_id', 100); + $table->unsignedBigInteger('po_id')->nullable(); + $table->dateTime('io_date'); + $table->text('remark')->nullable(); + $table->string('warehouse', 255)->nullable(); + $table->string('logistics_company', 255)->nullable(); + $table->string('status', 50)->nullable(); + $table->string('supplier_name', 255)->nullable(); + $table->dateTime('created')->nullable(); + $table->dateTime('updateTime')->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::ITEM_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('io_id', 100); + $table->string('ioi_id', 100)->nullable(); + $table->string('sku_id', 100)->nullable(); + $table->string('i_id', 100)->nullable(); + $table->string('name', 255)->nullable(); + $table->integer('qty')->nullable(); + $table->decimal('cost_price', 18, 2)->nullable(); + $table->decimal('cost_amount', 18, 2)->nullable(); + $table->text('remark')->nullable(); + $table->decimal('tax_rate', 8, 2)->nullable(); + $table->string('unit', 50)->nullable(); + }); + $schema->create(SupplierPayableForecastRepository::PRICE_TABLE, function (Blueprint $table): void { + $table->bigIncrements('Id'); + $table->string('skucode', 100)->nullable(); + $table->string('priceType', 20)->nullable(); + $table->decimal('afterPrice', 18, 2)->nullable(); + $table->dateTime('effectStartTime')->nullable(); + }); + } + + private function seedRows(): void + { + $now = now(); + DB::connection('business_mirror')->table('business_mirror_table_states')->insert([ + ['dataset_key' => SupplierPayableForecastRepository::HEAD_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ['dataset_key' => SupplierPayableForecastRepository::ITEM_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ['dataset_key' => SupplierPayableForecastRepository::PRICE_DATASET, 'status' => 'succeeded', 'initial_completed_at' => $now, 'last_succeeded_at' => $now], + ]); + + $heads = [ + [1, 'IN-1', 101, '2026-10-02 09:00:00', '正常仓', '供应商甲'], + [2, 'IN-2', 102, '2026-10-03 09:00:00', '正常仓', '供应商乙'], + [3, 'IN-OLD', 103, '2026-09-30 09:00:00', '正常仓', '供应商甲'], + [4, 'IN-ACCESSORY', 104, '2026-10-04 09:00:00', '配件单仓', '供应商甲'], + [5, 'IN-BLANK-PO', null, '2026-10-05 09:00:00', '正常仓', '供应商甲'], + [6, 'IN-VIRTUAL', 106, '2026-10-06 09:00:00', '正常仓', '虚拟'], + [7, 'IN-DELIVERY', 107, '2026-10-07 09:00:00', '正常仓', '简尚送货'], + [8, 'IN-DF', 108, '2026-10-08 09:00:00', '正常仓', '供应商甲'], + ]; + foreach ($heads as [$id, $ioId, $poId, $date, $warehouse, $supplier]) { + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::HEAD_TABLE)->insert([ + 'Id' => $id, + 'io_id' => $ioId, + 'po_id' => $poId, + 'io_date' => $date, + 'warehouse' => $warehouse, + 'supplier_name' => $supplier, + ]); + } + + $items = [ + [1, 'IN-1', 'SKU-A', 'STYLE-A', 2, 10], + [2, 'IN-2', 'SKU-B', 'STYLE-B', 1, 6], + [3, 'IN-OLD', 'SKU-A', 'STYLE-A', 9, 10], + [4, 'IN-ACCESSORY', 'SKU-C', 'STYLE-C', 1, 10], + [5, 'IN-BLANK-PO', 'SKU-D', 'STYLE-D', 1, 10], + [6, 'IN-VIRTUAL', 'SKU-E', 'STYLE-E', 1, 10], + [7, 'IN-DELIVERY', 'SKU-F', 'STYLE-F', 1, 10], + [8, 'IN-DF', 'DF-SKU', 'DF-STYLE', 1, 10], + ]; + foreach ($items as [$id, $ioId, $skuId, $styleId, $qty, $costPrice]) { + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::ITEM_TABLE)->insert([ + 'Id' => $id, + 'io_id' => $ioId, + 'ioi_id' => 'ITEM-' . $id, + 'sku_id' => $skuId, + 'i_id' => $styleId, + 'name' => $styleId . ' 商品', + 'qty' => $qty, + 'cost_price' => $costPrice, + 'cost_amount' => $qty * $costPrice, + ]); + } + + DB::connection('business_mirror')->table(SupplierPayableForecastRepository::PRICE_TABLE)->insert([ + ['Id' => 1, 'skucode' => 'SKU-A', 'priceType' => '1', 'afterPrice' => 8, 'effectStartTime' => '2026-09-01 00:00:00'], + ['Id' => 2, 'skucode' => 'SKU-A', 'priceType' => '1', 'afterPrice' => 12, 'effectStartTime' => '2026-10-10 00:00:00'], + ['Id' => 3, 'skucode' => 'SKU-A', 'priceType' => '0', 'afterPrice' => 99, 'effectStartTime' => '2026-10-12 00:00:00'], + ]); + } +}