$str=date('Ymd').str_pad(mt_rand(1,99999),5,'0',STR_PAD_LEFT);
第二种
public function GetRandStr($length){
$str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($str)-1;
$randstr = date('Ymd');
for ($i=0;$i<$length;$i++) {
$num=mt_rand(0,$len);
$randstr .= $str[$num];
}
$res = $this->OrderRepository->getOne(['order_numbers'=>$randstr]);
if($res){
$this->GetRandStr(16);
}
return $randstr;
}
评论 (0)