SettingServiceProvider.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Providers;
  3. use App\Channels\BarkChannel;
  4. use App\Channels\ServerChanChannel;
  5. use App\Models\Config;
  6. use Illuminate\Support\ServiceProvider;
  7. use NotificationChannels\BearyChat\BearyChatChannel;
  8. use NotificationChannels\Telegram\TelegramChannel;
  9. class SettingServiceProvider extends ServiceProvider
  10. {
  11. public function boot()
  12. {
  13. $toApp = collect([
  14. 'geetest_id' => 'geetest.id',
  15. 'geetest_key' => 'geetest.key',
  16. 'google_captcha_secret' => 'NoCaptcha.secret',
  17. 'google_captcha_sitekey' => 'NoCaptcha.sitekey',
  18. 'hcaptcha_secret' => 'HCaptcha.secret',
  19. 'hcaptcha_sitekey' => 'HCaptcha.sitekey',
  20. ]);
  21. $notifications = collect([
  22. 'account_expire_notification',
  23. 'data_anomaly_notification',
  24. 'data_exhaust_notification',
  25. 'node_blocked_notification',
  26. 'node_daily_notification',
  27. 'node_offline_notification',
  28. 'password_reset_notification',
  29. 'payment_received_notification',
  30. 'ticket_closed_notification',
  31. 'ticket_created_notification',
  32. 'ticket_replied_notification',
  33. ]);
  34. $payments = ['is_AliPay', 'is_QQPay', 'is_WeChatPay', 'is_otherPay'];
  35. $settings = Config::all();
  36. $modified = $settings
  37. ->whereNotIn('name', $toApp->keys()->merge($notifications)) // 设置一般系统选项
  38. ->pluck('value', 'name')
  39. ->merge($settings->whereIn('name', $notifications)->pluck('value', 'name')->map(function ($item) {
  40. return self::setChannel(json_decode($item, true) ?? []);
  41. })) // 设置通知相关选项
  42. ->merge(collect(['is_onlinePay' => $settings->whereIn('name', $payments)->pluck('value')->filter()->isNotEmpty()])) // 设置在线支付开关
  43. ->sortKeys()
  44. ->toArray();
  45. config(['settings' => $modified]); // 设置系统参数
  46. $settings->whereIn('name', $toApp->keys())->pluck('value', 'name')->each(function ($item, $key) use ($toApp) {
  47. config([$toApp[$key] => $item]); // 设置PHP软件包相关配置
  48. });
  49. collect([
  50. 'website_name' => 'app.name',
  51. 'website_url' => 'app.url',
  52. ])->each(function ($item, $key) {
  53. config([$item => config('settings.'.$key)]); // 设置APP有关的选项
  54. });
  55. }
  56. private static function setChannel(array $channels)
  57. {
  58. return collect([
  59. 'telegram' => TelegramChannel::class,
  60. 'beary' => BearyChatChannel::class,
  61. 'bark' => BarkChannel::class,
  62. 'serverChan' => ServerChanChannel::class,
  63. ])->each(function ($item, $key) use ($channels) {
  64. if (array_key_exists($key, $channels)) {
  65. $channels[$key] = $item;
  66. }
  67. });
  68. }
  69. }