Config.php 1.1 KB

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