Setting.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\common\controller\AdminController;
  4. use app\http\IResponse;
  5. class Setting extends AdminController
  6. {
  7. public function xdebug()
  8. {
  9. return IResponse::success();
  10. }
  11. /**
  12. * 获取设置
  13. *
  14. * @author 许祖兴 < zuxing.xu@lettered.cn>
  15. *
  16. * @return mixed
  17. */
  18. public function index()
  19. {
  20. if ($this->request->param('group')){
  21. $settings = model('common/SystemConfig')->where(['group' => $this->request->param('group')])
  22. ->order('sort,id')
  23. ->column('id,name,title,group,value,type,options,tips');
  24. //
  25. $lists = [];
  26. foreach ($settings as $k => $v) {
  27. if (!empty($v['options'])) {
  28. $v['options'] = parse_attr($v['options']);
  29. }
  30. if ($v['type'] == 'checkbox') {
  31. $v['value'] = explode(',', $v['value']);
  32. }
  33. $v['tips'] = htmlspecialchars_decode( $v['tips']);
  34. $lists[] = $v;
  35. }
  36. // 更新缓存
  37. model('common/SystemConfig')->getAppConfig('');
  38. return IResponse::success($lists);
  39. }
  40. $tabData= [];
  41. foreach (config('develop.config_group') as $key => $value) {
  42. $tabData[] = [
  43. 'name' => $value,
  44. 'policy' => $key
  45. ];
  46. }
  47. return IResponse::success($tabData);
  48. }
  49. /**
  50. * 更新设置
  51. *
  52. * @author 许祖兴 < zuxing.xu@lettered.cn>
  53. * @param string $group
  54. * @return mixed
  55. */
  56. public function update($group = 'system')
  57. {
  58. $data = $this->request->param('set/a');
  59. // halt($data);
  60. foreach ($data as $name => $value) {
  61. //$config = model('common/SystemConfig')::get(['name' => $name]);
  62. model('common/SystemConfig')::update(['value' => $value],['name' => $name]);
  63. }
  64. // 更新配置缓存
  65. model('common/SystemConfig')->getAppConfig('', true);
  66. return IResponse::success('更新系统配置成功');
  67. }
  68. }