Merge branch 'develop'

This commit is contained in:
mzl
2025-09-16 10:53:57 +08:00
parent b399f85707
commit 62c32d25ff
210 changed files with 15388 additions and 95 deletions
+80
View File
@@ -307,4 +307,84 @@ if (!function_exists('generateMsgId')) {
// 拼接:日期时间 + 微秒 + 随机数
return $date . $micro . $rand;
}
}
/**
* 生成sku_code
* 格式:年月日时分秒 + 微秒 + 随机数
* 例如:20250820175530987654321
*
* @return string
*/
if (!function_exists('skuCode')) {
function skuCode(): string
{
// 时间部分(精确到微秒)
$time = microtime(true);
$micro = sprintf("%06d", ($time - floor($time)) * 1e6);
$date = date('YmdHis', (int)$time);
// 随机部分(3位)
$rand = mt_rand(100, 999);
// 拼接:日期时间 + 微秒 + 随机数
return $date . $micro . $rand;
}
}
/**
* 生成备货单编号(预占式,每天从1开始)
*
* @return string
*/
if (!function_exists('generateStockNo')) {
function generateStockNo(string $prefix = 'BH', int $serialLength = 3): string
{
$date = date('Ymd');
$key = "stock:order:serial:{$date}";
// 原子递增获取当日流水号
$serial = \support\Redis::incr($key);
// 首次创建时设置过期时间:到明天凌晨 + 1小时(容错)
if ($serial === 1) {
$tomorrow = strtotime(date('Y-m-d', strtotime('+1 day')));
$expireSeconds = $tomorrow - time() + 3600; // 多加1小时
\support\Redis::expire($key, $expireSeconds);
}
// 格式化流水号(补零)
$paddedSerial = str_pad($serial, $serialLength, '0', STR_PAD_LEFT);
return $prefix . $date . $paddedSerial;
}
}
/**
* 发送通知
*
* @param string $title
* @param string $content
* @param string $url
* @param string $type
* @return void
*/
if (!function_exists('noticePush')) {
function noticePush(array $notice = [])
{
/*
消息字段:
'sender_id' //发送人
'sender_type' //发送人类型
'title' //标题
'content' //内容
'scene' //场景
'recipient' //接收人
'push_method' //推送方式
// 如果需要同时 邮箱推送 增加推送邮箱字段
'email' //邮箱
*/
\Webman\RedisQueue\Redis::send('notice', $notice);
}
}