mirror of
https://github.com/hotspotbilling/phpnuxbill.git
synced 2025-08-18 08:38:29 +02:00
Merge pull request #189 from pro-cms/patch-4
Added generate voucher function.
This commit is contained in:
commit
892c6bf7f5
1 changed files with 25 additions and 0 deletions
25
init.php
25
init.php
|
@ -233,6 +233,31 @@ function showResult($success, $message = '', $result = [], $meta = [])
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function generateUniqueNumericVouchers($totalVouchers, $length = 8) {
|
||||||
|
// Define characters allowed in the voucher code
|
||||||
|
$characters = '0123456789';
|
||||||
|
$charactersLength = strlen($characters);
|
||||||
|
$vouchers = array();
|
||||||
|
|
||||||
|
// Attempt to generate unique voucher codes
|
||||||
|
for ($j = 0; $j < $totalVouchers; $j++) {
|
||||||
|
do {
|
||||||
|
$voucherCode = '';
|
||||||
|
// Generate the voucher code
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$voucherCode .= $characters[rand(0, $charactersLength - 1)];
|
||||||
|
}
|
||||||
|
// Check if the generated voucher code already exists in the array
|
||||||
|
$isUnique = !in_array($voucherCode, $vouchers);
|
||||||
|
} while (!$isUnique);
|
||||||
|
|
||||||
|
$vouchers[] = $voucherCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $vouchers;
|
||||||
|
}
|
||||||
|
|
||||||
function sendTelegram($txt)
|
function sendTelegram($txt)
|
||||||
{
|
{
|
||||||
Message::sendTelegram($txt);
|
Message::sendTelegram($txt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue