浏览代码

Add snowflake id service

Daniel Supernault 4 年之前
父节点
当前提交
c0076ab035
共有 1 个文件被更改,包括 18 次插入0 次删除
  1. 18 0
      app/Services/SnowflakeService.php

+ 18 - 0
app/Services/SnowflakeService.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Services;
+
+use Illuminate\Support\Carbon;
+
+class SnowflakeService {
+
+	public static function byDate(Carbon $ts = null)
+	{
+		$ts = $ts ? now()->parse($ts)->timestamp : microtime(true);
+		return ((round($ts * 1000) - 1549756800000) << 22)
+		| (1 << 17)
+		| (1 << 12)
+		| 0;
+	}
+
+}