Add: maestro_upgrade DB

This commit is contained in:
2018-08-03 07:06:35 +09:00
parent 4a5fbca980
commit d32db6493a
3 changed files with 104 additions and 12 deletions
+28 -11
View File
@@ -1,7 +1,6 @@
<script>
let registeredAccountType = -1;
let newAccountType = -1;
$(document).ready(function() {
@@ -14,7 +13,7 @@ function loadMaestroInfo(maestroID) {
"maestro_id=" + maestroID,
(jsonData) => {
console.log(jsonData);
// console.log(jsonData);
registeredAccountType = jsonData.accountType;
updateCards(registeredAccountType);
},
@@ -47,12 +46,12 @@ function updateCards(accountType) {
break;
case 2:
$("#account_type_1").addClass("border-warning");
// $("#account_type_1").addClass("border-warning");
$("#account_type_1_btn").addClass("btn-secondary disabled");
$("#account_type_1_footer").addClass("text-muted");
$("#account_type_1_footer").text("낮은 요금제로 내릴 수는 없습니다.");
$("#account_type_2").addClass("border-primary");
$("#account_type_2").addClass("border-warning");
$("#account_type_2_btn").addClass("btn-secondary disabled");
$("#account_type_2_footer").addClass("text-warning");
$("#account_type_2_footer").text("현재 적용된 요금제입니다.");
@@ -64,17 +63,17 @@ function updateCards(accountType) {
break;
case 3:
$("#account_type_1").addClass("border-warning");
// $("#account_type_1").addClass("border-warning");
$("#account_type_1_btn").addClass("btn-secondary disabled");
$("#account_type_1_footer").addClass("text-muted");
$("#account_type_1_footer").text("낮은 요금제로 내릴 수는 없습니다.");
$("#account_type_2").addClass("border-primary");
// $("#account_type_2").addClass("border-primary");
$("#account_type_2_btn").addClass("btn-secondary disabled");
$("#account_type_2_footer").addClass("text-muted");
$("#account_type_2_footer").text("낮은 요금제로 내릴 수는 없습니다.");
$("#account_type_3").addClass("border-primary");
$("#account_type_3").addClass("border-warning");
$("#account_type_3_btn").addClass("btn-secondary disabled");
$("#account_type_3_footer").addClass("text-warning");
$("#account_type_3_footer").text("현재 적용된 요금제입니다.");
@@ -84,8 +83,26 @@ function updateCards(accountType) {
}
}
function changeMaestroInfo() {
function upgradeMaestroInfo(accountType) {
console.log("upgrade to " + accountType);
let newAccountType = accountType;
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
"./../server/maestro/upgrade_maestro.php",
"maestro_id=" + maestroID + "&registered_account_type=" + registeredAccountType + "&new_account_type=" + newAccountType,
(jsonData) => {
// console.log(jsonData);
alert("업그레이드 요청이 등록되었습니다.");
location.href="main_menu.html";
},
(errorMessage, errorCode) => {
showErrorMessage(errorMessage, "error");
}
);
}
</script>
@@ -112,7 +129,7 @@ function changeMaestroInfo() {
<li>모든 요금제의 기능은 동일합니다.</li>
<li>1년동안 유효합니다.</li>
</ul>
<a id="account_type_1_btn" class="btn" href="#">업그레이드</a>
<a id="account_type_1_btn" class="btn" href="javascript:void(0);">업그레이드</a>
</div>
<div class="card-footer">
<small id="account_type_1_footer" class="">낮은 요금제로 내릴 수는 없습니다.</small>
@@ -127,7 +144,7 @@ function changeMaestroInfo() {
<li>모든 요금제의 기능은 동일합니다.</li>
<li>1년동안 유효합니다.</li>
</ul>
<a id="account_type_2_btn" class="btn" href="#">업그레이드</a>
<a id="account_type_2_btn" class="btn" href="javascript:void(0);" onclick="upgradeMaestroInfo(2);">업그레이드</a>
</div>
<div class="card-footer">
<small id="account_type_2_footer" class="">현재 적용된 요금제입니다.</small>
@@ -142,7 +159,7 @@ function changeMaestroInfo() {
<li>모든 요금제의 기능은 동일합니다.</li>
<li>1년동안 유효합니다.</li>
</ul>
<a id="account_type_3_btn" class="btn" href="#">업그레이드</a>
<a id="account_type_3_btn" class="btn" href="javascript:void(0);" onclick="upgradeMaestroInfo(3);">업그레이드</a>
</div>
<div class="card-footer">
<small id="account_type_3_footer" class="">이 요금제로 업그레이드가 가능합니다.</small>
@@ -0,0 +1,64 @@
<?php
header("Content-Type: application/json");
include "./../lib/send_reply_json.php";
include "./../setup/connect_db.php";
$maestroID = $_POST["maestro_id"];
$registeredAcountType = $_POST["registered_account_type"];
$newAccountType = $_POST["new_account_type"];
// $maestroID = has_maestro_name($maestro_name);
// if($maestroID !== null) {
// set_error_message($maestro_name." : 이미 등록된 마에스트로 계정입니다.");
// send_result_fail();
// exit;
// }
add_maestro_update($maestroID, $registeredAcountType, $newAccountType);
$countUpgrade = count_maestro_upgrade($maestroID);
if($countUpgrade === null || $countUpgrade < 1) {
set_error_message($maestro_name." : 알 수 없는 이유로 마에스트로 계정 업그레이드 요청이 취소되었습니다.");
send_result_fail();
exit;
}
send_result_success();
exit;
function count_maestro_upgrade($maestroID) {
global $db_conn;
$query = "
SELECT COUNT(MaestroID)
FROM moty_maestro_upgrade
WHERE MaestroID = ?
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("i", $maestroID);
$stmt->execute();
$stmt->bind_result($countUpgrade);
// while($stmt->fetch())
$stmt->fetch();
$stmt->close();
return $countUpgrade;
}
function add_maestro_update($maestroID, $registeredAcountType, $newAccountType) {
global $db_conn;
$query = "
INSERT INTO moty_maestro_upgrade (RegisteredAccountType, RequestedAccountType, RequestedDateTime, Status, MaestroID)
VALUES (?, ?, NOW(), 1, ?);
";
$stmt = $db_conn->prepare($query);
$stmt->bind_param("iii", $registeredAcountType, $newAccountType, $maestroID);
$stmt->execute();
}
?>
+11
View File
@@ -20,6 +20,17 @@ CREATE TABLE moty_maestro (
MaestroTestID INT UNSIGNED
);
CREATE TABLE moty_maestro_upgrade (
MaestroUpgradeID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
RegisteredAccountType INT UNSIGNED NOT NULL,
RequestedAccountType INT UNSIGNED NOT NULL,
RequestedDateTime DATETIME NOT NULL,
Status INT UNSIGNED NOT NULL,
MaestroID INT UNSIGNED NOT NULL,
FOREIGN KEY (MaestroID) REFERENCES moty_maestro(MaestroID)
);
CREATE TABLE moty_player (
PlayerID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
MaestroID INT UNSIGNED NOT NULL,