CommonConfigController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Redis;
  6. class CommonConfigController extends Controller
  7. {
  8. public function index()
  9. {
  10. // 从 Redis 获取公用配置数据
  11. $configData = Redis::get("GameConfigX_Common");
  12. $config = $configData ? json_decode($configData, true) : [
  13. ["RechargeMin" => 0, "RechargeMax" => 1, "FreeWinMax" => 1000, "RechargeMaxPercent" => 0, "TaxPercent" => 100],
  14. ["RechargeMin" => 1, "RechargeMax" => 101, "FreeWinMax" => 20, "RechargeMaxPercent" => 80, "TaxPercent" => 100],
  15. ["RechargeMin" => 101, "RechargeMax" => 501, "FreeWinMax" => 100, "RechargeMaxPercent" => 70, "TaxPercent" => 95],
  16. ["RechargeMin" => 501, "RechargeMax" => 1001, "FreeWinMax" => 400, "RechargeMaxPercent" => 60, "TaxPercent" => 90],
  17. ["RechargeMin" => 1001, "RechargeMax" => 10001, "FreeWinMax" => 8000, "RechargeMaxPercent" => 55, "TaxPercent" => 85],
  18. ["RechargeMin" => 10001, "RechargeMax" => 99999999, "FreeWinMax" => 0, "RechargeMaxPercent" => 50, "TaxPercent" => 80]
  19. ];
  20. return view('admin.common_config.index', compact('config'));
  21. }
  22. public function update(Request $request)
  23. {
  24. $config = $request->input('config');
  25. \Log::info('公用配置更新请求', [
  26. 'config' => $config,
  27. 'all_data' => $request->all()
  28. ]);
  29. if (!$config) {
  30. \Log::error('公用配置更新失败:参数错误');
  31. return response()->json(['status' => 'error', 'message' => '参数错误']);
  32. }
  33. try {
  34. $configData = json_decode($config, true);
  35. if (json_last_error() !== JSON_ERROR_NONE) {
  36. \Log::error('公用配置更新失败:JSON格式错误', ['error' => json_last_error_msg()]);
  37. throw new \Exception('JSON格式错误: ' . json_last_error_msg());
  38. }
  39. Redis::set("GameConfigX_Common", $config);
  40. \Log::info('公用配置更新成功');
  41. return response()->json(['status' => 'success', 'message' => '更新成功']);
  42. } catch (\Exception $e) {
  43. \Log::error('公用配置更新失败:异常', ['message' => $e->getMessage()]);
  44. return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
  45. }
  46. }
  47. }