Skip to content

Commit

Permalink
修复若干 BUG,增加订单生成函数
Browse files Browse the repository at this point in the history
  • Loading branch information
He110te4m committed Jun 13, 2018
1 parent 7939b26 commit 1a969f4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions despote/kernel/Utils.php
Expand Up @@ -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 的前缀
Expand All @@ -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;
}

/////////////
// 资源统计 //
/////////////
Expand Down

0 comments on commit 1a969f4

Please sign in to comment.