feat: 修改ProductLists类实现搜索、排序和扩展功能

This commit is contained in:
mkm 2024-06-25 14:34:11 +08:00
parent 903573ece2
commit 5d5b2a28ca

View File

@ -20,7 +20,7 @@ use think\facade\Db;
* Class goods
* @package app\api\goods
*/
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface,ListsExtendInterface
class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface, ListsExtendInterface
{
@ -32,20 +32,10 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/
public function setSearch(): array
{
$name = $this->request->get('store_name', '');
// $where['%pipe_like%'] =['name'=>'store_name|bar_code'];
if ($name) {
if (preg_match('/[\x{4e00}-\x{9fff}]+/u', $name) == 1) {
$where['%like%'] = ['store_name' => 'store_name'];
$where['='] = ['store_id', 'bar_code', 'cate_id'];
} else {
$where['='] = ['bar_code', 'cate_id'];
}
} else {
$where['='] = ['store_id', 'bar_code', 'cate_id'];
}
return $where;
return [
'=' => ['store_id', 'cate_id'],
'%pipe_like%' => ['store_name' => 'store_name|bar_code'],
];
}
/**
* @notes 设置支持排序字段
@ -114,29 +104,16 @@ class ProductLists extends BaseAdminDataLists implements ListsSearchInterface, L
*/
public function count(): int
{
$class_all = $this->request->get('class_all');
if ($class_all) {
//查3级别的
$arr = Cate::where('pid', $class_all)->column('id');
if ($arr) {
$arr2 = Cate::where('pid', 'in', $arr)->column('id');
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)];
} else {
$this->searchWhere[] = ['cate_id', '=', $class_all];
}
}
$this->searchWhere[] = ['status', '=', 1];
$this->searchWhere[] = ['stock', '>', 0];
return StoreBranchProduct::where($this->searchWhere)
->count();
}
public function extend(){
public function extend()
{
$off_activity = Config::where('name', 'off_activity')->value('value');
return [
'off_activity'=>$off_activity,
'price'=>'cost',
'op_price'=>'price',
'off_activity' => $off_activity,
'price' => 'cost',
'op_price' => 'price',
];
}
}