SysConfig.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\common\AdminController;
  4. use think\facade\Db;
  5. /**
  6. * Description of SysConfig
  7. *
  8. * @author sgq
  9. */
  10. class SysConfig extends AdminController {
  11. private $valid_key = ["register"];
  12. public function index() {
  13. if ($this->request->isPost()) {
  14. $params = $this->request->param();
  15. $data = [];
  16. foreach ($params as $key => $value) {
  17. if (in_array($key, $this->valid_key)) {
  18. $_config = Db::table("sys_config")->where("key", $key)->find();
  19. if ($_config) {
  20. $data[] = ["id" => $_config["id"], "value" => json_encode($value), "updateTime" => date("Y-m-d H:i:s"), "updateUser" => session("user")["uid"]];
  21. } else {
  22. $data[] = ["key" => $key, "value" => json_encode($value), "createTime" => date("Y-m-d H:i:s"), "createUser" => session("user")["uid"]];
  23. }
  24. }
  25. }
  26. $model = new \app\common\model\SysConfig();
  27. $model->saveAll($data);
  28. $res = ["code" => 200, "msg" => "保存成功"];
  29. echo sprintf("<script>parent.SysConfig.callback(%s);</script>", json_encode($res));
  30. exit;
  31. }
  32. $configs = \think\facade\Db::table("sys_config")->select();
  33. $tmp = [];
  34. foreach ($configs as $config) {
  35. $tmp[$config["key"]] = json_decode($config["value"], true);
  36. }unset($config);
  37. return view("", ["config" => $tmp]);
  38. }
  39. }