This article describes how to generate a unique order function in php. For more information, see the solution for generating order numbers.
E-commerce and e-commerce systems are growing. I believe that the order number problem is the most common problem in such systems, but I still want to talk about it today.
In the past few days, I have taken over a transaction system developed by another colleague, which was originally generated by the uniqid () function. Theoretically, there will be no duplicates, but for some special reasons, we have to re-create a function for generating order numbers.
The code is as follows:
/**
* Generate a unique order number 20110809111259232312
* 2011-date of the year
* 08-month
* 09-date
* 11-hour
* 12-minute
* 59-seconds
* 2323-microseconds
* 12-random value
* @ Return string
*/
Public function trade_no (){
List ($ usec, $ sec) = explode ("", microtime ());
$ Usec = substr (str_replace ('0. ', '', $ usec), 0, 4 );
$ Str = rand (10, 99 );
Return date ("YmdHis"). $ usec. $ str;
}
The above is all the content of this article. I hope you will like it.