// +---------------------------------------------------------------------- namespace app\services\system\config; use app\model\system\config\SystemConfigTab; use qiniu\basic\BaseServices; use qiniu\exceptions\AdminException; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; /** * 系统配置分类 * Class SystemConfigTabServices * @package app\services\system\config * @mixin SystemConfigTab */ class SystemConfigTabServices extends BaseServices { /** * SystemConfigTabServices constructor. * @param SystemConfigTab $model */ public function __construct(SystemConfigTab $model) { $this->model = $model; } /** * 获取配置分类 * @param array $searchWhere * @param array $field * @param array $where * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function getConfigTabAll(array $searchWhere, array $field = ['*'], array $where = []) { return $this->search($searchWhere)->when(count($where), function ($query) use ($where) { $query->where($where); })->field($field)->order('sort desc,id asc')->select()->toArray(); } /** * 系统设置头部分类读取 * @param int $pid * @param int $is_store * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function getConfigTab(int $pid, int $is_store = 0) { $searchWhere = ['status' => 1, 'pid' => $pid, 'is_store' => $is_store]; $field = ['id', 'id as value', 'title as label', 'pid', 'icon']; $list = $this->getConfigTabAll($searchWhere, $field); return get_tree_children($list, $pid); } /** * 获取配置分类列表 * @param array $where * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function getConfgTabList(array $where) { $list = $this->getConfigTabAll($where); $count = $this->getCount($where); $list = get_tree_children($list, $where['pid'] ?? 0); return compact('list', 'count'); } /** * 获取配置分类选择下拉树 * @return array * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException */ public function getSelectForm() { $menuList = $this->getConfigTabAll([], ['id as value', 'pid', 'title as label']); $menus = [['value' => 0, 'label' => '顶级按钮']]; $menuList = array_merge($menus, $menuList); return get_tree_children($menuList, 0, 'value'); } }