You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
695 B
21 lines
695 B
2 months ago
|
<?php
|
||
|
|
||
|
namespace app\utility;
|
||
|
|
||
|
|
||
|
class Tool
|
||
|
{
|
||
|
public function orderNo(int $length = 20)
|
||
|
{
|
||
|
$prefix = date('ymd'); // 可选的订单号前缀,如需要可以在这里设置
|
||
|
$timestamp = time();
|
||
|
$randomNum = mt_rand(10000, 99999); // 使用 mt_rand() 生成一个四位的随机数
|
||
|
// 将时间戳和随机数组合起来作为订单号的一部分
|
||
|
$orderNumber = $prefix . $timestamp . $randomNum;
|
||
|
// 如果订单号的长度超过指定的长度,则截取前面指定长度的部分
|
||
|
if (strlen($orderNumber) > $length) {
|
||
|
$orderNumber = substr($orderNumber, 0, $length);
|
||
|
}
|
||
|
return $orderNumber;
|
||
|
}
|
||
|
}
|