Fix: add/delete player count bug

This commit is contained in:
2018-08-06 18:23:34 +09:00
parent f39b64d60e
commit 871d402dba
3 changed files with 87 additions and 22 deletions
+36 -1
View File
@@ -43,8 +43,11 @@ if($result === null) {
exit;
}
increase_player_count($maestroID, 1);
// increase_player_count($maestroID, 1);
$count = count_registered_player($maestroID);
update_count_registered_player($maestroID, $count);
set_data("count", $count);
send_result_success();
exit;
@@ -131,4 +134,36 @@ function increase_player_count($maestroID, $count) {
$stmt->execute();
}
function count_registered_player($maestroID) {
global $db_conn;
$query = "
SELECT COUNT(PlayerID)
FROM moty_player
WHERE MaestroID = ? AND AccountType = 0
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($countPlayer);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
return $countPlayer;
}
function update_count_registered_player($maestroID, $countPlayer) {
global $db_conn;
$query = "
UPDATE moty_maestro
SET PlayerCount = ?
WHERE MaestroID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("ii", $countPlayer, $maestroID);
$stmt->execute();
}
?>
+50 -21
View File
@@ -10,22 +10,25 @@ $playerID = $_POST["player_id"];
deletePlayer($maestroID, $playerID);
$result = hasPlayerID($maestroID, $playerID);
if($result === true) {
$countPlayer = countPlayerID($maestroID, $playerID);
if($countPlayer > 0) {
set_error_message("학생 계정 삭제 실패");
send_result_fail();
exit;
}
$result = hasPlayerRecord($maestroID, $playerID);
if($result === true) {
$countPlayer = countPlayerRecord($maestroID, $playerID);
if($countPlayer > 0) {
set_error_message("학생 플레이 기록 삭제 실패");
send_result_fail();
exit;
}
decrease_player_count($maestroID, 1);
// decrease_player_count($maestroID, 1);
$count = count_registered_player($maestroID);
update_count_registered_player($maestroID, $count);
set_data("count", $count);
send_result_success();
exit;
@@ -60,48 +63,42 @@ function deletePlayer($maestroID, $playerID) {
// }
}
function hasPlayerID($maestroID, $playerID) {
function countPlayerID($maestroID, $playerID) {
global $db_conn;
$query = "
SELECT PlayerID
SELECT COUNT(PlayerID)
FROM moty_player
WHERE MaestroID=? AND PlayerID=?
WHERE MaestroID = ? AND PlayerID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("ii", $maestroID, $playerID);
$stmt->execute();
$stmt->bind_result($playerID);
$stmt->bind_result($countPlayer);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
if($playerID !== null)
return true;
return false;
return $countPlayer;
}
function hasPlayerRecord($maestroID, $playerID) {
function countPlayerRecord($maestroID, $playerID) {
global $db_conn;
$query = "
SELECT PlayerID
SELECT COUNT(PlayerID)
FROM moty_best_record
WHERE MaestroID=? AND PlayerID=?
WHERE MaestroID = ? AND PlayerID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("ii", $maestroID, $playerID);
$stmt->execute();
$stmt->bind_result($playerID);
$stmt->bind_result($countPlayer);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
if($playerID !== null)
return true;
return false;
return $countPlayer;
}
function decrease_player_count($maestroID, $count) {
@@ -117,4 +114,36 @@ function decrease_player_count($maestroID, $count) {
$stmt->execute();
}
function count_registered_player($maestroID) {
global $db_conn;
$query = "
SELECT COUNT(PlayerID)
FROM moty_player
WHERE MaestroID = ? AND AccountType = 0
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($countPlayer);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
return $countPlayer;
}
function update_count_registered_player($maestroID, $countPlayer) {
global $db_conn;
$query = "
UPDATE moty_maestro
SET PlayerCount = ?
WHERE MaestroID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("ii", $countPlayer, $maestroID);
$stmt->execute();
}
?>
+1
View File
@@ -24,6 +24,7 @@ if($playerID === null) {
}
set_data("MaestroID", $maestroID);
set_data("PlayerID", $playerID);
send_result_success();
exit;