备货单&审批流程

This commit is contained in:
mzl
2025-09-04 10:26:28 +08:00
parent 6a1ab1f5c3
commit 249b61ddb8
20 changed files with 1783 additions and 110 deletions
+29
View File
@@ -330,4 +330,33 @@ if (!function_exists('skuCode')) {
// 拼接:日期时间 + 微秒 + 随机数
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;
}
}