优化查询
This commit is contained in:
parent
3ae5eab678
commit
08f6eedff4
@ -32,6 +32,7 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
'=' => ['product_id', 'cate_id','store_id','status'],
|
||||
'%pipe_like%' => ['store_name_code'=>'store_name|bar_code'],
|
||||
'%like%' => ['store_name'],
|
||||
'<='=> ['stock'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -47,7 +48,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$status = $this->params['status'] ?? '';
|
||||
$class_all=$this->request->get('class_all');
|
||||
$where=[];
|
||||
if($class_all){
|
||||
@ -69,17 +69,6 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
||||
$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)
|
||||
->order(['sort' => 'desc','stock'=>'desc','id' => 'desc'])
|
||||
->select()
|
||||
@ -101,22 +90,10 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
$status = $this->params['status'] ?? '';
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
->when(!empty($this->adminInfo['store_id']), function ($query) {
|
||||
$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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user