| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class GameTaxController extends Controller
- {
- /**
- * 显示游戏税收比例配置页面
- *
- * @return \Illuminate\View\View
- */
- public function index()
- {
- // 从数据库中获取一个示例值(所有游戏的税收值都是一样的)
- $gameRoom = DB::connection('read')
- ->table('QPPlatformDB.dbo.GameRoomInfo')
- ->select('RevenueRatio')
- ->first();
- // 将千分比转换为百分比显示(例如:50 -> 5%)
- $revenueRatio = $gameRoom ? ($gameRoom->RevenueRatio / 10) : 0;
- return view('admin.game_tax.index', compact('revenueRatio'));
- }
- /**
- * 更新所有游戏的税收比例
- *
- * @param Request $request
- * @return mixed
- */
- public function update(Request $request)
- {
- $revenueRatioPercent = $request->input('revenue_ratio');
- // 验证输入
- if ($revenueRatioPercent === null || $revenueRatioPercent === '') {
- return $this->json(400, '税收比例不能为空');
- }
- // 转换为浮点数
- $revenueRatioPercent = floatval($revenueRatioPercent);
- // 验证范围(0-100)
- if ($revenueRatioPercent < 0 || $revenueRatioPercent > 100) {
- return $this->json(400, '税收比例必须在0-100之间');
- }
- try {
- // 将百分比转换为千分比(例如:5% -> 50)
- $revenueRatioValue = $revenueRatioPercent * 10;
- // 更新所有游戏房间的税收比例
- $affectedRows = DB::connection('write')
- ->table('QPPlatformDB.dbo.GameRoomInfo')
- ->update(['RevenueRatio' => $revenueRatioValue]);
- // 记录日志
- \Log::info('游戏税收比例更新成功', [
- 'revenue_ratio_percent' => $revenueRatioPercent,
- 'revenue_ratio_value' => $revenueRatioValue,
- 'affected_rows' => $affectedRows
- ]);
- return $this->json(200, '更新成功,共更新 ' . $affectedRows . ' 条记录');
- } catch (\Exception $e) {
- \Log::error('游戏税收比例更新失败', [
- 'error' => $e->getMessage(),
- 'trace' => $e->getTraceAsString()
- ]);
- return $this->json(500, '更新失败:' . $e->getMessage());
- }
- }
- }
|