|
|
@ -136,11 +136,62 @@ function format_phone_number($phoneNumber):string |
|
|
*/ |
|
|
*/ |
|
|
function rand_avatar() |
|
|
function rand_avatar() |
|
|
{ |
|
|
{ |
|
|
$avatarArr = config('custom.avatar') ?: []; |
|
|
$avatarArr = return_image_name('avatar') ?: config('custom.avatar'); |
|
|
$rand = rand(0,count($avatarArr)); |
|
|
$rand = rand(0,count($avatarArr)-1); |
|
|
return $avatarArr[$rand] ?: ''; |
|
|
return $avatarArr[$rand] ?: ''; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取目录下面的图片文件 |
|
|
|
|
|
* @param string $path |
|
|
|
|
|
* @return array |
|
|
|
|
|
*/ |
|
|
|
|
|
function return_image_name(string $path = 'icon'):array |
|
|
|
|
|
{ |
|
|
|
|
|
$public_path = public_path(); |
|
|
|
|
|
$imageDir = $public_path . '/storage/'.$path; |
|
|
|
|
|
|
|
|
|
|
|
$files = scandir($imageDir); // 获取目标文件夹下的文件名 |
|
|
|
|
|
|
|
|
|
|
|
// 过滤掉当前目录('.')和上级目录('..') |
|
|
|
|
|
$files = array_diff($files, ['.', '..']); |
|
|
|
|
|
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif']; |
|
|
|
|
|
foreach ($files as $key => $imageName) { |
|
|
|
|
|
# 获取文件后缀 |
|
|
|
|
|
$extension = pathinfo($imageName, PATHINFO_EXTENSION); |
|
|
|
|
|
# 过滤不是图片的文件或目录 |
|
|
|
|
|
if (!in_array(strtolower($extension),$imageExtensions)) { |
|
|
|
|
|
unset($files[$key]); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
# 组合路径 |
|
|
|
|
|
$files[$key] = $path . '/' . $imageName; |
|
|
|
|
|
} |
|
|
|
|
|
# 排序覆盖数组索引 |
|
|
|
|
|
sort($files); |
|
|
|
|
|
return $files; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 返回图片链接 |
|
|
|
|
|
* @param string $path // 获取目录下面的图片文件 |
|
|
|
|
|
* @param bool $is_http // true = 图片完整访问路径 |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
|
|
|
function rand_icon(string $path = 'icon',bool $is_http = false):string |
|
|
|
|
|
{ |
|
|
|
|
|
$files = return_image_name($path); |
|
|
|
|
|
if (empty($files)) return ''; |
|
|
|
|
|
$rand = rand(0,count($files)-1); |
|
|
|
|
|
$imageUrl = $files[$rand] ?: ''; |
|
|
|
|
|
if ($is_http) { |
|
|
|
|
|
$domain = \think\facade\Request::instance()->domain(); |
|
|
|
|
|
$url = config('filesystem.disks.public.url'); |
|
|
|
|
|
return $domain . $url . '/' . $imageUrl; |
|
|
|
|
|
} |
|
|
|
|
|
return $imageUrl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 返回金额 |
|
|
* 返回金额 |
|
|
* @param $number |
|
|
* @param $number |
|
|
|