Setting.php 908 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 getSetting(): \think\response\Json
  26. {
  27. $admin = $this->getAdmin();
  28. $info = SettingModel::Config();
  29. if ($info) {
  30. return $this->success('ok', $info);
  31. }
  32. return $this->error('empty');
  33. }
  34. }