123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- define( "ROOT_PATH", dirname(dirname(__FILE__)) );
- require_once ROOT_PATH.'/DB_PDO.class.php';
- require_once ROOT_PATH.'/confv2.class.php';
- date_default_timezone_set('PRC');
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $sql = " select user_id from user_level where level=3 ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
-
- foreach ($result as $key => $v) {
- createInvite($v['user_id']);
- }
- function createInvite($userId){
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- for ($i = 0; $i < 1000 ; $i++) {
- $random = my_random(10);
- $sql = " insert into user_operate_invite(user_id, invite_code, type) values ({$userId}, '{$random}', 1) ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $res = $_PDO->lastinsertid();
- }
- }
- function my_random($length = 6, $type = 'string', $convert = 0)
- {
- $config = array(
- 'number' => '1234567890',
- 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
- 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
- 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
- );
- if (!isset($config[$type]))
- $type = 'string';
- $string = $config[$type];
- $code = '';
- $strlen = strlen($string) - 1;
- for ($i = 0; $i < $length; $i++) {
- $code .= $string{mt_rand(0, $strlen)};
- }
- if (!empty($convert)) {
- $code = ($convert > 0) ? strtoupper($code) : strtolower($code);
- }
- return $code;
- }
|