ConfigController.php 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Requests\Admin\ConfigSave;
  4. use Illuminate\Http\Request;
  5. use App\Utils\Dict;
  6. use App\Http\Controllers\Controller;
  7. class ConfigController extends Controller
  8. {
  9. public function fetch()
  10. {
  11. // TODO: default should be in Dict
  12. return response([
  13. 'data' => [
  14. 'invite' => [
  15. 'invite_force' => (int)config('v2board.invite_force', 0),
  16. 'invite_commission' => config('v2board.invite_commission', 10),
  17. 'invite_gen_limit' => config('v2board.invite_gen_limit', 5),
  18. 'invite_never_expire' => config('v2board.invite_never_expire', 0)
  19. ],
  20. 'site' => [
  21. 'safe_mode_enable' => (int)config('v2board.safe_mode_enable', 0),
  22. 'stop_register' => (int)config('v2board.stop_register', 0),
  23. 'email_verify' => (int)config('v2board.email_verify', 0),
  24. 'app_name' => config('v2board.app_name', 'V2Board'),
  25. 'app_description' => config('v2board.app_description', 'V2Board is best!'),
  26. 'app_url' => config('v2board.app_url'),
  27. 'subscribe_url' => config('v2board.subscribe_url'),
  28. 'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0),
  29. 'try_out_hour' => (int)config('v2board.try_out_hour', 1),
  30. 'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0),
  31. 'email_whitelist_suffix' => config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT)
  32. ],
  33. 'subscribe' => [
  34. 'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
  35. 'reset_traffic_method' => (int)config('v2board.reset_traffic_method', 0),
  36. 'renew_reset_traffic_enable' => (int)config('v2board.renew_reset_traffic_enable', 1)
  37. ],
  38. 'pay' => [
  39. // alipay
  40. 'alipay_enable' => (int)config('v2board.alipay_enable'),
  41. 'alipay_appid' => config('v2board.alipay_appid'),
  42. 'alipay_pubkey' => config('v2board.alipay_pubkey'),
  43. 'alipay_privkey' => config('v2board.alipay_privkey'),
  44. // stripe
  45. 'stripe_alipay_enable' => (int)config('v2board.stripe_alipay_enable', 0),
  46. 'stripe_wepay_enable' => (int)config('v2board.stripe_wepay_enable', 0),
  47. 'stripe_sk_live' => config('v2board.stripe_sk_live'),
  48. 'stripe_pk_live' => config('v2board.stripe_pk_live'),
  49. 'stripe_webhook_key' => config('v2board.stripe_webhook_key'),
  50. 'stripe_currency' => config('v2board.stripe_currency', 'hkd'),
  51. // bitpayx
  52. 'bitpayx_enable' => (int)config('v2board.bitpayx_enable', 0),
  53. 'bitpayx_appsecret' => config('v2board.bitpayx_appsecret'),
  54. // paytaro
  55. 'paytaro_enable' => (int)config('v2board.paytaro_enable', 0),
  56. 'paytaro_app_id' => config('v2board.paytaro_app_id'),
  57. 'paytaro_app_secret' => config('v2board.paytaro_app_secret')
  58. ],
  59. 'frontend' => [
  60. 'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
  61. 'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'),
  62. 'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'),
  63. 'frontend_background_url' => config('v2board.frontend_background_url')
  64. ],
  65. 'server' => [
  66. 'server_token' => config('v2board.server_token'),
  67. 'server_license' => config('v2board.server_license')
  68. ],
  69. 'tutorial' => [
  70. 'apple_id' => config('v2board.apple_id')
  71. ]
  72. ]
  73. ]);
  74. }
  75. public function save(ConfigSave $request)
  76. {
  77. $data = $request->input();
  78. $array = \Config::get('v2board');
  79. foreach ($data as $k => $v) {
  80. if (!in_array($k, array_keys(ConfigSave::RULES))) {
  81. abort(500, '参数' . $k . '不在规则内,禁止修改');
  82. }
  83. $array[$k] = $v;
  84. }
  85. $data = var_export($array, 1);
  86. if (!\File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) {
  87. abort(500, '修改失败');
  88. }
  89. \Artisan::call('config:cache');
  90. return response([
  91. 'data' => true
  92. ]);
  93. }
  94. }