Config.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\SystemService;
  18. /**
  19. * 系统参数配置
  20. * Class Config
  21. * @package app\admin\controller
  22. */
  23. class Config extends Controller
  24. {
  25. /**
  26. * 绑定数据表
  27. * @var string
  28. */
  29. protected $table = 'SystemConfig';
  30. /**
  31. * 阿里数据中心
  32. * @var array
  33. */
  34. protected $points = [
  35. 'oss-cn-hangzhou.aliyuncs.com' => '华东 1(杭州)',
  36. 'oss-cn-shanghai.aliyuncs.com' => '华东 2(上海)',
  37. 'oss-cn-qingdao.aliyuncs.com' => '华北 1(青岛)',
  38. 'oss-cn-beijing.aliyuncs.com' => '华北 2(北京)',
  39. 'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3(张家口)',
  40. 'oss-cn-huhehaote.aliyuncs.com' => '华北 5(呼和浩特)',
  41. 'oss-cn-shenzhen.aliyuncs.com' => '华南 1(深圳)',
  42. 'oss-cn-chengdu.aliyuncs.com' => '西南 1(成都)',
  43. 'oss-cn-hongkong.aliyuncs.com' => '中国(香港)',
  44. 'oss-us-west-1.aliyuncs.com' => '美国西部 1(硅谷)',
  45. 'oss-us-east-1.aliyuncs.com' => '美国东部 1(弗吉尼亚)',
  46. 'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1(新加坡)',
  47. 'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2(悉尼)',
  48. 'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3(吉隆坡)',
  49. 'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5(雅加达)',
  50. 'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1(日本)',
  51. 'oss-ap-south-1.aliyuncs.com' => '亚太南部 1(孟买)',
  52. 'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1(法兰克福)',
  53. 'oss-eu-west-1.aliyuncs.com' => '英国(伦敦)',
  54. 'oss-me-east-1.aliyuncs.com' => '中东东部 1(迪拜)',
  55. ];
  56. /**
  57. * 系统参数配置
  58. * @auth true
  59. * @menu true
  60. */
  61. public function index()
  62. {
  63. $this->title = '系统参数配置';
  64. $this->isSuper = AdminService::instance()->isSuper();
  65. $this->fetch();
  66. }
  67. /**
  68. * 修改系统参数
  69. * @auth true
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public function system()
  75. {
  76. $this->_applyFormToken();
  77. if ($this->request->isGet()) {
  78. $this->title = '修改系统参数';
  79. $this->fetch();
  80. } else {
  81. if ($xpath = $this->request->post('xpath')) {
  82. if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]+$/', $xpath)) {
  83. $this->error('后台入口名称需要是由英文字母开头!');
  84. }
  85. if ($xpath !== 'admin' && file_exists($this->app->getBasePath() . $xpath)) {
  86. $this->error("后台入口名称{$xpath}已经存在应用!");
  87. }
  88. SystemService::instance()->setRuntime([$xpath => 'admin']);
  89. }
  90. foreach ($this->request->post() as $name => $value) sysconf($name, $value);
  91. $this->success('修改系统参数成功!', sysuri("{$xpath}/index/index") . '#' . url("{$xpath}/config/index"));
  92. }
  93. }
  94. /**
  95. * 修改文件存储
  96. * @auth true
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\DbException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. */
  101. public function storage()
  102. {
  103. $this->_applyFormToken();
  104. if ($this->request->isGet()) {
  105. $this->type = input('type', 'local');
  106. $this->fetch("storage-{$this->type}");
  107. } else {
  108. $post = $this->request->post();
  109. if (!empty($post['storage']['allow_exts'])) {
  110. $exts = array_unique(explode(',', strtolower($post['storage']['allow_exts'])));
  111. if (sort($exts) && in_array('php', $exts)) $this->error('禁止上传可执行的文件!');
  112. $post['storage']['allow_exts'] = join(',', $exts);
  113. }
  114. foreach ($post as $name => $value) sysconf($name, $value);
  115. $this->success('修改文件存储成功!');
  116. }
  117. }
  118. }