CommonConfigController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. $defaultConfig = [
  11. ["RechargeMin" => 0, "RechargeMax" => 1, "FreeWinMax" => 1000, "RechargeMaxPercent" => 0, "TaxPercent" => 100],
  12. ["RechargeMin" => 1, "RechargeMax" => 101, "FreeWinMax" => 20, "RechargeMaxPercent" => 80, "TaxPercent" => 100],
  13. ["RechargeMin" => 101, "RechargeMax" => 501, "FreeWinMax" => 100, "RechargeMaxPercent" => 70, "TaxPercent" => 95],
  14. ["RechargeMin" => 501, "RechargeMax" => 1001, "FreeWinMax" => 400, "RechargeMaxPercent" => 60, "TaxPercent" => 90],
  15. ["RechargeMin" => 1001, "RechargeMax" => 10001, "FreeWinMax" => 8000, "RechargeMaxPercent" => 55, "TaxPercent" => 85],
  16. ["RechargeMin" => 10001, "RechargeMax" => 99999999, "FreeWinMax" => 0, "RechargeMaxPercent" => 50, "TaxPercent" => 80]
  17. ];
  18. // 从 Redis 获取公用配置数据
  19. $configData = Redis::get("GameConfigX_Common");
  20. $config = $configData ? json_decode($configData, true) : $defaultConfig;
  21. // 从 Redis 获取库存模式配置数据
  22. $specialConfigData = Redis::get("GameConfigX_Special");
  23. $specialConfig = $specialConfigData ? json_decode($specialConfigData, true) : $defaultConfig;
  24. return view('admin.common_config.index', compact('config', 'specialConfig'));
  25. }
  26. public function update(Request $request)
  27. {
  28. $config = $request->input('config');
  29. $configType = $request->input('config_type', 'common'); // 获取配置类型,默认为 common
  30. $redisKey = $configType === 'special' ? 'GameConfigX_Special' : 'GameConfigX_Common';
  31. \Log::info('公用配置更新请求', [
  32. 'config_type' => $configType,
  33. 'config' => $config,
  34. 'all_data' => $request->all()
  35. ]);
  36. if (!$config) {
  37. \Log::error('公用配置更新失败:参数错误');
  38. return response()->json(['status' => 'error', 'message' => '参数错误']);
  39. }
  40. try {
  41. $configData = json_decode($config, true);
  42. if (json_last_error() !== JSON_ERROR_NONE) {
  43. \Log::error('公用配置更新失败:JSON格式错误', ['error' => json_last_error_msg()]);
  44. throw new \Exception('JSON格式错误: ' . json_last_error_msg());
  45. }
  46. Redis::set($redisKey, $config);
  47. \Log::info('公用配置更新成功', ['redis_key' => $redisKey]);
  48. return response()->json(['status' => 'success', 'message' => '更新成功']);
  49. } catch (\Exception $e) {
  50. \Log::error('公用配置更新失败:异常', ['message' => $e->getMessage()]);
  51. return response()->json(['status' => 'error', 'message' => $e->getMessage()]);
  52. }
  53. }
  54. }