SerialNumber.php 950 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Helper;
  3. class SerialNumber
  4. {
  5. /**
  6. * 订单号生存规则
  7. *
  8. * @param int $bus_type 业务类型
  9. * @param int $user_id 用户ID
  10. * @return string 订单号 20位数
  11. */
  12. public static function createOrderId($user_id = 0, $bus_type = 1)
  13. {
  14. $userId = substr($user_id, -7);
  15. $userId = str_pad($userId, 7, "0", STR_PAD_LEFT);
  16. $u1 = substr($userId, 0, 2);
  17. $u2 = substr($userId, 2, 2);
  18. $u3 = substr($userId, 4, 2);
  19. $u4 = substr($userId, 6, 1);
  20. unset($userId);
  21. $d = date("ymd");
  22. $timestamp = microtime(true) - strtotime(date('Y-m-d'));
  23. list($t1, $t2) = explode(".", $timestamp);
  24. unset($timestamp);
  25. $t1 = str_pad($t1, 5, "0", STR_PAD_LEFT);
  26. $t2 = intval(substr($t2, 0, 1));
  27. $b = intval($bus_type);
  28. unset($busType);
  29. return "{$b}{$u1}{$d}{$u2}{$t1}{$u3}{$t2}{$u4}";
  30. }
  31. }