12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\api\utils;
- use app\common\library\AliyunSms;
- use think\facade\Config;
- use app\common\base\utils\BaseUUID;
- /**
- * 后台控制器基类
- * 接口方法权限 必传参数 接口返回 错误抛出 通用参数处理
- */
- class UUIDUtils extends BaseUUID {
- private static $instance = null;
- protected $flag = 0; // 1
- protected $flagLength = 1; // 0-1
- protected $env = 0; // 0-7
- protected $envLength = 3; //
- protected $db = 0; // 0-255
- protected $dbLength = 8; // 8
- protected $server = 0; // 0-255
- protected $serverLength = 8; // 8
- protected $firstLength = 20;
- protected $secondLength = 31;
- protected $thirdLength = 31;
- protected $first36Length = 4;
- protected $second36Length = 6;
- protected $third36Length = 6;
- protected $timeLength = 42; // 0 - 4398046511103
- protected $randomLength = 12;
- protected $tableLength = 8; // 255
- protected $startTime = '1558713600000'; // 2019/5/25 0:0:0(1558713600000) - 2158/10/6 7:35:11(5956760111103)
- private function __construct() {
- $this->initOptions();
- }
- private function initOptions() {
- [
- 'flag' => $this->flag,
- 'env' => $this->env,
- 'db' => $this->db,
- 'server' => $this->server,
- 'startTime' => $this->startTime
- ] = Config::get('uuid_options');
- }
- private static function getInstance() {
- return is_null(self::$instance) ? new UUIDUtils() :self::$instance;
- }
- public static function uuid($table = -1) {
- if(is_string($table) && strlen($table) === 16) {
- $table = self::pasreTable($table);
- }
- if(!is_numeric($table) || $table < 0) {
- $table = -1;
- }
- return self::getInstance()->_generateUUID($table);
- }
- public static function pasre($uuid) {
- return self::getInstance()->_pasreUUID($uuid);
- }
- public static function pasreTable($uuid) {
- return self::getInstance()->_pasreTable($uuid);
- }
- }
|