<?php
declare (strict_types = 1);

namespace app\admin\controller\v1;

use app\admin\model\v1\ProductTcoCategoryModel;

/**
 * 产品 - 产品目录分类控制器
 */
class ProductTcoCategory
{
    // 分类树
    public function tree()
    {
        $param = request()->param(['name']);

        $categorys = ProductTcoCategoryModel::field([
                'id',
                'tco_id',
                'tco_pid',
                'name',
            ])
            ->withSearch(['name'], [
                'name' => $param['name'] ?? null,
            ])
            ->language(request()->lang_id)
            ->enabled()
            ->order(['tco_id' => 'asc'])
            ->select()
            ->toArray();

        return success('获取成功', array_to_tree($categorys, 0, 'tco_pid', false, true, 'tco_id'));
    }
}
