First declare a reference variable in php. Prepare a reference value for subsequent splicing of random numbers. This value can be user ID, product ID, old order ID, etc. It is best to have fields in your own sql. $product_id = $_REQUEST['product_id'];
Declare a time variable. Get the value of the current time. $time=intval(time());
Declare this variable: $out_trade_no = $time.substr(ip2long($product_id), 3).rand(1000,9999);
This variable is spliced by three variables, namely: time + field in sql + randomly generated one-digit number