<?php

namespace app\api\service;

class UtilService
{
    public static function generateOrderNo($userId = 0,$str=null)
    {
        $microtime = microtime(true);
        $timestamp = date('YmdHis') . substr($microtime, 11, 3);


        $random = str_pad(mt_rand(0, 999999), 6, '0', STR_PAD_LEFT);


        $userPart = $userId ? substr(str_pad($userId, 4, '0', STR_PAD_LEFT), -4) : '';


        return $str.'-'. $timestamp . $random . ($userPart ? ('-' . $userPart) : '');
    }
}