SystemController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Module\Base;
  5. use App\Module\Users;
  6. use Request;
  7. /**
  8. * @apiDefine system
  9. *
  10. * 系统
  11. */
  12. class SystemController extends Controller
  13. {
  14. public function __invoke($method, $action = '')
  15. {
  16. $app = $method ? $method : 'main';
  17. if ($action) {
  18. $app .= "__" . $action;
  19. }
  20. return (method_exists($this, $app)) ? $this->$app() : Base::ajaxError("404 not found (" . str_replace("__", "/", $app) . ").");
  21. }
  22. /**
  23. * 获取设置、保存设置
  24. *
  25. * @apiParam {String} type
  26. * - get: 获取(默认)
  27. * - save: 保存设置(参数:logo、github、reg)
  28. */
  29. public function setting()
  30. {
  31. $type = trim(Request::input('type'));
  32. if ($type == 'save') {
  33. $user = Users::authE();
  34. if (Base::isError($user)) {
  35. return $user;
  36. } else {
  37. $user = $user['data'];
  38. }
  39. if (Base::isError(Users::identity('admin'))) {
  40. return Base::retError('权限不足!', [], -1);
  41. }
  42. $all = Request::input();
  43. foreach ($all AS $key => $value) {
  44. if (!in_array($key, ['logo', 'github', 'reg'])) {
  45. unset($all[$key]);
  46. }
  47. }
  48. $all['logo'] = is_array($all['logo']) ? $all['logo'][0]['path'] : $all['logo'];
  49. $setting = Base::setting('system', Base::newTrim($all));
  50. } else {
  51. $setting = Base::setting('system');
  52. }
  53. $setting['logo'] = Base::fillUrl($setting['logo']);
  54. return Base::retSuccess('success', $setting ? $setting : json_decode('{}'));
  55. }
  56. }