Ecshop system-generated red envelopes under the system to generate the red envelope serial number is 10000 based on the addition of four random digits. If we want to issue a large amount of red envelopes, such a serial number rules will inevitably give people a sense of insecurity, in case there really is a boring person, with a day to mask a few red envelopes serial number out, that would be a big loss. Because at most just try 10,000 times on it, so we need to change the system of red envelope serial number issuance rules, so that the red envelope serial number is composed of a-z,a-z,0-9 character combination, the following gives the method of modification:
1. Modify the data type of the Bonus_sn field in the Ecs_user_bonus table
ECSHOP 2.7.2 The field type is bigint, we need to modify it to varchar.
ALTER TABLE ' ecs_user_bonus ' change ' bonus_sn ' bonus_sn ' VARCHAR (+) not NULL DEFAULT ' 0′
2. Modify the part of the Js/user.js file to verify the red envelope serial number
In the file of about 672 lines, find
var reg =/^[0-9]{10}$/;
Modified to:
var reg =/^[0-9a-za-z]{10,32}$/;
3. Modify Red envelope serial number generation rule in admin/bonus.php file
In the file, about 569 lines, comment out the following two lines:
/* Generate red Envelope serial number */
$num = $db->getone ("Select MAX (BONUS_SN) from". $ecs->table (' User_bonus '));
$num = $num? Floor ($num/10000): 100000;
Modify the build rule for the sequence number in the For loop as follows:
for ($i = 0, $j = 0; $i < $bonus _sum; $i + +)
{
$bonus _SN = ($num + $i). Str_pad (Mt_rand (0, 9999), 4, ' 0′, str_pad_left);
$bonus _SN = get_unique_id (10);
$db->query ("INSERT into". $ecs->table (' User_bonus '). " (bonus_type_id, BONUS_SN) VALUES (' $bonus _typeid ', ' $bonus _sn ') ");
$j + +;
}
Add a function that generates a random character multibyte number:
function get_unique_id ($length =32, $pool = "")
{
if ($pool = = "") $pool. = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Mt_srand (Double) microtime () * 1000000);
$unique _id = "";
for ($index = 0; $index < $length; $index + +) {
$unique _id. = substr ($pool, (Mt_rand ()% (strlen ($pool))), 1);
}
return $unique _id;
}
4. Modify the verification part of adding red envelopes in user.php
About 768 lines in the file:
/* Add a red envelope */
ElseIf ($action = = ' Act_add_bonus ')
{
Include_once (Root_path. ' includes/lib_transaction.php ');
$bouns _sn = isset ($_post[' bonus_sn ')? Intval ($_post[' BONUS_SN ']): ";
$bouns _sn = isset ($_post[' bonus_sn ')? Trim ($_post[' bonus_sn '): ";
if (Add_bonus ($user _id, $bouns _sn))
{
Show_message ($_lang[' add_bonus_sucess '), $_lang[' back_up_page '], ' user.php?act=bonus ', ' info ');
}
Else
{
$err->show ($_lang[' back_up_page '), ' User.php?act=bonus ');
}
}
The original
$bouns _sn = isset ($_post[' bonus_sn ')? Intval ($_post[' BONUS_SN ']): ";
Modified to:
$bouns _sn = isset ($_post[' bonus_sn ')? Trim ($_post[' bonus_sn '): ";
5. Revise the Red Envelope serial number verification in the settlement part of the shopping process
flow.php file 1914 rows or so, find
if (Is_numeric ($bonus _sn))
Change to
if (is_string ($bonus _sn))
To the completion of the change here, the background to clear the cache can be generated for the red envelopes alphanumeric serial number, now generated by the serial number is a-Z, A-Z and 0-9 composition, high security, but also avoid the large number of issues caused by the serial numbers duplication problem.
Problem: In practice, you should specify the rules for generating red envelopes when adding a red envelope type, after all, the rules for each activity may be different.
Modifying the law of Red envelope serial number in Ecshop system