php代码
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();
}
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号