生成唯一订单号,后四位为id的后四位,不足四位的补充0填充
function build_order_no($uid){ //uid后四位 $uid_len = strlen($uid); if ($uid_len != 4){ if ($uid_len>4){ $after_uid = substr($uid,-4); }else{ $after_uid = ''; for ($i = 1 ; $i < (5 - $uid_len) ;$i++){ $after_uid .= 0; } $after_uid .= $uid; } }else{ $after_uid = $uid; } //获得微秒数 $un_number = substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8); return date('ymdhis').$un_number.$after_uid; } 复制代码 |
得到的单号是24位的例如:
161127035032565256560001