购物车迁入
This commit is contained in:
17
ba/Exception.php
Normal file
17
ba/Exception.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace ba;
|
||||
|
||||
use think\Exception as E;
|
||||
|
||||
/**
|
||||
* BuildAdmin通用异常类
|
||||
* catch 到异常后可以直接 $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
|
||||
*/
|
||||
class Exception extends E
|
||||
{
|
||||
public function __construct(protected $message, protected $code = 0, protected $data = [])
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
}
|
||||
54
ba/Random.php
Normal file
54
ba/Random.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace ba;
|
||||
|
||||
class Random
|
||||
{
|
||||
/**
|
||||
* 获取全球唯一标识
|
||||
* @return string
|
||||
*/
|
||||
public static function uuid(): string
|
||||
{
|
||||
return sprintf(
|
||||
'%04x%04x-%04x-%04x-%04x-',
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0x0fff) | 0x4000,
|
||||
mt_rand(0, 0x3fff) | 0x8000
|
||||
) . substr(md5(uniqid(mt_rand(), true)), 0, 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机字符生成
|
||||
* @param string $type 类型 alpha/alnum/numeric/noZero/unique/md5/encrypt/sha1
|
||||
* @param int $len 长度
|
||||
* @return string
|
||||
*/
|
||||
public static function build(string $type = 'alnum', int $len = 8): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'alpha':
|
||||
case 'alnum':
|
||||
case 'numeric':
|
||||
case 'noZero':
|
||||
$pool = match ($type) {
|
||||
'alpha' => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'alnum' => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
'numeric' => '0123456789',
|
||||
'noZero' => '123456789',
|
||||
default => '',
|
||||
};
|
||||
return substr(str_shuffle(str_repeat($pool, ceil($len / strlen($pool)))), 0, $len);
|
||||
case 'unique':
|
||||
case 'md5':
|
||||
return md5(uniqid(mt_rand()));
|
||||
case 'encrypt':
|
||||
case 'sha1':
|
||||
return sha1(uniqid(mt_rand(), true));
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user