修改商品列表检索
This commit is contained in:
parent
cde1d98426
commit
7faa7ff5db
@ -28,7 +28,8 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['product_id'],
|
||||
'=' => ['product_id', 'cate_id'],
|
||||
'%like%' => ['store_name'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -44,11 +45,23 @@ class StoreBranchProductLists extends BaseAdminDataLists implements ListsSearchI
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$status = $this->params['status'] ?? '';
|
||||
return StoreBranchProduct::where($this->searchWhere)
|
||||
->field(['id', 'image', 'store_name', 'cate_id', 'price', 'sales', 'stock', 'unit', 'cost'])
|
||||
->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', 'id' => 'desc'])
|
||||
->select()
|
||||
@ -69,10 +82,23 @@ 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']);
|
||||
})->count();
|
||||
})
|
||||
->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