Add: upgrade maestro account type
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
let maestroName = $("#search_name").val();
|
||||
|
||||
if(maestroName.length === 0) {
|
||||
$("#error_message").text("학생 이름을 입력하세요.");
|
||||
$("#error_message").text("마에스트로 아이디를 입력하세요.");
|
||||
$("#search_name").focus();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
function loadMaestroList(maestroName) {
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/admin/registered_maestro_list.php",
|
||||
"./../server/admin/maestro_registered_list.php",
|
||||
"maestro_name=" + maestroName,
|
||||
|
||||
(jsonData) => {
|
||||
@@ -125,7 +125,7 @@
|
||||
<span id="search_maestro_name">
|
||||
<h1>검색</h1>
|
||||
|
||||
마에스트로 이름
|
||||
마에스트로 아이디
|
||||
<input type="text" id="search_name"><input type="submit" name="찾기" onClick="searchMaestro()"><br/>
|
||||
<br/>
|
||||
</span>
|
||||
|
||||
@@ -7,14 +7,190 @@
|
||||
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
|
||||
<link rel="stylesheet" type="text/css" href="./../css/module.css">
|
||||
<link rel="stylesheet" type="text/css" href="./../css/color_button.css">
|
||||
<link rel="stylesheet" type="text/css" href="./../css/admin.css">
|
||||
|
||||
<script type="text/javascript" src="./../../../resources/jquery/jquery-3.3.1.min.js"></script>
|
||||
<script type="text/javascript" src="./../js/main.js"></script>
|
||||
<script type="text/javascript" src="./../js/request_server.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#header").load("admin_header.html");
|
||||
$("#section").load("admin_section.html");
|
||||
|
||||
loadMaestroUpgradeList("");
|
||||
});
|
||||
|
||||
|
||||
function loadMaestroUpgradeList(maestroName) {
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/admin/maestro_upgrade_list.php",
|
||||
"maestro_name=" + maestroName,
|
||||
|
||||
(jsonData) => {
|
||||
updateMaestroUpgradeList(jsonData["maestroUpgradeList"]);
|
||||
},
|
||||
|
||||
(errorMessage, errorCode) => {
|
||||
console.log(errorMessage);
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
function updateMaestroUpgradeList(jsonList) {
|
||||
$("#maestro_list_result_contents").empty();
|
||||
printHeader();
|
||||
printContents(jsonList);
|
||||
printFooter();
|
||||
}
|
||||
|
||||
function printHeader() {
|
||||
$("#maestro_list_result_contents").append(
|
||||
"<ul id='search_maestro_list' class='maestro_list'>"
|
||||
+ " <li>"
|
||||
+ " <span class='maestro_name'>이름</span>"
|
||||
+ " <span class='maestro_account_type'>등록된 요금제</span>"
|
||||
+ " <span class='maestro_account_type'>신청한 요금제</span>"
|
||||
+ " <span class='maestro_account_type'>금액</span>"
|
||||
+ " <span class='maestro_account_type'>요청 날짜</span>"
|
||||
+ " <span class='maestro_account_type'>요청 날짜</span>"
|
||||
+ " </li>"
|
||||
);
|
||||
}
|
||||
|
||||
function printContents(jsonList) {
|
||||
console.log(jsonList);
|
||||
if(jsonList === undefined || jsonList.length === 0)
|
||||
return;
|
||||
|
||||
for(let i = 0; i < jsonList.length; i++) {
|
||||
$("#maestro_list_result_contents").append(
|
||||
"<li class='search_result_list'>"
|
||||
+ " <span class='maestro_upgrade_id hide'>" + jsonList[i].maestroUpgradeID + "</span>"
|
||||
+ " <span class='maestro_id hide'>" + jsonList[i].maestroID + "</span>"
|
||||
+ " <input type='text' value='" + jsonList[i].maestroName + "' class='maestro_name'>"
|
||||
+ " <input type='text' value='" + accoutType(jsonList[i].registeredAccountType) + "' class='registered_account_type'>"
|
||||
+ " <input type='text' value='" + accoutType(jsonList[i].requestedAccountType) + "' class='requested_account_type'>"
|
||||
+ " <input type='text' value='" + price(jsonList[i].requestedAccountType, jsonList[i].registeredAccountType) + "' class='price'>"
|
||||
+ " <input type='text' value='" + jsonList[i].requestedDateTime + "' class='requested_date_time'>"
|
||||
+ " <input type='text' value='" + status(jsonList[i].status) + "' class='status'>"
|
||||
+ " <input type='button' class='maestro_upgrade' value='업그레이드' onClick='upgrade(this)'>"
|
||||
+ "</li>"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function accoutType(accountType) {
|
||||
switch(accountType) {
|
||||
case 1:
|
||||
return "20명, 1만원";
|
||||
|
||||
case 2:
|
||||
return "50명, 2만원";
|
||||
|
||||
case 3:
|
||||
return "100명, 3만원";
|
||||
}
|
||||
|
||||
return accountType + "? (N/A)";
|
||||
}
|
||||
|
||||
function accountTypePrice(accountType) {
|
||||
switch(accountType) {
|
||||
case 1:
|
||||
return 10000;
|
||||
|
||||
case 2:
|
||||
return 20000;
|
||||
|
||||
case 3:
|
||||
return 30000;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function accoutTypeValue(accountType) {
|
||||
switch(accountType) {
|
||||
case "20명, 1만원":
|
||||
return 1;
|
||||
|
||||
case "50명, 2만원":
|
||||
return 2;
|
||||
|
||||
case "100명, 3만원":
|
||||
return 3;
|
||||
}
|
||||
|
||||
return accountType + "? (N/A)";
|
||||
}
|
||||
|
||||
function price(requestedAccountType, registeredAccountType) {
|
||||
let priceRequested = accountTypePrice(requestedAccountType);
|
||||
let priceRegistered = accountTypePrice(registeredAccountType);
|
||||
|
||||
return priceRequested - priceRegistered;
|
||||
}
|
||||
|
||||
function status(status) {
|
||||
switch(status) {
|
||||
case 1:
|
||||
return "요청";
|
||||
|
||||
case 2:
|
||||
return "취소";
|
||||
|
||||
case 3:
|
||||
return "업그레이드 적용";
|
||||
}
|
||||
|
||||
return status + "? (N/A)";
|
||||
}
|
||||
|
||||
function printFooter() {
|
||||
$("#maestro_list_result_contents").append("</ul>");
|
||||
}
|
||||
|
||||
function searchMaestroUpgrade() {
|
||||
let maestroName = $("#search_name").val();
|
||||
|
||||
if(maestroName.length === 0) {
|
||||
$("#error_message").text("마에스트로 아이디를 입력하세요.");
|
||||
$("#search_name").focus();
|
||||
}
|
||||
|
||||
loadMaestroUpgradeList(maestroName);
|
||||
}
|
||||
|
||||
function upgrade(inputButton) {
|
||||
let upgradeID = $(inputButton).siblings(".maestro_upgrade_id");
|
||||
let maestroUpgradeID = upgradeID.text();
|
||||
let maestroID = $(inputButton).siblings(".maestro_id");
|
||||
let id = maestroID.text();
|
||||
let accountType = $(inputButton).siblings(".requested_account_type");
|
||||
let newAccountType = accoutTypeValue(accountType.val());
|
||||
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/admin/upgrade_maestro.php",
|
||||
"maestro_upgrade_id=" + maestroUpgradeID + "&maestro_id=" + id + "&new_account_type=" + newAccountType,
|
||||
|
||||
(jsonData) => {
|
||||
loadMaestroUpgradeList("");
|
||||
$("#error_message").text("마에스트로 계정이 정상적으로 등록되었습니다.");
|
||||
},
|
||||
|
||||
(errorMessage, errorCode) => {
|
||||
if($("#error_message").length) {
|
||||
$("#error_message").text(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -28,6 +204,21 @@
|
||||
</header>
|
||||
|
||||
<section id="section">
|
||||
<div>
|
||||
<span id="search_maestro_name">
|
||||
<h1>검색</h1>
|
||||
|
||||
마에스트로 아이디
|
||||
<input type="text" id="search_name"><input type="submit" name="찾기" onClick="searchMaestroUpgrade()"><br/>
|
||||
<br/>
|
||||
</span>
|
||||
|
||||
<span id="search_result">
|
||||
검색 결과
|
||||
<div id="maestro_list_result_contents">
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -88,7 +88,7 @@ function upgradeMaestroInfo(accountType) {
|
||||
let newAccountType = accountType;
|
||||
|
||||
sendRequestServer( //url, sendParams, onSuccess, onFail, isDebugMode);
|
||||
"./../server/maestro/upgrade_maestro.php",
|
||||
"./../server/maestro/request_upgrade_maestro.php",
|
||||
"maestro_id=" + maestroID + "®istered_account_type=" + registeredAccountType + "&new_account_type=" + newAccountType,
|
||||
|
||||
(jsonData) => {
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
header("Content-Type: application/json");
|
||||
|
||||
include "./../lib/send_reply_json.php";
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$maestroName = $_POST["maestro_name"];
|
||||
|
||||
|
||||
$maestroUpgradeList = null;
|
||||
if(strlen($maestroName) === 0)
|
||||
$maestroUpgradeList = get_maestro_upgrade_list();
|
||||
else
|
||||
$maestroUpgradeList = get_maestro_update_list_by_name($maestroName);
|
||||
|
||||
if(strlen($maestroUpgradeList) === 0) {
|
||||
set_error_message("마에스트로 업그레이드 요청 목록 없음");
|
||||
send_result_fail();
|
||||
exit;
|
||||
}
|
||||
|
||||
set_data("maestroUpgradeList", $maestroUpgradeList);
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
function get_maestro_upgrade_list() {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT U.MaestroUpgradeID, U.MaestroID, M.Name, U.RegisteredAccountType, U.RequestedAccountType, U.RequestedDateTime, U.Status
|
||||
FROM moty_maestro_upgrade U, moty_maestro M
|
||||
WHERE U.Status < 2 AND U.MaestroID = M.MaestroID
|
||||
ORDER BY U.MaestroUpgradeID DESC
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
// $stmt->bind_param("iii", $maestroID, $startNo, $endNo);
|
||||
// $stmt->bind_param("ii", $maestroName, $startNo);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($maestroUpgradeID, $maestroID, $maestroName, $registeredAccountType, $requestedAccountType, $requestedDateTime, $status);
|
||||
|
||||
$maestroUpgradeList = array();
|
||||
while($stmt->fetch()) {
|
||||
$maestro["maestroUpgradeID"] = $maestroUpgradeID;
|
||||
$maestro["maestroID"] = $maestroID;
|
||||
$maestro["maestroName"] = $maestroName;
|
||||
$maestro["registeredAccountType"] = $registeredAccountType;
|
||||
$maestro["requestedAccountType"] = $requestedAccountType;
|
||||
$maestro["requestedDateTime"] = $requestedDateTime;
|
||||
$maestro["status"] = $status;
|
||||
array_push($maestroUpgradeList, $maestro);
|
||||
}
|
||||
|
||||
return $maestroUpgradeList;
|
||||
}
|
||||
|
||||
function get_maestro_update_list_by_name($searchMaestroName) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
SELECT U.MaestroUpgradeID, U.MaestroID, M.Name, U.RegisteredAccountType, U.RequestedAccountType, U.RequestedDateTime, U.Status
|
||||
FROM moty_maestro_upgrade U, moty_maestro M
|
||||
WHERE M.Name LIKE CONCAT('%', ?, '%') AND U.MaestroID = M.MaestroID
|
||||
ORDER BY U.MaestroUpgradeID DESC
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("s", $searchMaestroName);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($maestroUpgradeID, $maestroID, $maestroName, $registeredAccountType, $requestedAccountType, $requestedDateTime, $status);
|
||||
|
||||
$maestroUpgradeList = array();
|
||||
while($stmt->fetch()) {
|
||||
$maestro["maestroUpgradeID"] = $maestroUpgradeID;
|
||||
$maestro["maestroID"] = $maestroID;
|
||||
$maestro["maestroName"] = $maestroName;
|
||||
$maestro["registeredAccountType"] = $registeredAccountType;
|
||||
$maestro["requestedAccountType"] = $requestedAccountType;
|
||||
$maestro["requestedDateTime"] = $requestedDateTime;
|
||||
$maestro["status"] = $status;
|
||||
array_push($maestroUpgradeList, $maestro);
|
||||
}
|
||||
|
||||
return $maestroUpgradeList;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
header("Content-Type: application/json");
|
||||
|
||||
include "./../lib/send_reply_json.php";
|
||||
include "./../setup/connect_db.php";
|
||||
|
||||
$maestroUpgradeID = $_POST["maestro_upgrade_id"];
|
||||
$maestroID = $_POST["maestro_id"];
|
||||
$newAccountType = $_POST["new_account_type"];
|
||||
|
||||
|
||||
upgrade_maestro($maestroID, $newAccountType);
|
||||
|
||||
change_upgrade_request_status_to_close($maestroID);
|
||||
change_upgrade_request_status_to_applied($maestroUpgradeID);
|
||||
|
||||
// set_data("maestroUpgradeID", $maestroUpgradeID);
|
||||
// set_data("maestroID", $maestroID);
|
||||
// set_data("newAccountType", $newAccountType);
|
||||
send_result_success();
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
function upgrade_maestro($maestroID, $newAccountType) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro
|
||||
SET AccountType = ?, ActivateStatus = 1, AvailableActivateDateTime = DATE_ADD(NOW(), INTERVAL 1 YEAR)
|
||||
WHERE MaestroID = ?;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("ii", $newAccountType, $maestroID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function change_upgrade_request_status_to_close($maestroID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro_upgrade
|
||||
SET Status = 2
|
||||
WHERE MaestroID = ? AND Status = 1;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("i", $maestroID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
function change_upgrade_request_status_to_applied($maestroUpgradeID) {
|
||||
global $db_conn;
|
||||
|
||||
$query = "
|
||||
UPDATE moty_maestro_upgrade
|
||||
SET Status = 3
|
||||
WHERE MaestroUpgradeID = ?
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param("i", $maestroUpgradeID);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user