ql_apimanager_backend/Apimanager_backend/Tools/OrderNumberGenerator.cs

15 lines
587 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Apimanager_backend.Tools
{
public static class OrderNumberGenerator
{
public static string Generate(int userId = 0, string prefix = "ORD")
{
var datePart = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff"); // 17位
var userPart = (userId % 10000).ToString("D4"); // 后4位用户ID
var randPart = Random.Shared.Next(1000, 9999).ToString(); // 4位随机数
return $"{prefix}{datePart}{userPart}{randPart}"; // 最终ORD + 时间 + 用户 + 随机数
}
}
}