SystemConfigTabServices.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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\dao\system\config\SystemConfigTabDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. use crmeb\services\FormBuilder as Form;
  16. /**
  17. * 系统配置分类
  18. * Class SystemConfigTabServices
  19. * @package app\services\system\config
  20. * @mixin SystemConfigTabDao
  21. */
  22. class SystemConfigTabServices extends BaseServices
  23. {
  24. /**
  25. * SystemConfigTabServices constructor.
  26. * @param SystemConfigTabDao $dao
  27. */
  28. public function __construct(SystemConfigTabDao $dao)
  29. {
  30. $this->dao = $dao;
  31. }
  32. /**
  33. * 系统设置头部分类读取
  34. * @param int $pid
  35. * @param int $is_store
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getConfigTab(int $pid, int $is_store = 0)
  42. {
  43. $list = $this->dao->getConfigTabAll(['status' => 1, 'pid' => $pid, 'is_store' => $is_store], ['id', 'id as value', 'title as label', 'pid', 'icon', 'type'], $pid ? [] : [['type', '=', '0']]);
  44. return get_tree_children($list);
  45. }
  46. /**
  47. * 获取配置分类列表
  48. * @param array $where
  49. * @return array
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\DbException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function getConfgTabList(array $where)
  55. {
  56. [$page, $limit] = $this->getPageValue();
  57. $list = $this->dao->getConfgTabList($where, $page, $limit);
  58. $count = $this->dao->count($where);
  59. $menusValue = [];
  60. foreach ($list as $item) {
  61. $menusValue[] = $item->getData();
  62. }
  63. $list = get_tree_children($menusValue);
  64. return compact('list', 'count');
  65. }
  66. /**
  67. * 获取配置分类选择下拉树
  68. * @return array
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function getSelectForm()
  74. {
  75. $menuList = $this->dao->getConfigTabAll([], ['id as value', 'pid', 'title as label']);
  76. $menus = [['value' => 0, 'label' => '顶级按钮']];
  77. $list = get_tree_children($menuList, 'children', 'value');
  78. $menus = array_merge($menus, $list);
  79. // foreach ($list as $menu) {
  80. // $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['title']];
  81. // }
  82. return $menus;
  83. }
  84. /**
  85. * 创建form表单
  86. * @param array $formData
  87. * @return array
  88. * @throws \FormBuilder\Exception\FormBuilderException
  89. * @throws \think\db\exception\DataNotFoundException
  90. * @throws \think\db\exception\DbException
  91. * @throws \think\db\exception\ModelNotFoundException
  92. */
  93. public function createConfigTabForm(array $formData = [])
  94. {
  95. $pid[] = isset($formData['pid']) ? $formData['pid'] : 0;
  96. $form[] = Form::radio('is_store', '类型', $formData['is_store'] ?? 0)->options([['value' => 0, 'label' => '总后台'], ['value' => 1, 'label' => '门店后台']]);
  97. $form[] = Form::cascader('pid', '父级分类', $pid)->data($this->getSelectForm())->changeOnSelect(true);
  98. $form[] = Form::input('title', '分类名称', $formData['title'] ?? '');
  99. $form[] = Form::input('eng_title', '分类字段英文', $formData['eng_title'] ?? '');
  100. $form[] = Form::frameInput('icon', '图标', $this->url(config('admin.admin_prefix') . '/widget.widgets/icon', ['fodder' => 'icon'], true), $formData['icon'] ?? '')->icon('ios-ionic')->height('435px');
  101. $form[] = Form::radio('type', '类型', $formData['type'] ?? 0)->options([
  102. ['value' => 0, 'label' => '系统'],
  103. ['value' => 3, 'label' => '其它']
  104. ]);
  105. $form[] = Form::radio('status', '状态', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
  106. $form[] = Form::number('sort', '排序', (int)($formData['sort'] ?? 0))->min(0);
  107. return $form;
  108. }
  109. /**
  110. * 添加配置分类表单
  111. * @return array
  112. * @throws \FormBuilder\Exception\FormBuilderException
  113. */
  114. public function createForm()
  115. {
  116. return create_form('添加配置分类', $this->createConfigTabForm(), $this->url('/setting/config_class'));
  117. }
  118. /**
  119. * 修改配置分类表单
  120. * @param int $id
  121. * @return array
  122. * @throws \FormBuilder\Exception\FormBuilderException
  123. */
  124. public function updateForm(int $id)
  125. {
  126. $configTabInfo = $this->dao->get($id);
  127. if (!$configTabInfo) {
  128. throw new AdminException('没有查到数据,无法修改!');
  129. }
  130. return create_form('编辑配置分类', $this->createConfigTabForm($configTabInfo->toArray()), $this->url('/setting/config_class/' . $id), 'PUT');
  131. }
  132. }