SystemConfigTabServices.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\system\config;
  12. use app\model\system\config\SystemConfigTab;
  13. use qiniu\basic\BaseServices;
  14. use qiniu\exceptions\AdminException;
  15. use think\db\exception\DataNotFoundException;
  16. use think\db\exception\DbException;
  17. use think\db\exception\ModelNotFoundException;
  18. /**
  19. * 系统配置分类
  20. * Class SystemConfigTabServices
  21. * @package app\services\system\config
  22. * @mixin SystemConfigTab
  23. */
  24. class SystemConfigTabServices extends BaseServices
  25. {
  26. /**
  27. * SystemConfigTabServices constructor.
  28. * @param SystemConfigTab $model
  29. */
  30. public function __construct(SystemConfigTab $model)
  31. {
  32. $this->model = $model;
  33. }
  34. /**
  35. * 获取配置分类
  36. * @param array $searchWhere
  37. * @param array $field
  38. * @param array $where
  39. * @return array
  40. * @throws DataNotFoundException
  41. * @throws DbException
  42. * @throws ModelNotFoundException
  43. */
  44. public function getConfigTabAll(array $searchWhere, array $field = ['*'], array $where = [])
  45. {
  46. return $this->search($searchWhere)->when(count($where), function ($query) use ($where) {
  47. $query->where($where);
  48. })->field($field)->order('sort desc,id asc')->select()->toArray();
  49. }
  50. /**
  51. * 系统设置头部分类读取
  52. * @param int $pid
  53. * @param int $is_store
  54. * @return array
  55. * @throws DataNotFoundException
  56. * @throws DbException
  57. * @throws ModelNotFoundException
  58. */
  59. public function getConfigTab(int $pid, int $is_store = 0)
  60. {
  61. $searchWhere = ['status' => 1, 'pid' => $pid, 'is_store' => $is_store];
  62. $field = ['id', 'id as value', 'title as label', 'pid', 'icon'];
  63. $list = $this->getConfigTabAll($searchWhere, $field);
  64. return get_tree_children($list, $pid);
  65. }
  66. /**
  67. * 获取配置分类列表
  68. * @param array $where
  69. * @return array
  70. * @throws DataNotFoundException
  71. * @throws DbException
  72. * @throws ModelNotFoundException
  73. */
  74. public function getConfgTabList(array $where)
  75. {
  76. $list = $this->getConfigTabAll($where);
  77. $count = $this->getCount($where);
  78. $list = get_tree_children($list, $where['pid'] ?? 0);
  79. return compact('list', 'count');
  80. }
  81. /**
  82. * 获取配置分类选择下拉树
  83. * @return array
  84. * @throws DataNotFoundException
  85. * @throws DbException
  86. * @throws ModelNotFoundException
  87. */
  88. public function getSelectForm()
  89. {
  90. $menuList = $this->getConfigTabAll([], ['id as value', 'pid', 'title as label']);
  91. $menus = [['value' => 0, 'label' => '顶级按钮']];
  92. $menuList = array_merge($menus, $menuList);
  93. return get_tree_children($menuList, 0, 'value');
  94. }
  95. }