Fix: register maestro test player

This commit is contained in:
2018-07-19 13:59:10 +09:00
parent 93a1332f4d
commit c8b1e15447
3 changed files with 81 additions and 17 deletions
+80 -11
View File
@@ -4,25 +4,94 @@ header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestro_id = $_POST["maestro_id"];
$maestroID = $_POST["maestro_id"];
$query = "
UPDATE moty_maestro
SET ActivateStatus = 1, AvailableActivateDateTime = DATE_ADD(NOW(), INTERVAL 1 YEAR)
WHERE MaestroID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestro_id);
$stmt->execute();
if($stmt->affected_rows <= 0) {
$result = register_maestro($maestroID);
if($result <= 0) {
set_error_message("마에스트로 계정 활성화 실패");
send_result_fail();
exit;
}
add_maestro_test_player($maestroID);
$playerID = get_maestro_test_player($maestroID);
if($playerID === null) {
set_error_message("마에스트로 테스트 플레이어 생성 실패");
send_result_fail();
exit;
}
$result = set_maestro_test_player($maestroID, $playerID);
if($result === null || $result === 0) {
set_error_message("마에스트로 테스트 플레이어 등록 실패");
send_result_fail();
exit;
}
send_result_success();
exit;
function register_maestro($maestroID) {
global $db_conn;
$query = "
UPDATE moty_maestro
SET ActivateStatus = 1, AvailableActivateDateTime = DATE_ADD(NOW(), INTERVAL 1 YEAR)
WHERE MaestroID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
return $stmt->affected_rows;
}
function add_maestro_test_player($maestroID) {
global $db_conn;
$query = "
INSERT INTO moty_player (MaestroID, Name, EnterCode, AccountType)
VALUES (?, 'Test', '', 1)
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
}
function get_maestro_test_player($maestroID) {
global $db_conn;
$query = "
SELECT PlayerID
FROM moty_player
WHERE MaestroID = ? AND AccountType = 1
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($playerID);
$stmt->fetch();
$stmt->close();
return $playerID;
}
function set_maestro_test_player($maestroID, $playerID) {
global $db_conn;
$query = "
UPDATE moty_maestro
SET MaestroTestID = ?
WHERE MaestroID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("ii", $playerID, $maestroID);
$stmt->execute();
return $stmt->affected_rows;
}
?>