Config.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller;
  15. use think\admin\Controller;
  16. use think\admin\service\AdminService;
  17. use think\admin\service\ModuleService;
  18. use think\admin\service\SystemService;
  19. use think\admin\storage\AliossStorage;
  20. use think\admin\storage\QiniuStorage;
  21. use think\admin\storage\TxcosStorage;
  22. /**
  23. * 系统参数配置
  24. * Class Config
  25. * @package app\admin\controller
  26. */
  27. class Config extends Controller
  28. {
  29. /**
  30. * 绑定数据表
  31. * @var string
  32. */
  33. protected $table = 'SystemConfig';
  34. /**
  35. * 系统参数配置
  36. * @auth true
  37. * @menu true
  38. */
  39. public function index()
  40. {
  41. $this->title = '系统参数配置';
  42. $this->isSuper = AdminService::instance()->isSuper();
  43. $this->version = ModuleService::instance()->getVersion();
  44. $this->fetch();
  45. }
  46. /**
  47. * 修改系统参数
  48. * @auth true
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function system()
  54. {
  55. $this->_applyFormToken();
  56. if ($this->request->isGet()) {
  57. $this->title = '修改系统参数';
  58. $this->fetch();
  59. } else {
  60. if ($xpath = $this->request->post('xpath')) {
  61. if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]+$/', $xpath)) {
  62. $this->error('后台入口名称需要是由英文字母开头!');
  63. }
  64. if ($xpath !== 'admin' && file_exists($this->app->getBasePath() . $xpath)) {
  65. $this->error("后台入口名称{$xpath}已经存在应用!");
  66. }
  67. SystemService::instance()->setRuntime([$xpath => 'admin']);
  68. }
  69. foreach ($this->request->post() as $name => $value) sysconf($name, $value);
  70. $this->success('修改系统参数成功!', sysuri("{$xpath}/index/index") . '#' . url("{$xpath}/config/index"));
  71. }
  72. }
  73. /**
  74. * 修改文件存储
  75. * @auth true
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function storage()
  81. {
  82. $this->_applyFormToken();
  83. if ($this->request->isGet()) {
  84. $this->type = input('type', 'local');
  85. if ($this->type === 'alioss') {
  86. $this->points = AliossStorage::region();
  87. } elseif ($this->type === 'txcos') {
  88. $this->points = TxcosStorage::region();
  89. } elseif ($this->type === 'qiniu') {
  90. $this->points = QiniuStorage::region();
  91. }
  92. $this->fetch("storage-{$this->type}");
  93. } else {
  94. $post = $this->request->post();
  95. if (!empty($post['storage']['allow_exts'])) {
  96. $exts = array_unique(explode(',', strtolower($post['storage']['allow_exts'])));
  97. if (sort($exts) && in_array('php', $exts)) $this->error('禁止上传可执行的文件!');
  98. $post['storage']['allow_exts'] = join(',', $exts);
  99. }
  100. foreach ($post as $name => $value) sysconf($name, $value);
  101. $this->success('修改文件存储成功!');
  102. }
  103. }
  104. }