Merge pull request '修改商品列表搜索' (#16) from dev into main

Reviewed-on: #16
This commit is contained in:
mkm 2025-04-16 16:44:58 +08:00
commit 4f7c8ffa85
4 changed files with 45 additions and 6 deletions

View File

@ -91,5 +91,10 @@ class StoreCategoryController extends BaseAdminController
return $this->data($result); return $this->data($result);
} }
public function tree()
{
$result = StoreCategoryLogic::tree();
return $this->data($result);
}
} }

View File

@ -57,12 +57,12 @@ class StoreProductLists extends BaseAdminDataLists implements ListsSearchInterfa
$class_all = $this->request->get('class_all'); $class_all = $this->request->get('class_all');
if ($class_all) { if ($class_all) {
//查3级别的 //查3级别的
$arr = Cate::where('pid', $class_all)->column('id'); if (count($class_all) == 1) {
if ($arr) { $this->searchWhere[] = ['top_cate_id', '=', $class_all[0]];
$arr2 = Cate::where('pid', 'in', $arr)->column('id'); } elseif (count($class_all) == 2) {
$this->searchWhere[] = ['cate_id', 'in', array_merge($arr, $arr2)]; $this->searchWhere[] = ['two_cate_id', '=', $class_all[1]];
} else { } else {
$this->searchWhere[] = ['cate_id', '=', $class_all]; $this->searchWhere[] = ['cate_id', '=', $class_all[2]];
} }
} }
$is_warehouse = $this->request->get('is_warehouse', 0); $is_warehouse = $this->request->get('is_warehouse', 0);

View File

@ -108,4 +108,11 @@ class StoreCategoryLogic extends BaseLogic
{ {
return StoreCategory::findOrEmpty($params['id'])->toArray(); return StoreCategory::findOrEmpty($params['id'])->toArray();
} }
public static function tree()
{
$data = StoreCategory::field('id,pid,name')->order('id desc')->select()->toArray();
return list2tree($data);
}
} }

View File

@ -584,3 +584,30 @@ function SqlChannelPriceLog($product_id=0, $group_id=0, $before_price=0,$after_p
// return $orderId; // return $orderId;
// } // }
// } // }
if (!function_exists('list2tree')) {
function list2tree(array $list, $idKey = 'id', $parentKey = 'pid', $childrenKey = 'children')
{
$tree = [];
$itemsByReference = [];
// 首先将所有项目按id存入引用数组
foreach ($list as &$item) {
$itemsByReference[$item[$idKey]] = &$item;
$item[$childrenKey] = [];
}
// 构建树
foreach ($list as &$item) {
if ($item[$parentKey] && isset($itemsByReference[$item[$parentKey]])) {
$itemsByReference[$item[$parentKey]][$childrenKey][] = &$item;
} else {
$tree[] = &$item;
}
}
return $tree;
}
}