feat(网盘商品): 列表支持分类/价格/库存/时间筛选

列表查询改走中台商品搜索器(getCount/getSearchList),新增 cate_id、价格区间、库存区间、创建时间筛选参数
This commit is contained in:
吴昊天 2026-10-20 16:45:26 +08:00
parent 890dfab6b2
commit ba81facddc
2 changed files with 45 additions and 17 deletions

View File

@ -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);

View File

@ -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