Setting.php 936 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. $list = $this->request->post('form');
  13. $tmp = [];
  14. foreach ($list as $key => $value) {
  15. $tmp[] = [
  16. 'keys' => $key,
  17. 'value' => $value
  18. ];
  19. }
  20. Db::table('setting')->replace()->insertAll($tmp);
  21. $config = array_column($tmp, 'value', 'keys');
  22. Cache::set('webConfig', $config, 300);
  23. return $this->success('ok');
  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. }