123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- 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');
- }
- }
|