ProtectController.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Facade\TableName;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Redis;
  7. class ProtectController
  8. {
  9. // 保护配置列表
  10. public function protect_config_info()
  11. {
  12. $list = DB::connection('write')->table(TableName::QPPlatformDB() . 'ProtectConfigInfo')->get();
  13. return view('admin.protect.protect_config_info', compact('list'));
  14. }
  15. // 保护配置修改
  16. public function protect_config_info_update(Request $request, $ID)
  17. {
  18. if ($request->isMethod('post')) {
  19. $post = $request->post();
  20. $post = array_map(function ($val) {
  21. return (int)$val;
  22. }, $post);
  23. DB::connection('write')->table(TableName::QPPlatformDB() . 'ProtectConfigInfo')
  24. ->where('ID', $ID)
  25. ->update($post);
  26. return apiReturnSuc();
  27. } else {
  28. $info = DB::connection('write')->table(TableName::QPPlatformDB() . 'ProtectConfigInfo')->where('ID', $ID)->first();
  29. return view('admin.protect.protect_config_info_update', compact('info'));
  30. }
  31. }
  32. // 免费保护配置
  33. public function free_protect_config()
  34. {
  35. $configData = Redis::get("FreeProtectConfig");
  36. $config = $configData ? json_decode($configData, true) : [
  37. "ProtectScore" => 3,
  38. "ScoreBetRatio" => 3,
  39. "ScoreBet" => 10,
  40. "ProtectRounds" => [40, 100],
  41. "ProtectRoundsLoop" => 100,
  42. "ProtectRoundsRatio" => 10
  43. ];
  44. return view('admin.protect.free_protect_config', compact('config'));
  45. }
  46. // 免费保护配置修改
  47. public function free_protect_config_update(Request $request)
  48. {
  49. if ($request->isMethod('post')) {
  50. $config = $request->input('config');
  51. \Log::info('免费保护配置更新请求', [
  52. 'config' => $config,
  53. 'all_data' => $request->all()
  54. ]);
  55. if (!$config) {
  56. \Log::error('免费保护配置更新失败:参数错误');
  57. return response()->json(['status' => 'error', 'message' => '参数错误']);
  58. }
  59. try {
  60. $configData = json_decode($config, true);
  61. if (json_last_error() !== JSON_ERROR_NONE) {
  62. \Log::error('免费保护配置更新失败:JSON格式错误', ['error' => json_last_error_msg()]);
  63. throw new \Exception('JSON格式错误: ' . json_last_error_msg());
  64. }
  65. Redis::set("FreeProtectConfig", $config);
  66. \Log::info('免费保护配置更新成功');
  67. return response()->json(['status' => 'success', 'message' => '更新成功']);
  68. } catch (\Exception $e) {
  69. \Log::error('免费保护配置更新失败:异常', ['message' => $e->getMessage()]);
  70. return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
  71. }
  72. } else {
  73. $configData = Redis::get("FreeProtectConfig");
  74. $config = $configData ? json_decode($configData, true) : [
  75. "ProtectScore" => 3,
  76. "ScoreBetRatio" => 3,
  77. "ScoreBet" => 10,
  78. "ProtectRounds" => [40, 100],
  79. "ProtectRoundsLoop" => 100,
  80. "ProtectRoundsRatio" => 10
  81. ];
  82. return view('admin.protect.free_protect_config_update', compact('config'));
  83. }
  84. }
  85. }