截流自动化的商城平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

StorageConfig.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\admin\controller\setting;
  20. use app\admin\validate\setting\StorageValidate;
  21. use app\common\basics\AdminBase;
  22. use app\common\server\ConfigServer;
  23. use app\common\server\JsonServer;
  24. /**
  25. * 上传设置
  26. * Class StorageConfig
  27. * @package app\admin\controller
  28. */
  29. class StorageConfig extends AdminBase
  30. {
  31. /**
  32. * Notes: 存储引擎列表
  33. * @author 张无忌(2021/2/22 11:43)
  34. * @return mixed
  35. */
  36. public function lists()
  37. {
  38. if ($this->request->isAjax()) {
  39. $default = ConfigServer::get('storage', 'default', '');
  40. $data = [
  41. [
  42. 'name' => '本地存储',
  43. 'path' => '存储在本地服务器',
  44. 'engine' => 'local',
  45. 'status' => $default == 'local' ? 1 : 0
  46. ],
  47. [
  48. 'name' => '七牛云存储',
  49. 'path' => '存储在七牛云,请前往七牛云开通存储服务',
  50. 'engine' => 'qiniu',
  51. 'status' => $default == 'qiniu' ? 1 : 0
  52. ],
  53. [
  54. 'name' => '阿里云OSS',
  55. 'path' => '存储在阿里云,请前往阿里云开通存储服务',
  56. 'engine' => 'aliyun',
  57. 'status' => $default == 'aliyun' ? 1 : 0
  58. ],
  59. [
  60. 'name' => '腾讯云OSS',
  61. 'path' => '存储在腾讯云,请前往腾讯云开通存储服务',
  62. 'engine' => 'qcloud',
  63. 'status' => $default == 'qcloud' ? 1 : 0
  64. ]
  65. ];
  66. return JsonServer::success('获取成功', ['lists' => $data]);
  67. }
  68. return view();
  69. }
  70. /**
  71. * Notes: 编辑存储引擎
  72. * @author 张无忌(2021/2/22 11:43)
  73. * @return mixed
  74. */
  75. public function edit()
  76. {
  77. if ($this->request->isAjax()) {
  78. $engine= $this->request->post('engine');
  79. $post = $this->request->post();
  80. if ($engine != 'local') {
  81. $post['domain'] = $post[$engine . '_domain'] ?? '';
  82. $validate = new StorageValidate();
  83. if (! $validate->scene('edit')->check($post)) {
  84. return JsonServer::error('设置失败:' . $validate->getError());
  85. }
  86. }
  87. if ($engine === 'qiniu') {
  88. try {
  89. ConfigServer::set('storage_engine', 'qiniu', [
  90. 'bucket' => $post['qiniu_bucket'],
  91. 'access_key' => $post['qiniu_ak'],
  92. 'secret_key' => $post['qiniu_sk'],
  93. 'domain' => $post['qiniu_domain']
  94. ]);
  95. } catch (\Exception $e) {
  96. return JsonServer::error('设置失败:'.$e->getMessage());
  97. }
  98. return JsonServer::success('设置成功');
  99. } elseif ($engine === 'aliyun') {
  100. try {
  101. ConfigServer::set('storage_engine', 'aliyun', [
  102. 'bucket' => $post['aliyun_bucket'],
  103. 'access_key_id' => $post['aliyun_ak'],
  104. 'access_key_secret' => $post['aliyun_sk'],
  105. 'domain' => $post['aliyun_domain']
  106. ]);
  107. } catch (\Exception $e) {
  108. return JsonServer::error('设置失败:'.$e->getMessage());
  109. }
  110. return JsonServer::success('设置成功');
  111. } elseif ($engine === 'qcloud') {
  112. try {
  113. ConfigServer::set('storage_engine', 'qcloud', [
  114. 'bucket' => $post['qcloud_bucket'],
  115. 'region' => $post['qcloud_region'],
  116. 'secret_id' => $post['qcloud_ak'],
  117. 'secret_key' => $post['qcloud_sk'],
  118. 'domain' => $post['qcloud_domain']
  119. ]);
  120. } catch (\Exception $e) {
  121. return JsonServer::error('设置失败:'.$e->getMessage());
  122. }
  123. return JsonServer::success('设置成功');
  124. }
  125. return JsonServer::error('您设置的存储引擎不存在');
  126. }
  127. $engine = $this->request->get('engine');
  128. $storage = [
  129. 'qiniu' => ConfigServer::get('storage_engine', 'qiniu', [
  130. 'bucket' => '',
  131. 'access_key' => '',
  132. 'secret_key' => '',
  133. 'domain' => 'http://'
  134. ]),
  135. 'aliyun' => ConfigServer::get('storage_engine', 'aliyun', [
  136. 'bucket' => '',
  137. 'access_key_id' => '',
  138. 'access_key_secret' => '',
  139. 'domain' => 'http://'
  140. ]),
  141. 'qcloud' => ConfigServer::get('storage_engine', 'qcloud', [
  142. 'bucket' => '',
  143. 'region' => '',
  144. 'secret_id' => '',
  145. 'secret_key' => '',
  146. 'domain' => 'http://'
  147. ])
  148. ];
  149. return view('', [
  150. 'engine' => $engine,
  151. 'storage' => $storage,
  152. ]);
  153. }
  154. /**
  155. * Notes: 切换存储引擎
  156. * @author 张无忌(2021/2/22 11:43)
  157. */
  158. public function changeEngine()
  159. {
  160. if ($this->request->isAjax()) {
  161. $post = $this->request->post();
  162. try {
  163. ConfigServer::set('storage', 'default', $post['engine']);
  164. } catch (\Exception $e) {
  165. return JsonServer::error('切换失败:'.$e->getMessage());
  166. }
  167. return JsonServer::success('切换成功');
  168. }
  169. }
  170. }