From ba81facddc095b0413b8482de7c45ce61683d445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Tue, 20 Oct 2026 16:45:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BD=91=E7=9B=98=E5=95=86=E5=93=81):=20?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=94=AF=E6=8C=81=E5=88=86=E7=B1=BB/?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC/=E5=BA=93=E5=AD=98/=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 列表查询改走中台商品搜索器(getCount/getSearchList),新增 cate_id、价格区间、库存区间、创建时间筛选参数 --- .../controller/admin/ProductController.php | 6 ++ .../virtual/service/ProductServices.php | 56 +++++++++++++------ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/backend/modules/product/virtual/controller/admin/ProductController.php b/backend/modules/product/virtual/controller/admin/ProductController.php index 283614e1b..62b96459d 100644 --- a/backend/modules/product/virtual/controller/admin/ProductController.php +++ b/backend/modules/product/virtual/controller/admin/ProductController.php @@ -30,8 +30,14 @@ class ProductController extends AuthController ['page', 1], ['limit', 20], ['store_name', ''], + ['cate_id', ''], ['status', ''], ['is_del', 0], + ['price_min', ''], + ['price_max', ''], + ['stock_min', ''], + ['stock_max', ''], + ['time', ''], ]); $result = $service->getList($params); return app('json')->success($result); diff --git a/backend/modules/product/virtual/service/ProductServices.php b/backend/modules/product/virtual/service/ProductServices.php index 73e8bcbb5..48ea4d40c 100644 --- a/backend/modules/product/virtual/service/ProductServices.php +++ b/backend/modules/product/virtual/service/ProductServices.php @@ -45,34 +45,56 @@ class ProductServices */ public function getList(array $params): array { - $where = [ - ['product_type', '=', 'virtual'], + $searchWhere = [ + 'product_type' => 'virtual', + 'store_name' => $params['store_name'] ?? '', + 'cate_id' => $params['cate_id'] ?? '', + 'price_s' => [ + $params['price_min'] ?? '', + $params['price_max'] ?? '', + ], + 'stock_s' => [ + $params['stock_min'] ?? '', + $params['stock_max'] ?? '', + ], + 'time' => $this->parseTimeRange($params['time'] ?? ''), ]; $isDel = (int) ($params['is_del'] ?? 0); - if ($isDel === 0) { - $where[] = ['is_del', '=', 0]; - } elseif ($isDel === 1) { - $where[] = ['is_del', '=', 1]; - } - if (!empty($params['store_name'])) { - $where[] = ['name', 'like', '%' . $params['store_name'] . '%']; - } - if ($params['status'] !== '') { - $where[] = ['is_show', '=', (int) $params['status']]; + $searchWhere['is_del'] = $isDel; + if (($params['status'] ?? '') !== '') { + $searchWhere['is_show'] = (int) $params['status']; } $page = max(1, (int) ($params['page'] ?? 1)); $limit = max(1, (int) ($params['limit'] ?? 20)); - $total = $this->centerDao->count($where); - $list = $this->centerDao->selectList( - $where, - 'id,name as store_name,image,price,stock,sales,is_show,sort_order,add_time', + $total = $this->centerDao->getCount($searchWhere); + $list = $this->centerDao->getSearchList( + $searchWhere, $page, $limit, - 'sort_order DESC, id DESC' + ['id', 'name as store_name', 'image', 'price', 'stock', 'sales', 'is_show', 'sort_order', 'add_time'] ); return compact('total', 'list'); } + /** + * 将前端日期范围转换为中台商品搜索器支持的时间戳数组。 + * @param array|string $value + * @return array|string + */ + protected function parseTimeRange(array|string $value): array|string + { + if (is_array($value) || $value === '') { + return $value; + } + $range = array_map('trim', explode(',', $value)); + if (count($range) !== 2) { + return $value; + } + $start = strtotime($range[0] . ' 00:00:00'); + $end = strtotime($range[1] . ' 23:59:59'); + return [$start ?: 0, $end ?: 0]; + } + /** * 获取商品详情(基础信息 + 扩展信息) * @param int $productId