GameSomeConfigController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Redis;
  6. class GameSomeConfigController
  7. {
  8. /**
  9. * 个控回报配置列表(可编辑)
  10. */
  11. public function index(Request $request)
  12. {
  13. // 获取游戏ID,默认为0(通用配置)
  14. $gameId = $request->input('game_id', 0);
  15. // 可选的游戏列表
  16. $games = [
  17. 0 => '通用配置',
  18. '921219001' => 'IGT-双砖',
  19. '1519119693' => 'Jokers Jewels',
  20. ];
  21. // 查询指定GameID的配置
  22. $configs = DB::connection('write')
  23. ->table('QPPlatformDB.dbo.GameSomeConfig')
  24. ->where('GameID', $gameId)
  25. ->orderBy('ZMin', 'asc')
  26. ->orderBy('ZMax', 'asc')
  27. ->orderBy('MultiMin', 'asc')
  28. ->get();
  29. return view('admin.game_some_config.index', compact('configs', 'games', 'gameId'));
  30. }
  31. /**
  32. * 批量更新配置(只更新有变动的数据)
  33. */
  34. public function update(Request $request)
  35. {
  36. try {
  37. $configs = $request->input('configs', []);
  38. if (empty($configs)) {
  39. return apiReturnFail('没有需要更新的数据');
  40. }
  41. DB::beginTransaction();
  42. $updatedIds = [];
  43. $updatedCount = 0;
  44. foreach ($configs as $configId => $data) {
  45. // 构建更新数据(只包含提交的字段)
  46. $updateData = [];
  47. if (isset($data['ZMin'])) {
  48. $updateData['ZMin'] = (int)$data['ZMin'];
  49. }
  50. if (isset($data['ZMax'])) {
  51. $updateData['ZMax'] = (int)$data['ZMax'];
  52. }
  53. if (isset($data['MultiMin'])) {
  54. $updateData['MultiMin'] = round((float)$data['MultiMin'], 2);
  55. }
  56. if (isset($data['MultiMax'])) {
  57. $updateData['MultiMax'] = round((float)$data['MultiMax'], 2);
  58. }
  59. // if (isset($data['MultiAvg'])) {
  60. // $updateData['MultiAvg'] = round((float)$data['MultiAvg'], 2);
  61. // }
  62. if (isset($data['Weight'])) {
  63. $updateData['Weight'] = (int)$data['Weight'];
  64. }
  65. if (isset($data['WeightAdjust'])) {
  66. $updateData['WeightAdjust'] = $data['WeightAdjust'];
  67. }
  68. // Status字段不允许修改,已移除
  69. // 只有有数据时才更新
  70. if (!empty($updateData)) {
  71. DB::connection('write')
  72. ->table('QPPlatformDB.dbo.GameSomeConfig')
  73. ->where('ConfigID', $configId)
  74. ->update($updateData);
  75. $updatedIds[] = $configId;
  76. $updatedCount++;
  77. }
  78. }
  79. DB::commit();
  80. \Log::info('个控回报配置更新成功', [
  81. 'admin_id' => $request->session()->get('admin')->id ?? 0,
  82. 'updated_count' => $updatedCount,
  83. 'config_ids' => $updatedIds
  84. ]);
  85. return apiReturnSuc("配置更新成功,共更新 {$updatedCount} 条数据");
  86. } catch (\Exception $e) {
  87. DB::rollBack();
  88. \Log::error('个控回报配置更新失败', [
  89. 'error' => $e->getMessage(),
  90. 'trace' => $e->getTraceAsString()
  91. ]);
  92. return apiReturnFail('更新失败: ' . $e->getMessage());
  93. }
  94. }
  95. }