query($sql)) { $res = $mysql->fetch_row(); return $res['uid']; } return false; } $max_uid = getMaxUid(); $min = ONE; $max = 100; echo "uid---" . $max_uid . "
"; if (!empty($max_uid)) { $min = $max_uid + ONE; $max = $min + 100; } $data = []; $at = ['']; $indata = []; //$config = Utils::config('rand_at'); // 查询注册最大uid 对应进行自增 $myfile = fopen("C:\Users\Administrator\Desktop\online\\tb_register" . $min . "and" . $max . ".json", "a+") or die("Unable to open file!"); $myloginfile = fopen("C:\Users\Administrator\Desktop\online\\tb_login" . $min . "and" . $max . ".json", "a+") or die("Unable to open file!"); $mypayfile = fopen("C:\Users\Administrator\Desktop\online\\tb_pay" . $min . "and" . $max . ".json", "a+") or die("Unable to open file!"); echo $min . "---" . $max . "
"; for ($i = $min; $i <= $max; $i++) { $creat_at_rand_num = mt_rand(ZERO, 188); $server_id = mt_rand(ONE, HUNDRED); $creat_at = $rand_at[$creat_at_rand_num]; $dat_day = mt_rand(ONE, 10); $data1 = date('Y-m-d', strtotime("$creat_at +$dat_day day")); $chandid = rand(1, 20); $tou_num = rand(ZERO, 331); $wei_num = rand(ZERO, 325); $nick_name = $nicheng_tou[$tou_num] . $nicheng_wei[$wei_num] . $i; $channd_name = 'channd' . $chandid; // online 注册 $setdata[] = array( $i, "'" . $nick_name . "'", "'" . $creat_at . "'", "'" . $data1 . "'", $chandid, "'" . $channd_name . "'", $server_id ); $vip = ONE; $level = ONE; // 整理初始登录数据 $indata[] = array( $i, $chandid, "'" . $creat_at . "'", "'" . $creat_at . "'", $vip, $level, "'" . $nick_name . "'", $server_id ); // 组装json 录入json 文件 $str1 = '{"index":{"_type":"register","_id":"' . $i . '"}}' . "\n"; $str2 = '{"uid":' . $i . ',"server_id":"' . $server_id . '","nick_name":"' . $nick_name . '","creat_at":"' . $creat_at . '","login_at":"' . $data1 . '","channelid":"' . $chandid . '","channelname":"' . $channd_name . '"}' . "\n"; if ($myfile) { fwrite($myfile, $str1); fwrite($myfile, $str2); } } $str1 = null; $str2 = null; fclose($myfile); function setRegister($setdata) { if (count($setdata) > ZERO) { $mysql = new mysqldb(); $res = $mysql->insertBatch("tb_register", "uid, nick_name, creat_at, login_at, channelid, channelname,server_id", $setdata); if ($res) { return "注册用户 录入成功!
"; } else { return "注册用户 录入失败!
"; } } return "resq user data is null !
"; } // 登录 function setLogin($setdata) { if (count($setdata) > ZERO) { $mysql = new mysqldb(); $res = $mysql->insertBatch("tb_login", "uid, channelid,create_at,login_at, vip, level,nick_name,server_id", $setdata); if ($res) { return "登录活跃 录入成功!
"; } return "登录活跃 录入失败!
"; } return "dau data is null !
"; } function setPay($setdata) { if (count($setdata) > ZERO) { $mysql = new mysqldb(); $res = $mysql->insertBatch("tb_pay", "uid, pay_num, status, channelid, creat_at,pay_at,server_id", $setdata); if ($res) { //echo\n; return "充值成功
"; } return "充值失败
";; } //echo "resq user data is null !
"; return "充值失败 data
";;; } // 录入注册用户 //$re_nline = setOnline($setdata); $indata2 = []; if (count($indata) > ZERO) { // 循环遍历100万条记录数据 for ($i = ZERO; $i < count($indata); $i++) { $uid = $indata[$i][ZERO]; $channelid = $indata[$i][ONE]; $nick_name = $indata[$i][SIX]; $creat_at = $indata[$i][TWO]; $vip = $indata[$i][4]; $level = $indata[$i][5]; $server_id = $indata[$i][7]; // - // // 遍历次数 $fornum = mt_rand(ONE, 30); for ($j = ONE; $j <= $fornum; $j++) { $dat_day = mt_rand(ONE, 30); $level_rand = mt_rand(ONE, 5); $str = str_replace("'", '', $creat_at); $data1 = date('Y-m-d', strtotime("$str +$dat_day day")); $level += $level_rand; if ($level >= ONE AND $level <= 10) { $vip = $vip; } if ($level >= 10 AND $level <= 20) { $vip = 1; } if ($level >= 20 AND $level <= 30) { $vip = 2; } if ($level >= 30 AND $level <= 50) { $vip = 3; } if ($level >= 50 AND $level <= 100) { $vip = 4; } if ($level >= 100) { $vip = 5; } // 死循环 在执行 indata 第一层循环的时候进行的遍历 到地二次执行的时候确是有队 indata 进行了重新赋值,这时候indata 是不断的增大 通过 // 第一层等for循环也会一直存在数据 count 永远会被迭代 所以一直就会处于死循环的状态了 $indata2[] = array( $uid, $channelid, $creat_at, "'" . $data1 . "'", $vip, $level, $nick_name, $server_id ); $str1 = '{"index":{"_type":"login","_id":"' . $uid . '"}}' . "\n"; //"uid, channelid, login_at, create_at, vip, level,nick_name $str2 = '{"uid":' . $uid . ',"server_id":"' . $server_id . '","channelid":"' . $chandid . '","login_at":"' . $data1 . '","create_at":"' . $creat_at . '","vip":"' . $vip . '","level":"' . $level . '"}' . "\n"; if ($myloginfile) { fwrite($myloginfile, $str1); fwrite($myloginfile, $str2); } } } fclose($myloginfile); } $pay_gear = [6, 10, 688, 188]; // 付费充值 if (count($indata) > ZERO) { $indata_max_key = count($indata); $pay_probability = [0.06, 0.02, 0.1, 0.2]; $rand_sifter = mt_rand(ZERO, THREE); $paylin = ceil(($indata_max_key * $pay_probability[$rand_sifter])); //echo $paylin . "
"; for ($i = ZERO; $i < $paylin; $i++) { //echo "-indata max key --" . $indata_max_key . "
"; $role_dat_key = ceil(mt_rand(ZERO, $indata_max_key - ONE)); //echo $role_dat_key . "
"; $in_rand_roole = $indata[$role_dat_key]; $uid = $in_rand_roole[ZERO]; $channelid = $in_rand_roole[ONE]; $nick_name = $in_rand_roole[SIX]; $creat_at = $in_rand_roole[TWO]; $server_id = $in_rand_roole[7]; $pay_rand_num = mt_rand(ZERO, THREE); $pay_num = $pay_gear[$pay_rand_num]; $status = rand(ZERO, THREE); $dat_day = mt_rand(ZERO, 30); $str = str_replace("'", '', $creat_at); $data1 = date('Y-m-d', strtotime("$str +$dat_day day")); $pay_data[] = array( $uid, $pay_num, $status, $channelid, $creat_at, "'" . $data1 . "'", $server_id ); $str1 = '{"index":{"_type":"pay","_id":"' . $uid . '"}}' . "\n"; //"uid, channelid, login_at, create_at, vip, level,nick_name $str2 = '{"uid":' . $uid . ',"server_id":"' . $server_id . '","channelid":"' . $channelid . '","login_at":"' . $data1 . '","create_at":"' . $creat_at . '","vip":"' . $vip . '","level":"' . $level . '"}' . "\n"; if ($mypayfile) { fwrite($mypayfile, $str1); fwrite($mypayfile, $str2); } } fclose($mypayfile); } echo $paylin . "
"; echo setRegister($setdata); unset($setdata); echo setLogin($indata2); unset($indata2); echo setPay($pay_data); unset($indata); unset($pay_data);