Add: upgrade maestro account type

This commit is contained in:
2018-08-04 06:06:05 +09:00
parent d32db6493a
commit 9c7a67c561
7 changed files with 347 additions and 5 deletions
@@ -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;
}
?>
+64
View File
@@ -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();
}
?>