mirror of
https://gitee.com/niucloud-team/niucloud-admin.git
synced 2025-12-16 12:22:48 +00:00
update
This commit is contained in:
parent
2f230c9255
commit
4df82d7fee
@ -370,7 +370,11 @@ function filter($string)
|
|||||||
*/
|
*/
|
||||||
function create_no(string $prefix = '', string $tag = '')
|
function create_no(string $prefix = '', string $tag = '')
|
||||||
{
|
{
|
||||||
return $prefix.date('YmdHis').$tag;
|
$data_center_id = 1;
|
||||||
|
$machine_id = 2;
|
||||||
|
$snowflake = new Snowflake($data_center_id, $machine_id);
|
||||||
|
$id = $snowflake->generateId();
|
||||||
|
return $prefix.date('Ymd').$tag.(string)$id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -7,8 +7,8 @@ class Snowflake
|
|||||||
|
|
||||||
// 各部分所占位数
|
// 各部分所占位数
|
||||||
const SEQUENCE_BITS = 12;
|
const SEQUENCE_BITS = 12;
|
||||||
const MACHINE_ID_BITS = 5;
|
const MACHINE_ID_BITS = 0;
|
||||||
const DATA_CENTER_ID_BITS = 5;
|
const DATA_CENTER_ID_BITS = 0;
|
||||||
|
|
||||||
// 最大值
|
// 最大值
|
||||||
const MAX_SEQUENCE = 4095;
|
const MAX_SEQUENCE = 4095;
|
||||||
@ -60,11 +60,10 @@ class Snowflake
|
|||||||
|
|
||||||
$this->last_timestamp = $timestamp;
|
$this->last_timestamp = $timestamp;
|
||||||
|
|
||||||
$id = (($timestamp - self::START_EPOCH) << (self::SEQUENCE_BITS + self::MACHINE_ID_BITS + self::DATA_CENTER_ID_BITS))
|
$id = (($timestamp - self::START_EPOCH) << (self::SEQUENCE_BITS))
|
||||||
| ($this->data_center_id << (self::SEQUENCE_BITS + self::MACHINE_ID_BITS))
|
// | ($this->data_center_id << (self::SEQUENCE_BITS + self::MACHINE_ID_BITS))
|
||||||
| ($this->machine_id << self::SEQUENCE_BITS)
|
// | ($this->machine_id << self::SEQUENCE_BITS)
|
||||||
| $this->sequence;
|
| $this->sequence;
|
||||||
|
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user