Config.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\controller;
  3. use app\BaseController;
  4. use app\model\ConfigModel;
  5. class Config extends BaseController
  6. {
  7. public function update(): \think\response\Json
  8. {
  9. $user = $this->getUser(true);
  10. if ($user) {
  11. $config = $this->request->post("config", []);
  12. if ($config) {
  13. $is = ConfigModel::where("user_id", $user['user_id'])->find();
  14. if ($is) {
  15. $is->config = $config;
  16. $is->save();
  17. } else {
  18. ConfigModel::create(["user_id" => $user['user_id'], "config" => $config]);
  19. }
  20. return $this->success('ok');
  21. }
  22. }
  23. return $this->error('保存失败');
  24. }
  25. public function get(): \think\response\Json
  26. {
  27. $user = $this->getUser();
  28. if ($user) {
  29. $data = ConfigModel::find($user['user_id']);
  30. if ($data) {
  31. return $this->success("ok", $data['config']);
  32. }
  33. }
  34. return $this->error('not Config');
  35. }
  36. }