FeatureController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controllers\Admin\Setting;
  4. use App\Controllers\BaseController;
  5. use App\Models\Config;
  6. use Exception;
  7. final class FeatureController extends BaseController
  8. {
  9. private static array $update_field = [
  10. 'display_detect_log',
  11. 'display_docs',
  12. 'display_docs_only_for_paid_user',
  13. 'traffic_log',
  14. 'traffic_log_retention_days',
  15. 'subscribe_log',
  16. 'subscribe_log_retention_days',
  17. 'notify_new_subscribe',
  18. 'login_log',
  19. 'notify_new_login',
  20. 'enable_checkin',
  21. 'checkin_min',
  22. 'checkin_max',
  23. ];
  24. /**
  25. * @throws Exception
  26. */
  27. public function index($request, $response, $args)
  28. {
  29. $settings = Config::getClass('feature');
  30. return $response->write(
  31. $this->view()
  32. ->assign('update_field', self::$update_field)
  33. ->assign('settings', $settings)
  34. ->fetch('admin/setting/feature.tpl')
  35. );
  36. }
  37. public function save($request, $response, $args)
  38. {
  39. foreach (self::$update_field as $item) {
  40. if (! Config::set($item, $request->getParam($item))) {
  41. return $response->withJson([
  42. 'ret' => 0,
  43. 'msg' => '保存 ' . $item . ' 时出错',
  44. ]);
  45. }
  46. }
  47. return $response->withJson([
  48. 'ret' => 1,
  49. 'msg' => '保存成功',
  50. ]);
  51. }
  52. }