Config.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | framework
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://framework.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/ThinkAdmin
  12. // +----------------------------------------------------------------------
  13. namespace app\admin\controller;
  14. use library\Controller;
  15. /**
  16. * 系统配置
  17. * Class Config
  18. * @package app\admin\controller
  19. */
  20. class Config extends Controller
  21. {
  22. /**
  23. * 默认数据模型
  24. * @var string
  25. */
  26. protected $table = 'SystemConfig';
  27. /**
  28. * 系统参数配置
  29. * @return mixed
  30. * @throws \think\Exception
  31. * @throws \think\exception\PDOException
  32. */
  33. public function info()
  34. {
  35. $this->applyCsrfToken();
  36. $this->title = '系统参数配置';
  37. if ($this->request->isGet()) return $this->fetch();
  38. foreach ($this->request->post() as $k => $v) sysconf($k, $v);
  39. $this->success('系统参数配置保存成功!');
  40. }
  41. /**
  42. * 文件存储配置
  43. * @return string
  44. * @throws \think\Exception
  45. * @throws \think\exception\PDOException
  46. */
  47. public function file()
  48. {
  49. $this->applyCsrfToken();
  50. if ($this->request->isGet()) {
  51. $this->fetch('file', [
  52. 'title' => '文件存储配置',
  53. 'point' => [
  54. 'oss-cn-hangzhou.aliyuncs.com' => '华东 1 杭州',
  55. 'oss-cn-shanghai.aliyuncs.com' => '华东 2 上海',
  56. 'oss-cn-qingdao.aliyuncs.com' => '华北 1 青岛',
  57. 'oss-cn-beijing.aliyuncs.com' => '华北 2 北京',
  58. 'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3 张家口',
  59. 'oss-cn-huhehaote.aliyuncs.com' => '华北 5 呼和浩特',
  60. 'oss-cn-shenzhen.aliyuncs.com' => '华南 1 深圳',
  61. 'oss-cn-hongkong.aliyuncs.com' => '香港 1',
  62. 'oss-us-west-1.aliyuncs.com' => '美国西部 1 硅谷',
  63. 'oss-us-east-1.aliyuncs.com' => '美国东部 1 弗吉尼亚',
  64. 'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1 新加坡',
  65. 'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2 悉尼',
  66. 'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3 吉隆坡',
  67. 'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5 雅加达',
  68. 'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1 日本',
  69. 'oss-ap-south-1.aliyuncs.com' => '亚太南部 1 孟买',
  70. 'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1 法兰克福',
  71. 'oss-eu-west-1.aliyuncs.com' => '英国 1 伦敦',
  72. 'oss-me-east-1.aliyuncs.com' => '中东东部 1 迪拜',
  73. ],
  74. ]);
  75. } else {
  76. $post = $this->request->post();
  77. if (isset($post['storage_type']) && $post['storage_type'] === 'local') {
  78. $exts = array_unique(explode(',', $post['storage_local_exts']));
  79. if (in_array('php', $exts)) $this->error('禁止上传可执行文件到本地服务器!');
  80. $post['storage_local_exts'] = join(',', $exts);
  81. }
  82. foreach ($post as $key => $value) sysconf($key, $value);
  83. if (isset($post['storage_type']) && $post['storage_type'] === 'oss') {
  84. try {
  85. $local = sysconf('storage_oss_domain');
  86. $bucket = $this->request->post('storage_oss_bucket');
  87. $domain = \library\File::instance('oss')->setBucket($bucket);
  88. if (empty($local) || stripos($local, '.aliyuncs.com') !== false) {
  89. sysconf('storage_oss_domain', $domain);
  90. }
  91. $this->success('阿里云OSS存储动态配置成功!');
  92. } catch (\think\exception\HttpResponseException $exception) {
  93. throw $exception;
  94. } catch (\Exception $e) {
  95. $this->error("阿里云OSS存储配置失效,{$e->getMessage()}");
  96. }
  97. } else {
  98. $this->success('文件存储配置保存成功!');
  99. }
  100. }
  101. }
  102. }