include_once('connect.php');
include_once('common.php');
include_once('redis.php');
define('CDKEY', 'cdkeylist');
define('CDKEY_MAX', 2000);
define('CDKEY_MIN', 1);
$number = CDKEY_MAX;
if (!is_numeric($number)) {
return error('数量必须是整形');
}
if ($number > CDKEY_MAX) {
return error('数量不能大于' . CDKEY_MAX);
}
if ($number < CDKEY_MIN) {
return error('数量不能小于' . CDKEY_MIN);
}
$random_arr = [];
for ($i = 0; $i < $number; $i++) {
$random_arr[$i] = getRandom();
}
$num = $redis->lLen(CDKEY);
if ($num > 0) {
return error('CDKEY已批量生成,无需重复生成');
}
if (!empty($random_arr)) {
$sql = sprintf("INSERT INTO m_cdkey (`code`, `create_time`) VALUES ");
$time = date('Y-m-d H:i:s', time());
foreach ($random_arr as $item) {
$itemStr = '( ';
$itemStr .= sprintf("'%s', '%s'", $item, $time);
$itemStr .= '),';
$sql .= $itemStr;
}
$sql = rtrim($sql, ',');
$sql .= ';';
if ($conn->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "
" . $conn->error;
}
}
$sql_query = "SELECT code FROM m_cdkey";
$result = $conn->query($sql_query);
$arr = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$redis->lPush(CDKEY, $row['code']);
}
}
return success("CDKEY批量生成");
- 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