1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace App\Helper;
- class SerialNumber
- {
- /**
- * 订单号生存规则.
- *
- * @param int $bus_type 业务类型
- * @param int $user_id 用户ID
- *
- * @return string 订单号 20位数
- */
- public static function createOrderId($user_id = 0, $bus_type = 1)
- {
- $userId = substr($user_id, -7);
- $userId = str_pad($userId, 7, '0', STR_PAD_LEFT);
- $u1 = substr($userId, 0, 2);
- $u2 = substr($userId, 2, 2);
- $u3 = substr($userId, 4, 2);
- $u4 = substr($userId, 6, 1);
- unset($userId);
- $d = date('ymd');
- $timestamp = microtime(true) - strtotime(date('Y-m-d'));
- list($t1, $t2) = explode('.', $timestamp);
- unset($timestamp);
- $t1 = str_pad($t1, 5, '0', STR_PAD_LEFT);
- $t2 = intval(substr($t2, 0, 1));
- $b = intval($bus_type);
- unset($busType);
- return "{$b}{$u1}{$d}{$u2}{$t1}{$u3}{$t2}{$u4}";
- }
- }
|