6
0
Fork 0
jiqu-library-server/app/helpers.php

57 lines
1.2 KiB
PHP

<?php
use App\Services\SettingService;
if (! function_exists('app_settings')) {
/**
* 获取/设置应用设置项
*
* @param array|string $key
* @param mixed $default
* @return mixed
*
* @return mixed|\App\Services\SettingService
*/
function app_settings($key = null, $default = null)
{
if (is_null($key)) {
return app(SettingService::class);
}
if (is_array($key)) {
return app(SettingService::class)->set($key);
}
return app(SettingService::class)->get($key, $default);
}
}
if (! function_exists('serial_number')) {
/**
* 生成流水号
*
* @return string
*/
function serial_number(): string
{
return date('YmdHis').sprintf('%06d', mt_rand(1, 999999));
}
}
if (! function_exists('trim_trailing_zeros')) {
/**
* 去除数字字符串小数点后多余的 0
*
* @param mixed $value
* @return mixed
*/
function trim_trailing_zeros($value)
{
if (is_numeric($value) && strpos($value, '.') !== false) {
$value = rtrim(rtrim($value, '0'), '.') ?: '0';
}
return $value;
}
}