优惠券订单及其他脚本

create_liedou_invite_code.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. define( "ROOT_PATH", dirname(dirname(__FILE__)) );
  3. require_once ROOT_PATH.'/DB_PDO.class.php';
  4. require_once ROOT_PATH.'/confv2.class.php';
  5. date_default_timezone_set('PRC');
  6. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  7. $sql = " select user_id from user_level where level=3 ";
  8. $stmt = $_PDO->prepare($sql);
  9. $stmt->execute();
  10. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  11. foreach ($result as $key => $v) {
  12. createInvite($v['user_id']);
  13. }
  14. function createInvite($userId){
  15. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  16. for ($i = 0; $i < 1000 ; $i++) {
  17. $random = my_random(10);
  18. $sql = " insert into user_operate_invite(user_id, invite_code, type) values ({$userId}, '{$random}', 1) ";
  19. $stmt = $_PDO->prepare($sql);
  20. $stmt->execute();
  21. $res = $_PDO->lastinsertid();
  22. }
  23. }
  24. function my_random($length = 6, $type = 'string', $convert = 0)
  25. {
  26. $config = array(
  27. 'number' => '1234567890',
  28. 'letter' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
  29. 'string' => 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789',
  30. 'all' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
  31. );
  32. if (!isset($config[$type]))
  33. $type = 'string';
  34. $string = $config[$type];
  35. $code = '';
  36. $strlen = strlen($string) - 1;
  37. for ($i = 0; $i < $length; $i++) {
  38. $code .= $string{mt_rand(0, $strlen)};
  39. }
  40. if (!empty($convert)) {
  41. $code = ($convert > 0) ? strtoupper($code) : strtolower($code);
  42. }
  43. return $code;
  44. }