This article mainly introduces the unique order function generated by php. For more information, see
This article mainly introduces the unique order function generated by php. For more information, see
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, you 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.