减少查询总数排序

This commit is contained in:
liu 2024-03-09 11:50:23 +08:00
parent 847b30637b
commit ea7a01ecf4
2 changed files with 22 additions and 4 deletions

View File

@ -55,6 +55,11 @@ class SpuDao extends BaseDao
if(isset($where['order']) && $where['order'] === 'none'){
$order = '';
}
if(isset($where['order_remark']) && $where['order_remark'] === 'none'){
$order = '';
}
$query = Spu::getDB()->alias('S')->join('StoreProduct P','S.product_id = P.product_id', 'left');
$query->when(isset($where['is_del']) && $where['is_del'] !== '',function($query)use($where){
$query->where('P.is_del',$where['is_del']);
@ -90,9 +95,9 @@ class SpuDao extends BaseDao
->when(isset($where['is_trader']) && $where['is_trader'] !== '',function($query)use($where){
$merId = app()->make(MerchantRepository::class)->search([
'is_trader' => $where['is_trader'],
'status' => 1,
'mer_state' => 1,
'is_del' => 1,
'status' => 1,//状态正常
'mer_state' => 1,//商户开启
'is_del' => 1,//
])->column('mer_id');
$query->whereIn('P.mer_id',$merId);

View File

@ -154,6 +154,19 @@ class SpuRepository extends BaseRepository
if (!empty($this->orderField)) {
$this->dao->orderField = $this->orderField;
}
//取消数量排序
$where['order_remark'] = "none";
$queryCount = $this->dao->search($where);
// $queryCount->with([
// 'merchant' => function ($queryCount) {
// $queryCount->field($this->merchantFiled)->with(['type_names', 'street_names']);
// },
// 'issetCoupon',
// 'product.attrValue',
// ]);
unset($where['order_remark']);
$count = $queryCount->count();
$query = $this->dao->search($where);
$query->with([
@ -164,7 +177,7 @@ class SpuRepository extends BaseRepository
'product.attrValue',
]);
$productMake = app()->make(ProductRepository::class);
$count = $query->count();
// $count = $query->count();
if ($limit == 0) {
$list = $query->setOption('field', [])->field($this->productFiled)->select()
->each(function ($item) use ($is_sku, $productMake, $userInfo,$where) {