Config.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\admin\controller\shop;
  3. use app\common\controller\Backend;
  4. use think\addons\Service;
  5. use think\Exception;
  6. /**
  7. * 系统配置
  8. *
  9. * @icon fa fa-gears
  10. */
  11. class Config extends Backend
  12. {
  13. /**
  14. * 查看
  15. */
  16. public function index()
  17. {
  18. $name = 'shop';
  19. $info = get_addon_info($name);
  20. $config = get_addon_fullconfig($name);
  21. if (!$info) {
  22. $this->error(__('No Results were found'));
  23. }
  24. if ($this->request->isPost()) {
  25. $params = $this->request->post("row/a", [], 'trim');
  26. if ($params) {
  27. foreach ($config as $k => &$v) {
  28. if (isset($params[$v['name']])) {
  29. if ($v['type'] == 'array') {
  30. $params[$v['name']] = is_array($params[$v['name']]) ? $params[$v['name']] : (array)json_decode($params[$v['name']], true);
  31. $value = $params[$v['name']];
  32. } else {
  33. $value = is_array($params[$v['name']]) ? implode(',', $params[$v['name']]) : $params[$v['name']];
  34. }
  35. $v['value'] = $value;
  36. }
  37. }
  38. try {
  39. //更新配置文件
  40. set_addon_fullconfig($name, $config);
  41. Service::refresh();
  42. $this->success();
  43. } catch (Exception $e) {
  44. $this->error(__($e->getMessage()));
  45. }
  46. }
  47. $this->error(__('Parameter %s can not be empty', ''));
  48. }
  49. $tips = [];
  50. foreach ($config as $index => &$item) {
  51. if ($item['name'] == '__tips__') {
  52. $tips = $item;
  53. unset($config[$index]);
  54. }
  55. }
  56. $this->view->assign("addon", ['info' => $info, 'config' => $config, 'tips' => $tips]);
  57. $configFile = ADDON_PATH . $name . DS . 'config.html';
  58. $viewFile = is_file($configFile) ? $configFile : '';
  59. return $this->view->fetch($viewFile);
  60. }
  61. }