// 价格区间
$price_where = $max_where = [];
if (isset($json['section'])) {
$min_money = $json['section']['min'];
$max_money = $json['section']['max'];
if ($min_money >= 0 ) {
$price_where["goods_price"] = ['egt',$min_money];
}
if ($max_money > 0) {
$price_where["goods_price"] = ['elt',$max_money];
}
}
// 执行查询
$list = $this
->field(['*', '(sales_initial + sales_actual) as goods_sales',
"$minPriceSql AS goods_min_price",
"$maxPriceSql AS goods_max_price"
])
->with(['category','image.file',
'sku' => function($query) use ($price_where) {
if (!empty($price_where)) {
$query->where($price_where);
}
}
])
->where('is_delete', '=', 0)
->where($filter)
->order($sort)
->paginate($params['listRows'], false, [
'query' => \request()->request()
]);
echo $this->getLastSql(); 最佳答案