From 1a969f4bb506c29943d7cdec4dbe5f835afef34e Mon Sep 17 00:00:00 2001 From: He110 Date: Wed, 13 Jun 2018 16:27:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8B=A5=E5=B9=B2=20BUG?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=AE=A2=E5=8D=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- despote/kernel/Utils.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/despote/kernel/Utils.php b/despote/kernel/Utils.php index d10fa58..bbd25b5 100644 --- a/despote/kernel/Utils.php +++ b/despote/kernel/Utils.php @@ -75,6 +75,10 @@ public static function isAssoc(array $arr) return array_keys($arr) !== range(0, count($arr) - 1); } + //////////// + // ID 相关 // + //////////// + /** * 获取 uuid(通用唯一标识符) * @param String $prefix uuid 的前缀 @@ -88,6 +92,19 @@ public function getUuid($prefix = '') return $uuid; } + /** + * 获取订单号 + * @param Integer $startYear 开始年份,默认为 2018 + * @return Array 每隔 n 年代表的字母,索引数组 + */ + public function getOrderId($startYear = 2018, array $yearCode = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']) + { + // 使用字母代表年份 + 月份的大写 16 进制值 + 当前月第几天 + 时间戳最后五位数 + 三位毫秒 + 两位微秒 + 两位随机数 + $orderId = $yearCode[intval(date('Y')) - $startYear] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99)); + + return $orderId; + } + ///////////// // 资源统计 // /////////////