SerialNumber.php 992 B

1234567891011121314151617181920212223242526272829303132333435
  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. *
  11. * @return string 订单号 20位数
  12. */
  13. public static function createOrderId($user_id = 0, $bus_type = 1)
  14. {
  15. $userId = substr($user_id, -7);
  16. $userId = str_pad($userId, 7, '0', STR_PAD_LEFT);
  17. $u1 = substr($userId, 0, 2);
  18. $u2 = substr($userId, 2, 2);
  19. $u3 = substr($userId, 4, 2);
  20. $u4 = substr($userId, 6, 1);
  21. unset($userId);
  22. $d = date('ymd');
  23. $timestamp = microtime(true) - strtotime(date('Y-m-d'));
  24. list($t1, $t2) = explode('.', $timestamp);
  25. unset($timestamp);
  26. $t1 = str_pad($t1, 5, '0', STR_PAD_LEFT);
  27. $t2 = intval(substr($t2, 0, 1));
  28. $b = intval($bus_type);
  29. unset($busType);
  30. return "{$b}{$u1}{$d}{$u2}{$t1}{$u3}{$t2}{$u4}";
  31. }
  32. }