-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.php
More file actions
75 lines (67 loc) · 2.88 KB
/
Copy pathprofile.php
File metadata and controls
75 lines (67 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
require_once __DIR__ . '/config.php';
require_once __DIR__ . '/core/Database.php';
require_once __DIR__ . '/init_check.php';
require_once __DIR__ . '/core/Session.php';
require_once __DIR__ . '/core/TokenSystem.php';
require_once __DIR__ . '/core/StockEngine.php';
require_once __DIR__ . '/core/GachaEngine.php';
require_once __DIR__ . '/core/TradingEngine.php';
require_once __DIR__ . '/core/PoolEngine.php';
require_once __DIR__ . '/core/QuestEngine.php';
require_once __DIR__ . '/core/MarketEngine.php';
require_once __DIR__ . '/core/CheckinEngine.php';
require_once __DIR__ . '/adapters/manager.php';
Session::start();
require_once __DIR__ . '/core/AutoJob.php';
AutoJob::run();
$profileUserId = (int)($_GET['id'] ?? Session::userId());
if ($profileUserId <= 0) $profileUserId = Session::userId();
$isOwner = Session::isLoggedIn() && $profileUserId === Session::userId();
// Handle number_style save
if ($isOwner && $_SERVER['REQUEST_METHOD'] === 'POST' && ($_POST['action'] ?? '') === 'set_number_style') {
$style = $_POST['number_style'] ?? 'wan';
if (in_array($style, ['wan', '4digit', '3digit'])) {
$db = Database::getInstance();
$db->prepare("UPDATE users SET number_style = ? WHERE id = ?")->execute([$style, $profileUserId]);
$_SESSION['number_style'] = $style;
Session::flash('success', '数字格式已更新。');
}
header('Location: ' . url('/profile.php'));
exit;
}
$db = Database::getInstance();
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$profileUserId]);
$profileUser = $stmt->fetch();
if (!$profileUser) { http_response_code(404); echo '用户不存在'; exit; }
// Stats
$isKs = is_kaleidoscope();
$stats = TokenSystem::getUserStats($profileUserId);
if ($isKs) {
$ksBal = TokenSystem::getKaleidoscopeBalance($profileUserId);
$stats['token_balance'] = $ksBal;
$stats['net_worth'] = $ksBal + ($stats['portfolio_value'] ?? 0);
}
$checkinStats = CheckinEngine::getCheckinStats($profileUserId);
$summary = TradingEngine::getPortfolioSummary($profileUserId);
// Best cards (top 3 by value)
$bestCards = $db->prepare("
SELECT h.*, s.symbol, s.name as stock_name, s.rarity, s.current_price,
(h.quantity * s.current_price) as market_value
FROM " . ks_table("holdings") . " h JOIN stocks s ON h.stock_id = s.id
WHERE h.user_id = ? AND h.quantity > 0
ORDER BY market_value DESC LIMIT 3
");
$bestCards->execute([$profileUserId]);
// Completed achievements
$achievements = $db->prepare("
SELECT qc.* FROM user_quests uq
JOIN quest_config qc ON uq.quest_id = qc.id
WHERE uq.user_id = ? AND uq.completed = 1 AND qc.type = 'achievement'
ORDER BY uq.completed_at DESC
");
$achievements->execute([$profileUserId]);
$gachaStats = GachaEngine::getPullStats($profileUserId);
$pageTitle = htmlspecialchars($profileUser['username']) . ' 的个人主页';
require_once __DIR__ . '/templates/profile.php';