feat: 重构代码架构 + 新增报表/跟单/输赢统计功能
- 拆分 HomeController → TransactionController, ReportWebController, FollowPlanController - 新增 Service 层: TransactionService, ReportService, FollowPlanService - pk10.php JS 抽离为 4 个独立文件 (sound/race/bet/poll) - 前台新增报表查询页面 (/report) + 跟单计划页面 (/follow-plan) - 后台新增跟单计划管理 + 用户输赢明细统计 - 封盘状态显示倒计时 (x:xx) - 音效仅在开奖弹窗打开时播放 - 路由按模块分组整理 - autoload 支持 App\Services 命名空间
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace App\Controllers\Web;
|
||||
|
||||
use App\Core\WebBaseController;
|
||||
use App\Core\I18n;
|
||||
use App\Services\FollowPlanService;
|
||||
use Db\Database;
|
||||
|
||||
class FollowPlanController extends WebBaseController {
|
||||
|
||||
public function followPlan() {
|
||||
$this->checkWebLogin();
|
||||
I18n::init();
|
||||
$db = new Database();
|
||||
$userId = $this->getCurrentUserId();
|
||||
$user = $db->get('users', ['id','username','balance'], ['id' => $userId]);
|
||||
|
||||
$service = new FollowPlanService($db);
|
||||
$game = $db->get('games', '*', ['code' => 'pk10', 'status' => 1]);
|
||||
$gameId = $game['id'] ?? 0;
|
||||
|
||||
$plans = $service->getActivePlans($gameId);
|
||||
$userFollows = $service->getUserFollowStatus($userId);
|
||||
$summary = $service->getUserSummary($userId);
|
||||
|
||||
extract(compact('user', 'plans', 'userFollows', 'summary', 'game'));
|
||||
include __DIR__ . '/../../Views/Web/follow_plan.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换跟单状态 API
|
||||
*/
|
||||
public function toggleFollow() {
|
||||
$this->checkWebLogin();
|
||||
header('Content-Type: application/json');
|
||||
$db = new Database();
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$planId = intval($data['plan_id'] ?? 0);
|
||||
|
||||
$service = new FollowPlanService($db);
|
||||
$result = $service->toggleFollow($this->getCurrentUserId(), $planId);
|
||||
echo json_encode($result);
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,26 @@ class HomeController extends WebBaseController {
|
||||
$user = $db->get('users', ['id','username','balance','lang'], ['id' => $userId]);
|
||||
$game = $db->get('games', '*', ['code' => 'pk10', 'status' => 1]);
|
||||
$isAgent = !!$db->get('agents', 'id', ['user_id' => $userId, 'status' => 1]);
|
||||
// 加载赔率(优先代理专属赔率,否则用游戏默认赔率)
|
||||
$gameId = $game['id'] ?? 0;
|
||||
$oddsRaw = $db->select('game_odds', '*', ['game_id' => $gameId]);
|
||||
$oddsMap = [];
|
||||
foreach ($oddsRaw as $o) {
|
||||
$oddsMap[$o['type'] . '_' . $o['target']] = (float)$o['odds'];
|
||||
}
|
||||
// 代理专属赔率覆盖
|
||||
$agentId = $db->get('agents', 'id', ['user_id' => $userId, 'status' => 1]);
|
||||
if ($agentId) {
|
||||
$agentOdds = $db->select('agent_odds', '*', ['agent_id' => $agentId, 'game_id' => $gameId]);
|
||||
foreach ($agentOdds as $ao) {
|
||||
$oddsMap[$ao['bet_type'] . '_' . $ao['bet_target']] = (float)$ao['odds'];
|
||||
}
|
||||
}
|
||||
extract([
|
||||
'user' => $user ?: ['id' => $userId, 'username' => $this->getCurrentUsername(), 'balance' => 0],
|
||||
'game' => $game,
|
||||
'isAgent' => $isAgent,
|
||||
'isAgent' => !!$agentId,
|
||||
'oddsMap' => $oddsMap,
|
||||
]);
|
||||
include __DIR__ . '/../../Views/Web/pk10.php';
|
||||
}
|
||||
@@ -56,7 +72,13 @@ class HomeController extends WebBaseController {
|
||||
'ORDER' => ['id' => 'DESC'], 'LIMIT' => 20
|
||||
]);
|
||||
|
||||
extract(compact('user', 'transactions', 'bets'));
|
||||
// 充提记录
|
||||
$fundRequests = $db->select('fund_requests', '*', [
|
||||
'user_id' => $userId,
|
||||
'ORDER' => ['id' => 'DESC'], 'LIMIT' => 20
|
||||
]);
|
||||
|
||||
extract(compact('user', 'transactions', 'bets', 'fundRequests'));
|
||||
include __DIR__ . '/../../Views/Web/profile.php';
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class PeriodController extends WebBaseController {
|
||||
'game_id' => $gameId,
|
||||
'status' => ['drawn', 'settled'],
|
||||
'ORDER' => ['id' => 'DESC'],
|
||||
'LIMIT' => 10
|
||||
'LIMIT' => 30
|
||||
]);
|
||||
foreach ($recentPeriods as $s) {
|
||||
$pk = $getResult($s);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\Controllers\Web;
|
||||
|
||||
use App\Core\WebBaseController;
|
||||
use App\Core\I18n;
|
||||
use App\Services\ReportService;
|
||||
use Db\Database;
|
||||
|
||||
class ReportWebController extends WebBaseController {
|
||||
|
||||
/**
|
||||
* 前台报表查询页面
|
||||
*/
|
||||
public function report() {
|
||||
$this->checkWebLogin();
|
||||
I18n::init();
|
||||
$db = new Database();
|
||||
$userId = $this->getCurrentUserId();
|
||||
$user = $db->get('users', ['id','username','balance'], ['id' => $userId]);
|
||||
extract(compact('user'));
|
||||
include __DIR__ . '/../../Views/Web/report.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 前台报表查询 API
|
||||
*/
|
||||
public function userReportApi() {
|
||||
$this->checkWebLogin();
|
||||
header('Content-Type: application/json');
|
||||
$service = new ReportService(new Database());
|
||||
$dateFrom = $_GET['from'] ?? date('Y-m-d');
|
||||
$dateTo = $_GET['to'] ?? date('Y-m-d');
|
||||
$data = $service->getUserReport($this->getCurrentUserId(), $dateFrom, $dateTo);
|
||||
echo json_encode(['success' => true, 'data' => $data]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\Controllers\Web;
|
||||
|
||||
use App\Core\WebBaseController;
|
||||
use App\Services\TransactionService;
|
||||
use Db\Database;
|
||||
|
||||
class TransactionController extends WebBaseController {
|
||||
|
||||
public function fundRequest() {
|
||||
$this->checkWebLogin();
|
||||
header('Content-Type: application/json');
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$service = new TransactionService(new Database());
|
||||
$result = $service->fundRequest(
|
||||
$this->getCurrentUserId(),
|
||||
$data['type'] ?? '',
|
||||
floatval($data['amount'] ?? 0),
|
||||
$data['remark'] ?? ''
|
||||
);
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
public function transfer() {
|
||||
$this->checkWebLogin();
|
||||
header('Content-Type: application/json');
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$service = new TransactionService(new Database());
|
||||
$result = $service->transfer(
|
||||
$this->getCurrentUserId(),
|
||||
trim($data['to_username'] ?? ''),
|
||||
floatval($data['amount'] ?? 0)
|
||||
);
|
||||
echo json_encode($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user