Number.php
1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* 订单号:
* 140705 89 8738 2394 379
* 年月日 渠道 用户ID 随机数
* User: ziy
* Date: 14-8-3
* Time: 下午1:51
*/
class YHMCart_Library_Number
{
/**
* 年月日 渠道 用户ID 随机数
* 140803-01-02993932-402
* @param $uid
* @param int $channel
* @param int $randLen
* @return string
*/
static function getOrderCode($uid, $channel = 1, $randLen = 99999)
{
if (!in_array($channel, YHMCart_Config::$channelCodeList)) {
#TODO Error
}
$mc = YHMUtils_Mc::getMc();
#TODO 获取标记的增量数字
$i=0;
while ($i < $randLen) {
$format = "%0" . strlen($randLen) . "d";
$randNumber = sprintf($format, mt_rand(0, $randLen));
$retData = $mc->get('order_' . $randNumber . '_uid_' . $uid);
if ($retData == "") {
$mc->set('order_' . $randNumber . '_uid_' . $uid, $randNumber, 84600);
break ;
}
}
$uidNumber = sprintf("%08d", $uid);
$channelNumber = sprintf("%02d", $channel);
return (int)(date('ymd') . $uidNumber . $randNumber);
}
}