问题现象:商品列表按分类筛选后,选择“所有页”批量修改运费模板,提交后报错:查询表达式错误:'pid'。
原因定位:批量操作在根据筛选条件查询商品 ID 时,分类子级查询条件写成了 getColumn(['pid', 'in', $where['cate_id']], 'id')。当前 Dao 的 getColumn 需要标准 where 数组或走搜索器,这种写法会被解析成错误查询表达式,导致 pid 报错。
修复思路:复用商品分类服务中已有的分类缓存展开方法 getChildIdsFromCache,先把当前分类和子分类 ID 合并,再传给商品列表查询。
行数以当前本地源码为准,不同版本可能有少量偏移。
1. 修复批量操作按分类筛选商品 ID 的查询条件
文件: app/services/product/product/StoreProductBatchProcessServices.php
方法: getIdsByWhere(array $where): array
行数: 61-83
/** * 根据搜索条件查询商品ID * @param array $where 搜索条件 * @return array */
public function getIdsByWhere(array $where): array
{
$ids = [];
if (isset($where['cate_id']) && $where['cate_id']) {
/** @var StoreProductCategoryServices $storeCategory */
$storeCategory = app()->make(StoreProductCategoryServices::class);
$cateId = is_array($where['cate_id']) ? $where['cate_id'] : [$where['cate_id']];
$cateId = array_values(array_unique(array_filter($cateId)));
// 全选批量操作按当前分类及其子分类筛选,避免错误的 where 数组触发 pid 查询表达式异常。
$where['cate_id'] = array_values(array_unique(array_merge($cateId, $storeCategory->getChildIdsFromCache($cateId))));
}
/** @var StoreProductServices $productService */
$productService = app()->make(StoreProductServices::class);
$dataInfo = $productService->getProductListByWhere($where, 'id');
if ($dataInfo) {
$ids = array_unique(array_column($dataInfo, 'id'));
}
return $ids;
}验证方式:
1. 后台进入商品列表,选择一个商品分类筛选。
2. 勾选“所有页”,批量修改运费模板,选择运费模板后提交。
3. 不再出现 查询表达式错误:'pid',任务正常加入批量队列。
4. 已执行语法检查:php -l app/services/product/product/StoreProductBatchProcessServices.php。

