Setting.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\SettingModel;
  5. use think\facade\Cache;
  6. use think\facade\Db;
  7. class Setting extends BaseController
  8. {
  9. function saveSetting(): \think\response\Json
  10. {
  11. $this->getAdmin();
  12. is_demo_mode(true);
  13. $list = $this->request->post('form');
  14. $tmp = [];
  15. foreach ($list as $key => $value) {
  16. $tmp[] = [
  17. 'keys' => $key,
  18. 'value' => $value
  19. ];
  20. }
  21. Db::table('setting')->replace()->insertAll($tmp);
  22. Cache::delete('webConfig');
  23. return $this->success('保存成功');
  24. }
  25. function refreshCache(): \think\response\Json
  26. {
  27. $this->getAdmin();
  28. Cache::delete('webConfig');
  29. return $this->success('刷新成功');
  30. }
  31. function getSetting(): \think\response\Json
  32. {
  33. $admin = $this->getAdmin();
  34. $info = SettingModel::Config();
  35. if ($info) {
  36. return $this->success('ok', $info);
  37. }
  38. return $this->error('empty');
  39. }
  40. }