日期:2014-05-17  浏览次数:20776 次

asp怎么订单生成流水号不重复
<%dim shijian,dingdan
 shijian=now()
 set rs=server.CreateObject("adodb.recordset")
 rs.open "select * from shopxp_action where username='"&username&"' and zhuangtai=7",conn,1,3
 if request.Cookies("shopxp")("username")<>"" then
 dingdan=now()&Right("00000"& Round(Rnd*89999,0),5)
 dingdan=replace(trim(dingdan),"-","")
 dingdan=replace(dingdan,":","")
 dingdan=replace(dingdan," ","")
 else
 dingdan=username
 end if
 do while not rs.eof
 rs("zhuangtai")=1
 rs("dingdan")=dingdan
 rs("dingdan2")=dingdan2
 rs.movenext
 loop
 rs.close%>
订单号太长了,能不能改成短的订单号显示是2012111222252863499怎么给他改成流水号?流水号不能重复的。而这订单号可能还是重复的。
------解决方案--------------------
不要随机
年月日+5位数流水号
一般就不会重复了
------解决方案--------------------
但是太长了,可不可以这样写,这样写对吗,可以实现这个功能了吗
为什么我这Right("00000"& Round(Rnd*89999,0),5)流水号好下个每个订单都是63499
数,流水号不会不是不变,这个回事,下面的代码对吗重点是判断订单是否重复,大家帮我看看。

dim shijian,dingdan
shijian=now()
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from shopxp_action where username='"&username&"' and zhuangtai=7",conn,1,3
if request.Cookies("shopxp")("username")<>"" then
 If rs.eof Then
dingdan=now()+1
  dingdan=replace(trim(dingdan),"-","")
  dingdan=replace(dingdan,":","")
  dingdan=replace(dingdan," ","")
else
dingdan=now()
  dingdan=replace(trim(dingdan),"-","")
  dingdan=replace(dingdan,":","")
  dingdan=replace(dingdan," ","")
end if
else
dingdan=username
end if
do while not rs.eof
------解决方案--------------------
超强固定的18位随机数,日期时间+4位随机数,永不重复



<%
y=cstr(year(now()))
m=cstr(month(now()))
If len(m)=1 Then
m="0"&m
end if
d=cstr(day(now()))
If len(d)=1 Then
d="0"&d
end if
h=cstr(hour(now()))
If len(h)=1 Then
h="0"&h
end if
n=cstr(minute(now()))
If len(n)=1 Then
n="0"&n
end if
s=cstr(second(now()))
If len(s)=1 Then
s="0"&s
end if
str_now=y&""&m&""&d&""&h&""&n&""&s
Function gen_key(digits)
dim char_array(10)
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
randomize
do while len(output) < digits
num = char_array(Int((9 - 1 + 1) * Rnd + 0))
output = output + num
loop
gen_key = str_now & output
End Function
strrad=gen_key(4)

response.Write(strrad)
%>


------解决方案--------------------
造一堆流水号。每天清零使用。