优化查询

This commit is contained in:
liu 2024-07-02 09:44:23 +08:00
parent 3ae5eab678
commit 08f6eedff4

View File

@ -32,6 +32,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
'=' => ['product_id', 'cate_id','store_id','status'], '=' => ['product_id', 'cate_id','store_id','status'],
'%pipe_like%' => ['store_name_code'=>'store_name|bar_code'], '%pipe_like%' => ['store_name_code'=>'store_name|bar_code'],
'%like%' => ['store_name'], '%like%' => ['store_name'],
'<='=> ['stock'],
]; ];
} }
@ -47,7 +48,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/ */
public function lists(): array public function lists(): array
{ {
$status = $this->params['status'] ?? '';
$class_all=$this->request->get('class_all'); $class_all=$this->request->get('class_all');
$where=[]; $where=[];
if($class_all){ if($class_all){
@ -69,17 +69,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
->when(!empty($this->adminInfo['store_id']), function ($query) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']); $query->where('store_id', $this->adminInfo['store_id']);
}) })
->when(!empty($status), function ($query) use ($status) {
if ($status == 1) {
$query->where('status', $status);
} elseif ($status == 2) {
$query->where('status', 0);
} elseif ($status == 3) {
$query->where('stock', '<=', 0);
} elseif ($status == 4) {
$query->where('stock', '<', 10)->where('stock', '>', 0);
}
})
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['sort' => 'desc','stock'=>'desc','id' => 'desc']) ->order(['sort' => 'desc','stock'=>'desc','id' => 'desc'])
->select() ->select()
@ -101,22 +90,10 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
*/ */
public function count(): int public function count(): int
{ {
$status = $this->params['status'] ?? '';
return StoreBranchProduct::where($this->searchWhere) return StoreBranchProduct::where($this->searchWhere)
->when(!empty($this->adminInfo['store_id']), function ($query) { ->when(!empty($this->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->adminInfo['store_id']); $query->where('store_id', $this->adminInfo['store_id']);
}) })
->when(!empty($status), function ($query) use ($status) {
if ($status == 1) {
$query->where('status', $status);
} elseif ($status == 2) {
$query->where('status', 0);
} elseif ($status == 3) {
$query->where('stock', '<=', 0);
} elseif ($status == 4) {
$query->where('stock', '<', 10)->where('stock', '>', 0);
}
})
->count(); ->count();
} }