创建订单时候订单号已存在情况下为什么不直接再次生成而是返回 false 呢?
public static function findAvailableNo()
{
// 订单流水号前缀
$prefix = date('YmdHis');
for ($i = 0; $i < 10; $i++) {
// 随机生成 6 位的数字
$no = $prefix.str_pad(random_int(0, 999999), 6, '0', STR_PAD_LEFT);
// 判断是否已经存在
if (!static::where('no', $no)->exists()) {
return $no;
}
}
\Log::warning('find order no failed');
return false;
}
推荐文章: