您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php生成唯一订单号的5种方法

2024/3/14 13:02:55发布28次查看
这篇文章主要介绍了关于php生成唯一订单号的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
php 生成唯一订单号5种方法
第一种
private function docreateordernumber($time){ $i=1; $dd = date('ymd',$time); $aa = 'oh'.$dd; $res = $this->ordermodel->query("select sn from sr_order_list where sn like '$aa%' order by id limit 1"); if(!isset($res[0]['sn'])){ $i = 1; }else{ $i = (int)substr($res[0]['sn'],9,10) + 1; } while(true){ $nsn = 'oh'.$dd.$i; $exist = $this->ordermodel->query("select id from sr_order_list where sn = '$nsn' "); if($exist){ $i++; }else{ return $nsn; } } }
第二种
$osn = date('ymd') . str_pad(mt_rand(1, 99999), 5, '0', str_pad_left);echo $osn; //2018070462577
第三种
$osn = date('ymd').substr(implode(null, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);echo $osn; //2018070499495653
第四种
$order_id_main = date('ymdhis') . rand(10000000,99999999); $order_id_len = strlen($order_id_main); $order_id_sum = 0; for($i=0; $i<$order_id_len; $i++){ $order_id_sum += (int)(substr($order_id_main,$i,1)); } $osn = $order_id_main . str_pad((100 - $order_id_sum % 100) % 100,2,'0',str_pad_left);echo $osn; //201807041332258742313727
第五种
$code = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');$osn = $code[intval(date('y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));echo $osn; //h704764673624352
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注!
相关推荐:
php实现微信支付的代码
php 7.1安装xhprof进行性能分析的介绍
以上就是php生成唯一订单号的5种方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product