第一种是以前写过的那种 , 订单号要多少位数自己控制,反正前面6位都是时间:
第二种是:
1,生成A类,B类两个表,
CREATE TABLE `order_id_a` (
`id` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT,
`stub` char(1) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
CREATE TABLE `order_id_b` (
`id` int(10) unsigned zerofill NOT NULL AUTO_INCREMENT,
`stub` char(1) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
其中,单数天是A类,双数是B类;
2,然后根据一定的规则生成17位的订单号:
<?php /** * 生成订单号表a * @param int $suid 门店id * @return string */ public static function getorderIdA($suid = 0) { $table = CaterDbTables::orderIdA(); $sql = "REPLACE INTO $table (stub) VALUES ('a')"; $conn = MysqlHelper::getInstance(); $id = $conn->insert($sql, 1); $system_num = '11'; return date('ymd') . $system_num . ($suid % 10) . sprintf("%08d", $id % 100000000); } /** * 生成订单号表b * @param int $suid 门店id * @return string */ public static function getorderIdB($suid = 0) { $table = CaterDbTables::orderIdB(); $sql = "REPLACE INTO $table (stub) VALUES ('b')"; $conn = MysqlHelper::getInstance(); $id = $conn->insert($sql, 1); $system_num = '11'; return date('ymd') . $system_num . ($suid % 10) . sprintf("%08d", $id % 100000000); }