class Pay extends Web { /** * 最多以每秒999个的速度生成13位订单号 * * @return string */ function getOrderId() { //哪年,哪天,哪一秒 $base = date('y') . date('z') . str_pad((date('H') * 60 * 60 + date('i') * 60 + date('s')), 5, 0, STR_PAD_LEFT); $next_sec = time() + 1; $pre_max_id = 999; while(time() < $next_sec) { $order_id = mt_rand(1, $pre_max_id); $store_key = parent::getCacheKey('orderIdCache', $base, $order_id); $setRet = $this->store->setnx($store_key, 1); if ($setRet) { $this->store->expire($store_key, 5); return $base.str_pad($order_id, 3, 0, STR_PAD_LEFT); } else { continue; } } return $this->getOrderId(); } }
![php中文网最新课程二维码](/static/images/article_wechat2021.jpg?1111)
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论