Home >Backend Development >PHP Tutorial >PHP生成唯一订单号方法算法

PHP生成唯一订单号方法算法

WBOY
WBOYOriginal
2016-06-20 13:01:021741browse

在开发购物类电子商务网站的时候,常常涉及到生成订单,如何保证每个订单唯一呢,在PHP开发网站中,PHP生成唯一订单号方法

/**
* 生成唯一订单号
*/
public function build_order_no()
{
    $no = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
    //检测是否存在
    $db = M('Order');
    $info = $db->where(array('number'=>$no))->find();
    (!empty($info)) && $no = $this->build_order_no();
    return $no;

}

 


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn