12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\common\util;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\facade\Db;
- class OrderHelper
- {
-
- public static function createOrderNo($user_id): ?string
- {
- for ($i = 0; $i < 10000; $i++) {
-
- $no = date('YmdHis') . rand(1000, 9999) . $user_id;
- $exist = (new Db)->name('order')->where(["order_no" => $no])->find();
- if (!$exist) {
- return $no;
- }
- }
- return null;
- }
- }
|