From 2e3468408e19917688819a3fe6225764ad036267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Wed, 21 Oct 2026 11:49:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AE=9E=E7=89=A9=E5=95=86=E5=93=81):=20?= =?UTF-8?q?=E8=AD=A6=E6=88=92=E5=BA=93=E5=AD=98=E6=8C=89=20SKU=20=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E4=BD=8E=E4=BA=8E=E7=B3=BB=E7=BB=9F=E8=AD=A6=E6=88=92?= =?UTF-8?q?=E5=80=BC=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 列表 tab 与头部统计共用 SKU 子查询(启用 SKU 任一低于 store_stock 配置即命中),原实现与出售中计数相同不含库存条件 --- .../normal/service/ProductServices.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/modules/product/normal/service/ProductServices.php b/backend/modules/product/normal/service/ProductServices.php index 41e1bd101..37499f331 100644 --- a/backend/modules/product/normal/service/ProductServices.php +++ b/backend/modules/product/normal/service/ProductServices.php @@ -388,6 +388,7 @@ class ProductServices break; case '4': // 警戒库存 $query->where('is_show', 1)->where('is_del', 0); + $this->applyWarningStockFilter($query); break; case '5': // 回收站 $query->where('is_del', 1); @@ -465,15 +466,39 @@ class ProductServices { $base = $this->centerDao->search()->where('product_type', 'normal'); + $warningBase = (clone $base)->where('is_show', 1)->where('is_del', 0); + $this->applyWarningStockFilter($warningBase); + return [ ['type' => 1, 'name' => '出售中的商品', 'count' => (clone $base)->where('is_show', 1)->where('is_del', 0)->count()], ['type' => 2, 'name' => '仓库中的商品', 'count' => (clone $base)->where('is_show', 0)->where('is_del', 0)->count()], ['type' => 3, 'name' => '已售馨的商品', 'count' => (clone $base)->where('is_show', 1)->where('is_del', 0)->where('stock', 0)->count()], - ['type' => 4, 'name' => '警戒库存商品', 'count' => (clone $base)->where('is_show', 1)->where('is_del', 0)->count()], + ['type' => 4, 'name' => '警戒库存商品', 'count' => $warningBase->count()], ['type' => 5, 'name' => '回收站的商品', 'count' => (clone $base)->where('is_del', 1)->count()], ]; } + /** + * 按 SKU 库存筛选警戒库存商品。 + * 只有存在启用 SKU 且至少一个 SKU 库存低于系统警戒值的商品才命中。 + * @param mixed $query + * @return void + */ + protected function applyWarningStockFilter($query): void + { + $warningStock = (int)sys_config('store_stock'); + if ($warningStock <= 0) { + $warningStock = 2; + } + + $query->whereIn('id', function ($skuQuery) use ($warningStock) { + $skuQuery->name('pt_normal_sku') + ->where('is_show', 1) + ->where('stock', '<', $warningStock) + ->field('product_id'); + }); + } + // ===== 商品生命周期管理(中台主表 + 扩展表同步) ===== /**