no message
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
class ShortLink extends BaseModel
|
||||
{
|
||||
protected $name = 'short_link';
|
||||
|
||||
/**
|
||||
* @notes 生成唯一随机码
|
||||
*/
|
||||
public static function generateCode(int $length = 8): string
|
||||
{
|
||||
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789';
|
||||
do {
|
||||
$code = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$code .= $chars[random_int(0, strlen($chars) - 1)];
|
||||
}
|
||||
} while (self::where('code', $code)->findOrEmpty()->isExists());
|
||||
return $code;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user