Config.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/framework
  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. * @throws \think\Exception
  30. * @throws \think\exception\PDOException
  31. */
  32. public function info()
  33. {
  34. $this->applyCsrfToken();
  35. if ($this->request->isGet()) {
  36. $this->title = '系统参数配置';
  37. $this->fetch();
  38. } else {
  39. foreach ($this->request->post() as $k => $v) sysconf($k, $v);
  40. $this->success('系统参数配置成功!');
  41. }
  42. }
  43. /**
  44. * 文件存储配置
  45. * @throws \think\Exception
  46. * @throws \think\exception\PDOException
  47. */
  48. public function file()
  49. {
  50. $this->applyCsrfToken();
  51. if ($this->request->isGet()) {
  52. $this->fetch('file', [
  53. 'title' => '文件存储配置',
  54. 'point' => [
  55. 'oss-cn-hangzhou.aliyuncs.com' => '华东 1 杭州',
  56. 'oss-cn-shanghai.aliyuncs.com' => '华东 2 上海',
  57. 'oss-cn-qingdao.aliyuncs.com' => '华北 1 青岛',
  58. 'oss-cn-beijing.aliyuncs.com' => '华北 2 北京',
  59. 'oss-cn-zhangjiakou.aliyuncs.com' => '华北 3 张家口',
  60. 'oss-cn-huhehaote.aliyuncs.com' => '华北 5 呼和浩特',
  61. 'oss-cn-shenzhen.aliyuncs.com' => '华南 1 深圳',
  62. 'oss-cn-hongkong.aliyuncs.com' => '香港 1',
  63. 'oss-us-west-1.aliyuncs.com' => '美国西部 1 硅谷',
  64. 'oss-us-east-1.aliyuncs.com' => '美国东部 1 弗吉尼亚',
  65. 'oss-ap-southeast-1.aliyuncs.com' => '亚太东南 1 新加坡',
  66. 'oss-ap-southeast-2.aliyuncs.com' => '亚太东南 2 悉尼',
  67. 'oss-ap-southeast-3.aliyuncs.com' => '亚太东南 3 吉隆坡',
  68. 'oss-ap-southeast-5.aliyuncs.com' => '亚太东南 5 雅加达',
  69. 'oss-ap-northeast-1.aliyuncs.com' => '亚太东北 1 日本',
  70. 'oss-ap-south-1.aliyuncs.com' => '亚太南部 1 孟买',
  71. 'oss-eu-central-1.aliyuncs.com' => '欧洲中部 1 法兰克福',
  72. 'oss-eu-west-1.aliyuncs.com' => '英国 1 伦敦',
  73. 'oss-me-east-1.aliyuncs.com' => '中东东部 1 迪拜',
  74. ],
  75. ]);
  76. } else {
  77. $post = $this->request->post();
  78. if (isset($post['storage_type']) && $post['storage_type'] === 'local') {
  79. $exts = array_unique(explode(',', $post['storage_local_exts']));
  80. if (in_array('php', $exts)) $this->error('禁止上传可执行文件到本地服务器!');
  81. $post['storage_local_exts'] = join(',', $exts);
  82. }
  83. foreach ($post as $key => $value) sysconf($key, $value);
  84. if (isset($post['storage_type']) && $post['storage_type'] === 'oss') {
  85. try {
  86. $local = sysconf('storage_oss_domain');
  87. $bucket = $this->request->post('storage_oss_bucket');
  88. $domain = \library\File::instance('oss')->setBucket($bucket);
  89. if (empty($local) || stripos($local, '.aliyuncs.com') !== false) {
  90. sysconf('storage_oss_domain', $domain);
  91. }
  92. $this->success('阿里云OSS存储动态配置成功!');
  93. } catch (\think\exception\HttpResponseException $exception) {
  94. throw $exception;
  95. } catch (\Exception $e) {
  96. $this->error("阿里云OSS存储配置失效,{$e->getMessage()}");
  97. }
  98. } else {
  99. $this->success('文件存储配置成功!');
  100. }
  101. }
  102. }
  103. }