prepare("select * from vpnuser where vuser='".$username."'");
$data->execute();
$row = $data->fetch(PDO::FETCH_ASSOC);
if (empty($row)){
echo json_encode([
"status" => 401,
"message" => "Account doesn't exist",
]);
return;
} else{
$type = 5;
$group = "BY";
$hyid = "3";
$subPackage = "Basic";
$package = "";
$speed = "1024";
if($plan == "basic") {
$subPackage = "Basic";
$hyid = "3";
$speed = "1024";
} else if($plan == "premium") {
$subPackage = "Premium";
$hyid = "4";
$speed = "2048";
} else {
$subPackage = "VIP";
$hyid = "5";
$speed = "4096";
}
$months = "+1 month";
$day = 30;
if($time == "1month") {
$months = "+1 month";
$day = 30;
$package = "월정제 ".$subPackage."(30일)";
} else if($time == "3month") {
$months = "+3 months";
$day = 90;
$package = "월정제 ".$subPackage."(90일)";
} else if($time == "6month") {
$months = "+6 months";
$day = 180;
$package = "월정제 ".$subPackage."(180일)";
} else {
$months = "+1 year";
$day = 365;
$package = "월정제 ".$subPackage."(365일)";
}
$data = $db->prepare("INSERT INTO prddbh (paymethod, bh, vpnus, spname, groups, sday, sjg, ddtype, ddtime, ddip, oldhyid, oldlastdate) VALUES ('"
.$type."', '"
.date("Ymd").mt_rand(1000,9999)."', '"
.$username."', '"
.$package."', 'BY', '"
.$day."', '"
.$price."', 'android', '"
.date("Y-m-d H:i:s")."', '"
.$ip."', '"
.$row['hyid']."', '"
.$row['lastdate']."' )");
$data->execute();
if($row['groups'] == 'LL') {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
if (date("Y-m-d H:i:s", strtotime($row['lastdate'])) <= date("Y-m-d H:i:s" )) {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
if($hyid == 2 | $hyid == 3) {
if($row['hyid'] == 2 | $row['hyid'] == 3) {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months, strtotime($row['lastdate'])))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
$now = time(); // or your date as well
$expire = strtotime($row['lastdate']);
$datediff = $expire - $now;
$days = round($datediff / (60 * 60 * 24));
$money = 0;
if($row['hyid'] == 4)
$money = ($days / 30) * 32;
else if($row['hyid'] == 5)
$money = ($days / 30) * 64;
$plusDays = round($money / (16/ 30));
$plusStr = "+1 day";
if($plusDays > 1) {
$plusStr = "+".$plusDays." days";
}
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($plusStr, strtotime($new['lastdate'])))
."' where vuser='".$username."'");
$data->execute();
}
} else if($hyid == 4) {
if($row['hyid'] == 4) {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months, strtotime($row['lastdate'])))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
} else {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
$now = time(); // or your date as well
$expire = strtotime($row['lastdate']);
$datediff = $expire - $now;
$days = round($datediff / (60 * 60 * 24));
$money = 0.0;
if($row['hyid'] == 2 | $row['hyid'] == 3 ) {
$money = ($days / 30) * 16;
} else if($row['hyid'] == 5) {
$money = ($days / 30) * 64;
}
$plusDays = round($money / (32 / 30));
$plusStr = "+1 day";
if($plusDays > 1) {
$plusStr = "+".$plusDays." days";
}
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($plusStr, strtotime($new['lastdate'])))
."' where vuser='".$username."'");
$data->execute();
}
} else if($hyid == 5) {
if($row['hyid'] == 5) {
$data = $db->prepare("update vpnuser set lastdate = '" . date("Y-m-d H:i:s", strtotime($months, strtotime($row['lastdate'])))
. "', hyid = '" . $hyid
. "', groups = '" . $group
. "', updk = '" . $speed
. "', downdk = '" . $speed
. "', flow = 0 where vuser='" . $username . "'");
$data->execute();
} else {
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($months))
."', hyid = '".$hyid
."', groups = '".$group
."', updk = '".$speed
."', downdk = '".$speed
."', flow = 0 where vuser='".$username."'");
$data->execute();
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
$now = time(); // or your date as well
$expire = strtotime($row['lastdate']);
$datediff = $expire - $now;
$days = round($datediff / (60 * 60 * 24));
$money = 0.0;
if($row['hyid'] == 4)
$money = ($days / 30) * 32;
else if($row['hyid'] == 2| $row['hyid'] == 3 )
$money = ($days / 30) * 16 ;
$plusDays = round($money / (64 / 30));
$plusStr = "+1 day";
if($plusDays > 1) {
$plusStr = "+".$plusDays." days";
}
$data = $db->prepare("update vpnuser set lastdate = '".date("Y-m-d H:i:s", strtotime($plusStr, strtotime($new['lastdate'])))
."' where vuser='".$username."'");
$data->execute();
}
}
}
}
$newData = $db->prepare("select * from vpnuser where vuser='".$username."'");
$newData->execute();
$new = $newData->fetch(PDO::FETCH_ASSOC);
echo json_encode([
"status" => 200,
"data" => $new
]);
}
} else {
echo json_encode([
"status" => 401,
"message" => "Email, password are required!",
]);
return;
}
?>