Commit beae8456 authored by wangzhengwen's avatar wangzhengwen

订单号生成优化

parent d7fa8090
...@@ -19,13 +19,14 @@ class UtilService ...@@ -19,13 +19,14 @@ class UtilService
// return $str.'-'. $timestamp . $random . ($userPart ? ('-' . $userPart) : ''); // return $str.'-'. $timestamp . $random . ($userPart ? ('-' . $userPart) : '');
// } // }
public static function generateCompactOrderNo($userId = null,$str=null) //生成订单号 示例 ORD-042-230815123456789
public static function generateCompactOrderNo($userId = null, $prefix = null)
{ {
$time = substr(time(), -6); // 取时间戳后6位 $time = date('ymdHis');
$rand = mt_rand(100000, 999999); // 6位随机数 $rand = mt_rand(100, 999);
$user = $userId ? chr(65 + ($userId % 26)) : ''; // 用户标识转A-Z $userCode = $userId ? str_pad($userId % 1000, 3, '0', STR_PAD_LEFT) : '';
return $str . $user . $time . $rand; return trim(implode('-', array_filter([$prefix, $userCode, $time.$rand])), '-');
} }
public static function listWithTags($list, string $modelClass, string $tagIdsField = 'tag_ids'): array public static function listWithTags($list, string $modelClass, string $tagIdsField = 'tag_ids'): array
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment