forked from Kurenai-Network/KurenaiSSManage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.php
144 lines (136 loc) · 5.03 KB
/
hooks.php
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/*
* Copyright (c) 2022. Kurenai Network
* 项目名称:KurenaiSSManage
* 文件名称:hook.php
* Date:2022/1/1 下午6:55
* Author: Kurenai Network
*/
use WHMCS\Database\Capsule;
use Carbon\Carbon;
add_hook('AfterCronJob', 1, function ($vars) {
require 'api/database.php';
try {
check_traffic();
$adminUser = '';//Administrator username
$command = 'GetOrders';
$postData = [
'limitnum' => 10000,
'status' => 'Pending'
];
$results = localAPI($command, $postData, $adminUser);
if (isset($results['orders']['order'])) {
foreach ($results['orders']['order'] as $order) {
if ($order['paymentstatus'] === 'Paid' || $order['amount'] === '0.00') {
$command = 'AcceptOrder';
$postData = [
'orderid' => $order['id']
];
$results = localAPI($command, $postData, $adminUser);
if ($results['result'] !== 'success') {
$postData = array(
'description' => 'Accept order failed #' . $order['id'],
);
$command = 'LogActivity';
localAPI($command, $postData, $adminUser);
}
}
}
}
}catch (Exception $e){
file_put_contents('after_cron_log.txt',var_export($e,true), FILE_APPEND);
}
});
add_hook('DailyCronJob', 1, function($vars) {
require 'api/database.php';
try {
reset_traffic_month();
}catch (Exception $e){
file_put_contents('after_cron_log.txt',var_export($e,true), FILE_APPEND);
}
});
add_hook('ClientAreaPageProductDetails', 1, function($var)
{
$email_ca = new WHMCS_ClientArea();
if ($email_ca->isLoggedIn()) {
$result = Capsule::table('tblusers')->where('id', '=', $email_ca->getUserID())->get()[0]->email_verified_at;
if ($result == NULL) {
echo '<script>if(confirm("You have not verified your email, access is denied!\nPlease click confirm to back to homepage and verify email!\nPlease click cancel to modify account information!")){location.href=\'clientarea.php\';}else{location.href=\'clientarea.php?action=details\';};</script>';
exit();
}
}
});
add_hook('DailyCronJob', 1, function ($vars) {
$adminUser = '';//Administrator username
$orderOverdueDays = 3;//Allow order overdue time(day)
$invoiceOverdueDays = 3;//Allow bill overdue time(day)
$now = Carbon::now();
$now->hour = 0;
$now->minute = 0;
$now->second = 0;
//Cancel order start
$command = 'GetOrders';
$postData = [
'limitnum' => 10000,
'status' => 'Pending'
];
$results = localAPI($command, $postData, $adminUser);
if (isset($results['orders']['order'])) {
foreach ($results['orders']['order'] as $order) {
$createDate = Carbon::parse($order['date']);
$createDate->hour = 0;
$createDate->minute = 0;
$createDate->second = 0;
if ($now->diffInDays($createDate) >= $orderOverdueDays) {
$command = 'CancelOrder';
$postData = [
'orderid' => $order['id']
];
$results = localAPI($command, $postData, $adminUser);
if ($results['result'] !== 'success') {
$postData = array(
'description' => 'Cancel order failed #' . $order['id'],
);
$command = 'LogActivity';
localAPI($command, $postData, $adminUser);
}
}
}
}
//Cancel order end
//Cancel invoices start
$command = 'GetInvoices';
$postData = [
'limitnum' => 10000,
'status' => 'Overdue'
];
$results = localAPI($command, $postData, $adminUser);
if (isset($results['invoices']['invoice'])) {
foreach ($results['invoices']['invoice'] as $invoice) {
$dueDate = Carbon::parse($invoice['duedate']);
$dueDate->hour = 0;
$dueDate->minute = 0;
$dueDate->second = 0;
if ($now->diffInDays($dueDate) >= $invoiceOverdueDays) {
$command = 'UpdateInvoice';
$postData = [
'invoiceid' => $invoice['id'],
'status' => 'Cancelled'
];
$results = localAPI($command, $postData, $adminUser);
if ($results['result'] === 'success') {
$postData = array(
'description' => 'Cancel invoice succeed #' . $invoice['id'],
);
} else {
$postData = array(
'description' => 'Cancel invoice failed #' . $invoice['id'] . ';' . $results['message'],
);
}
$command = 'LogActivity';
localAPI($command, $postData, $adminUser);
}
}
}
//Cancel invoices end
});