ManageController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Controllers\Admin\Server;
  3. use App\Services\ServerService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Support\Facades\DB;
  7. class ManageController extends Controller
  8. {
  9. public function getNodes(Request $request)
  10. {
  11. $serverService = new ServerService();
  12. return response([
  13. 'data' => $serverService->getAllServers()
  14. ]);
  15. }
  16. public function sort(Request $request)
  17. {
  18. ini_set('post_max_size', '1m');
  19. $params = $request->only(
  20. 'shadowsocks',
  21. 'vmess',
  22. 'trojan',
  23. 'hysteria'
  24. ) ?? [];
  25. DB::beginTransaction();
  26. foreach ($params as $k => $v) {
  27. $model = 'App\\Models\\Server' . ucfirst($k);
  28. foreach($v as $id => $sort) {
  29. if (!$model::find($id)->update(['sort' => $sort])) {
  30. DB::rollBack();
  31. abort(500, '保存失败');
  32. }
  33. }
  34. }
  35. DB::commit();
  36. return response([
  37. 'data' => true
  38. ]);
  39. }
  40. }