84 lines
2.1 KiB
PHP
84 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* Here is your custom functions.
|
|
*/
|
|
|
|
|
|
if (!function_exists('generate_order_no')) {
|
|
/**
|
|
* 生成 前缀+24位数字的订单号
|
|
* @param string $prefix 前缀
|
|
* @return string
|
|
*/
|
|
function generate_order_no($prefix = '')
|
|
{
|
|
$randLen = 6;
|
|
$id = base_convert(substr(uniqid(), 0 - $randLen), 16, 10);
|
|
if (strlen($id) > 10) {
|
|
$id = substr($id, -10);
|
|
} elseif (strlen($id) < 10) {
|
|
$rLen = 10 - strlen($id);
|
|
$id = $id . rand(pow(10, $rLen - 1), pow(10, $rLen) - 1);
|
|
}
|
|
$dateTimeStr = date('YmdHis');
|
|
return $prefix . $dateTimeStr . $id;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 记录日志,默认存放路径为:{$config_path}/logs/{$dir_name}/ddddmm/d.log
|
|
* @dir_name logs/下的目录路径
|
|
* @data 日志数据
|
|
*/
|
|
if (!function_exists('raw_log')) {
|
|
function raw_log(string $dir_name, $data)
|
|
{
|
|
$log_path = runtime_path() . "/logs/{$dir_name}/" . date('Ym');
|
|
|
|
if (!is_dir($log_path)) {
|
|
mkdir($log_path, 0777, true);
|
|
}
|
|
$log_path .= '/' . date('d') . '.log';
|
|
$log = new Monolog\Logger($dir_name);
|
|
$log->pushHandler(new \Monolog\Handler\StreamHandler($log_path, \Monolog\Logger::INFO));
|
|
$log->info('', $data);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @desc 生成随机字符串
|
|
* @param $len
|
|
* @return string
|
|
* @throws \Random\RandomException
|
|
*/
|
|
if (!function_exists('random_str')) {
|
|
|
|
function random_str($len = 32)
|
|
{
|
|
return bin2hex(random_bytes(round($len / 2)));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('get_dates_in_month')) {
|
|
/**
|
|
* @desc 获取月份所有天
|
|
* @param $year
|
|
* @param $month
|
|
* @return array
|
|
*/
|
|
function get_dates_in_month($year, $month) {
|
|
$dates = [];
|
|
$firstDayOfMonth = new DateTime("$year-$month-01");
|
|
$lastDayOfMonth = clone $firstDayOfMonth;
|
|
$lastDayOfMonth->modify('last day of this month');
|
|
|
|
for ($currentDate = $firstDayOfMonth; $currentDate <= $lastDayOfMonth; $currentDate->modify('+1 day')) {
|
|
$dates[] = $currentDate->format('Y-m-d');
|
|
}
|
|
|
|
return $dates;
|
|
}
|
|
}
|