调整商品分类管理
This commit is contained in:
parent
01d63e6114
commit
ea0b6f1f65
@ -7,6 +7,7 @@ use app\admin\controller\BaseAdminController;
|
|||||||
use app\admin\lists\ProductCategoryLists;
|
use app\admin\lists\ProductCategoryLists;
|
||||||
use app\admin\logic\ProductCategoryLogic;
|
use app\admin\logic\ProductCategoryLogic;
|
||||||
use app\admin\validate\ProductCategoryValidate;
|
use app\admin\validate\ProductCategoryValidate;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,5 +92,11 @@ class ProductCategoryController extends BaseAdminController
|
|||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function all(Request $request)
|
||||||
|
{
|
||||||
|
$params = $request->get();
|
||||||
|
$result = ProductCategoryLogic::all($params);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -27,6 +27,7 @@ class ProductCategoryLists extends BaseAdminDataLists implements ListsSearchInte
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['pid', 'name'],
|
'=' => ['pid', 'name'],
|
||||||
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +43,13 @@ class ProductCategoryLists extends BaseAdminDataLists implements ListsSearchInte
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return ProductCategory::where($this->searchWhere)
|
$lists = ProductCategory::where($this->searchWhere)
|
||||||
->field(['id', 'pid', 'name', 'create_time'])
|
->field(['id', 'pid', 'name', 'create_time'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
return linear_to_tree($lists, 'children');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,4 +93,12 @@ class ProductCategoryLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
return ProductCategory::findOrEmpty($params['id'])->toArray();
|
return ProductCategory::findOrEmpty($params['id'])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function all($params)
|
||||||
|
{
|
||||||
|
$query = ProductCategory::field(['id', 'pid', 'name', 'create_time']);
|
||||||
|
$list = $query->order(['id' => 'desc'])->select()->toArray();
|
||||||
|
return linear_to_tree($list, 'children');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -94,13 +94,14 @@ function create_password(string $plaintext, string $salt) : string
|
|||||||
* @param int $parent_id 此值请勿给参数
|
* @param int $parent_id 此值请勿给参数
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function linear_to_tree($data, $sub_key_name = 'sub', $id_name = 'id', $parent_id_name = 'pid', $parent_id = 0)
|
function linear_to_tree($data, $sub_key_name = 'sub', $id_name = 'id', $parent_id_name = 'pid', $parent_id = 0, $level = 0)
|
||||||
{
|
{
|
||||||
$tree = [];
|
$tree = [];
|
||||||
foreach ($data as $row) {
|
foreach ($data as $row) {
|
||||||
|
$row['level'] = $level;
|
||||||
if ($row[$parent_id_name] == $parent_id) {
|
if ($row[$parent_id_name] == $parent_id) {
|
||||||
$temp = $row;
|
$temp = $row;
|
||||||
$child = linear_to_tree($data, $sub_key_name, $id_name, $parent_id_name, $row[$id_name]);
|
$child = linear_to_tree($data, $sub_key_name, $id_name, $parent_id_name, $row[$id_name], $level + 1);
|
||||||
if ($child) {
|
if ($child) {
|
||||||
$temp[$sub_key_name] = $child;
|
$temp[$sub_key_name] = $child;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user