GameTaxController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\DB;
  6. class GameTaxController extends Controller
  7. {
  8. /**
  9. * 显示游戏税收比例配置页面
  10. *
  11. * @return \Illuminate\View\View
  12. */
  13. public function index()
  14. {
  15. // 从数据库中获取一个示例值(所有游戏的税收值都是一样的)
  16. $gameRoom = DB::connection('read')
  17. ->table('QPPlatformDB.dbo.GameRoomInfo')
  18. ->select('RevenueRatio')
  19. ->first();
  20. // 将千分比转换为百分比显示(例如:50 -> 5%)
  21. $revenueRatio = $gameRoom ? ($gameRoom->RevenueRatio / 10) : 0;
  22. return view('admin.game_tax.index', compact('revenueRatio'));
  23. }
  24. /**
  25. * 更新所有游戏的税收比例
  26. *
  27. * @param Request $request
  28. * @return mixed
  29. */
  30. public function update(Request $request)
  31. {
  32. $revenueRatioPercent = $request->input('revenue_ratio');
  33. // 验证输入
  34. if ($revenueRatioPercent === null || $revenueRatioPercent === '') {
  35. return $this->json(400, '税收比例不能为空');
  36. }
  37. // 转换为浮点数
  38. $revenueRatioPercent = floatval($revenueRatioPercent);
  39. // 验证范围(0-100)
  40. if ($revenueRatioPercent < 0 || $revenueRatioPercent > 100) {
  41. return $this->json(400, '税收比例必须在0-100之间');
  42. }
  43. try {
  44. // 将百分比转换为千分比(例如:5% -> 50)
  45. $revenueRatioValue = $revenueRatioPercent * 10;
  46. // 更新所有游戏房间的税收比例
  47. $affectedRows = DB::connection('write')
  48. ->table('QPPlatformDB.dbo.GameRoomInfo')
  49. ->update(['RevenueRatio' => $revenueRatioValue]);
  50. // 记录日志
  51. \Log::info('游戏税收比例更新成功', [
  52. 'revenue_ratio_percent' => $revenueRatioPercent,
  53. 'revenue_ratio_value' => $revenueRatioValue,
  54. 'affected_rows' => $affectedRows
  55. ]);
  56. return $this->json(200, '更新成功,共更新 ' . $affectedRows . ' 条记录');
  57. } catch (\Exception $e) {
  58. \Log::error('游戏税收比例更新失败', [
  59. 'error' => $e->getMessage(),
  60. 'trace' => $e->getTraceAsString()
  61. ]);
  62. return $this->json(500, '更新失败:' . $e->getMessage());
  63. }
  64. }
  65. }