Setting.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. (new \app\controller\admin\Index(app()))->authorization();
  24. return $this->success('保存成功');
  25. }
  26. function refreshCache(): \think\response\Json
  27. {
  28. $this->getAdmin();
  29. Cache::delete('webConfig');
  30. return $this->success('刷新成功');
  31. }
  32. function getSetting(): \think\response\Json
  33. {
  34. $admin = $this->getAdmin();
  35. $role = $this->request->post('role', []);
  36. $info = SettingModel::Config();
  37. $tmp = [];
  38. $url = '';
  39. if (in_array('ext_name', $role)) {
  40. if (file_exists(public_path() . '/browserExt.zip')) {
  41. $url = '/browserExt.zip';
  42. }
  43. }
  44. if ($info) {
  45. if (count($role) > 0) {
  46. foreach ($info as $key => $val) {
  47. if (in_array($key, $role)) {
  48. $tmp[$key] = $val;
  49. }
  50. }
  51. }
  52. return json(['msg' => "ok", "data" => $tmp, 'success' => $this->auth, 'code' => 1, "url" => $url]);
  53. }
  54. return json(['msg' => 'ok', 'data' => false, 'success' => $this->auth, 'code' => 0, 'url' => $url]);
  55. }
  56. function delExt(): \think\response\Json
  57. {
  58. $this->getAdmin();
  59. if (file_exists(public_path() . '/browserExt.zip')) {
  60. unlink(public_path() . '/browserExt.zip');
  61. }
  62. return $this->success("ok");
  63. }
  64. }