ConfigController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\AppSwitch;
  5. use App\Util;
  6. use Illuminate\Http\Request;
  7. class ConfigController extends Controller
  8. {
  9. public function index(Request $request)
  10. {
  11. $channel = $request->input('channel');
  12. if(!isset($channel)){
  13. $channel = $request->input('Channel');
  14. }
  15. if(!isset($channel)){
  16. $pack=Util::getPackageByURL();
  17. if(isset($pack)){
  18. $channel=$pack['channel'];
  19. if($channel!=103)$channel=-1;
  20. }
  21. }else if(strstr("PackageName",$channel)){
  22. $channel=explode("&",$channel)[0];
  23. }
  24. $defaultSwitches = AppSwitch::query()->where('channel', -1)
  25. ->pluck('status', 'name');
  26. $channelSwitches = [];
  27. if ($channel && $channel != -1) {
  28. $channelSwitches = AppSwitch::query()->where('channel', $channel)
  29. ->pluck('status', 'name');
  30. }
  31. $switches = array_merge(
  32. json_decode(json_encode($defaultSwitches), true),
  33. json_decode(json_encode($channelSwitches), true)
  34. );
  35. return apiReturnSuc([
  36. 'switches' => $switches,
  37. ]);
  38. }
  39. }