SystemConfigTab.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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\admin\controller\setting;
  12. use think\Url;
  13. use service\FormBuilder as Form;
  14. use think\Request;
  15. use service\JsonService as Json;
  16. use app\admin\controller\AuthController;
  17. use app\admin\model\system\SystemConfigTab as ConfigTabModel;
  18. use app\admin\model\system\SystemConfig as ConfigModel;
  19. /**
  20. * 配置分类控制器
  21. * Class SystemConfigTab
  22. * @package app\admin\controller\system
  23. */
  24. class SystemConfigTab extends AuthController
  25. {
  26. /**
  27. * 子子段
  28. * @return mixed|\think\response\Json
  29. */
  30. public function sonconfigtab($tab_id = '')
  31. {
  32. if (!$tab_id) return Json::fail('参数错误');
  33. $this->assign('tab_id', $tab_id);
  34. $list = ConfigModel::getAll($tab_id);
  35. foreach ($list as $k => $v) {
  36. $list[$k]['value'] = json_decode($v['value'], true);
  37. if ($v['type'] == 'radio' || $v['type'] == 'checkbox') {
  38. $list[$k]['value'] = ConfigTabModel::getRadioOrCheckboxValueInfo($v['menu_name'], $v['value']);
  39. }
  40. if ($v['type'] == 'upload' && !empty($v['value'])) {
  41. if ($v['upload_type'] == 1 || $v['upload_type'] == 3) $list[$k]['value'] = is_array($v['value']) ? explode(',', $v['value'][0]) : explode(',', $v['value']);
  42. }
  43. }
  44. $this->assign('list', $list);
  45. return $this->fetch();
  46. }
  47. /**
  48. * 基础配置
  49. * @return mixed
  50. */
  51. public function index()
  52. {
  53. $where = parent::getMore([
  54. ['status', ''],
  55. ['title', ''],
  56. ], $this->request);
  57. $this->assign('where', $where);
  58. $this->assign(ConfigTabModel::getSystemConfigTabPage($where));
  59. return $this->fetch();
  60. }
  61. /**
  62. * 添加配置分类
  63. * @return mixed
  64. */
  65. public function create()
  66. {
  67. $form = Form::create(Url::build('save'), [
  68. Form::input('title', '分类昵称'),
  69. Form::input('eng_title', '分类字段'),
  70. Form::frameInputOne('icon', '图标', Url::build('admin/widget.widgets/icon', array('fodder' => 'icon')))->icon('ionic'),
  71. Form::radio('type', '类型', 0)->options([['value' => 0, 'label' => '系统'], ['value' => 1, 'label' => '公众号'],['value' => 4, 'label' => '支付'],['value' => 5, 'label' => '阿里云'],['value' => 3, 'label' => '其它'],['value' => 7, 'label' => '虚拟币']]),
  72. Form::radio('status', '状态', 1)->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']])
  73. ]);
  74. $form->setMethod('post')->setTitle('添加分类配置');
  75. $this->assign(compact('form'));
  76. return $this->fetch('public/form-builder');
  77. }
  78. /**
  79. * 保存分类名称
  80. * @param Request $request
  81. * @return \think\response\Json
  82. */
  83. public function save(Request $request)
  84. {
  85. $data = parent::postMore([
  86. 'eng_title',
  87. 'status',
  88. 'title',
  89. 'icon',
  90. 'type'], $request);
  91. if (!$data['title']) return Json::fail('请输入按钮名称');
  92. ConfigTabModel::set($data);
  93. return Json::successful('添加菜单成功!');
  94. }
  95. /**
  96. * 修改分类
  97. * @param $id
  98. * @return mixed
  99. */
  100. public function edit($id)
  101. {
  102. $menu = ConfigTabModel::get($id)->getData();
  103. if (!$menu) return Json::fail('数据不存在!');
  104. $form = Form::create(Url::build('update', array('id' => $id)), [
  105. Form::input('title', '分类昵称', $menu['title']),
  106. Form::input('eng_title', '分类字段', $menu['eng_title']),
  107. Form::frameInputOne('icon', '图标', Url::build('admin/widget.widgets/icon', array('fodder' => 'icon')), $menu['icon'])->icon('ionic'),
  108. Form::radio('type', '类型', $menu['type'])->options([['value' => 0, 'label' => '系统'], ['value' => 1, 'label' => '公众号'], ['value' => 4, 'label' => '支付'] ,['value' => 5, 'label' => '阿里云'],['value' => 3, 'label' => '其它'],['value' => 6, 'label' => '虚拟币']]),
  109. Form::radio('status', '状态', $menu['status'])->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']])
  110. ]);
  111. $form->setMethod('post')->setTitle('添加分类配置');
  112. $this->assign(compact('form'));
  113. return $this->fetch('public/form-builder');
  114. }
  115. /**
  116. * @param Request $request
  117. * @param $id
  118. * @return \think\response\Json
  119. */
  120. public function update(Request $request, $id)
  121. {
  122. $data = parent::postMore(['title', 'status', 'eng_title', 'icon', 'type'], $request);
  123. if (!$data['title']) return Json::fail('请输入分类昵称');
  124. if (!$data['eng_title']) return Json::fail('请输入分类字段');
  125. if (!ConfigTabModel::get($id)) return Json::fail('编辑的记录不存在!');
  126. ConfigTabModel::edit($data, $id);
  127. return Json::successful('修改成功!');
  128. }
  129. /**
  130. * @param $id
  131. * @return \think\response\Json
  132. */
  133. public function delete($id)
  134. {
  135. if (!ConfigTabModel::del($id))
  136. return Json::fail(ConfigTabModel::getErrorInfo('删除失败,请稍候再试!'));
  137. else
  138. return Json::successful('删除成功!');
  139. }
  140. }