You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Support;
|
|
|
|
|
|
|
|
|
|
|
|
use Overtrue\Pinyin\Pinyin;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 场馆后台账号:用户名(拼音首字母缩写)与密码(首尾大写 + @)规则。
|
|
|
|
|
|
*/
|
|
|
|
|
|
final class VenueAdminCredentials
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 由场馆名称得到拼音首字母缩写(小写、仅字母数字),用于用户名及密码变换的基底。
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static function acronymFromVenueName(string $name): string
|
|
|
|
|
|
{
|
|
|
|
|
|
$joined = Pinyin::abbr($name)->join('');
|
|
|
|
|
|
$joined = strtolower($joined);
|
|
|
|
|
|
$joined = preg_replace('/[^a-z0-9]/', '', $joined) ?? '';
|
|
|
|
|
|
|
|
|
|
|
|
return $joined !== '' ? $joined : 'v';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 由「缩写基底」生成密码:首字母大写、中间小写、末字母大写、末尾 @。
|
|
|
|
|
|
* 例:zjgkjg → ZjgkjG@
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static function passwordFromAcronym(string $acronymLower): string
|
|
|
|
|
|
{
|
|
|
|
|
|
$slug = strtolower(preg_replace('/[^a-z0-9]/', '', $acronymLower) ?? '');
|
|
|
|
|
|
if ($slug === '') {
|
|
|
|
|
|
return 'Xx@';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$len = strlen($slug);
|
|
|
|
|
|
if ($len === 1) {
|
|
|
|
|
|
return strtoupper($slug[0]).'@';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$first = strtoupper($slug[0]);
|
|
|
|
|
|
$last = strtoupper($slug[$len - 1]);
|
|
|
|
|
|
$middle = strtolower(substr($slug, 1, $len - 2));
|
|
|
|
|
|
|
|
|
|
|
|
return $first.$middle.$last.'@';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|