forked from greensea/seavpn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount_renew.php
More file actions
90 lines (69 loc) · 2.38 KB
/
Copy pathaccount_renew.php
File metadata and controls
90 lines (69 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require_once('includes/header.php');
require_once('includes/order.lib.php');
require_once('includes/vpn.php');
$aid = @$_GET['vpnid'];
$aid = (int)$aid;
$user = user_isonline();
if ($user === false) {
renew_error(_('You have to login before renew your VPN account'));
die();
}
$accounts = db_quick_fetch('vpnaccount', "WHERE id=$aid AND uid={$user['id']}");
if (count($accounts) <= 0) {
renew_error(_('VPN account not exists'));
die();
}
$account = $accounts[0];
$services = db_quick_fetch('service', "WHERE id IN (SELECT serviceid FROM (SELECT DISTINCT serviceid FROM `order` WHERE NOT ISNULL(paidtime) AND vpnid={$account['id']} ORDER BY id DESC LIMIT 1) AS t)");
if (count($services) <= 0) {
vpn_log("Could not find correlate service id for vpnaccount id {$account['id']}");
renew_error(_('Can not renew, please contact us for help'));
die();
}
$service = $services[0];
$amt = vpn_afford($service['id'], $user['email']);
/// 开始支付过程
if ($amt <= 0) {
$order = order_new($service['id'], -$amt);
}
else {
$order = order_new($service['id']);
}
if ($order === false) {
vpn_log("Can not get order via order_new('{$service['id']}')");
renew_error(_('Can not renew, please contact us for help'));
die();
}
/// 创建订单是不会设置 VPNID 的,所以需要手动设置
order_setvpnid($order['orderid'], $aid);
if ($amt < 0) {
/// 余额不足时,显示付款页面,并在付款成功后继续开通帐号操作
//$smarty->assign('amount', abs($amt));
//$smarty->assign('service', $service);
$url = "order_preview.php?id={$order['orderid']}";
header("Location: $url");
$smarty->assign('redirect_url', $url);
$smarty->assign('tip_title', _('Redirect'));
$smarty->assign('tip_msg', _('Redirecting...'));
$smarty->display('tip.html');
die();
}
/// 3. 账户余额足够,续费
//print_r($account);
//print_r($service);
vpn_renew($account['username'], $service['duration'], $service['radiusgroup']);
/// 4. 发货(扣款)
order_delivery($order['orderid']);
$smarty->assign('tip_title', _('Renew Success'));
$smarty->assign('tip_msg', _('Thank you for purchase, now you can go to VPN Account page to view you VPN account'));
$smarty->assign('redirect_url', 'account.php');
$smarty->display('tip.html');
die();
function renew_error($msg) {
global $smarty;
$smarty->assign('tip_title', _('ERROR'));
$smarty->assign('tip_msg', $msg);
$smarty->display('tip.html');
}
?>