第一种
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; //2019070462577
第三种
$osn = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
echo $osn; //2019070499495653
第四种
$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