<!--#include virtual="/inc/conn.asp"--> 
<%
'####################在通知工具使用 请见页底提示##################################################################
'####################在通知工具使用 请见页底提示##################################################################

On error resume next 
Server.ScriptTimeOut = 999999

mulu="\updata\upkami_fenge\"		'分割文件目录
fengesum=2000						'分割条数设置######################

'日期格式补零
function FillZero(str)
	if len(str)=1 then
	FillZero = "0"&str
	else
	FillZero=str
	end if
end function

'获取完整时间+随机4位
function nowtime()
time_start=year(now)&FillZero(month(now))&FillZero(day(now))&FillZero(hour(now))&FillZero(minute(now))&FillZero(second(now))	'20190419155601
Const stringmodarr = "0123456789"
strlength = Len(stringmodarr)
Randomize timer
For i = 1 To 4 
randarr = randarr&Mid(stringmodarr,Int(Rnd * strlength + 1),1)  
Next 
nowtime=time_start&randarr
end function

'创建文件
function addtxt(addname)
Set txtadd = fso.CreateTextFile(server.MapPath(addname), True)   
txtadd.Close
end function

set rsto=server.CreateObject("adodb.recordset")
Set fso=Server.CreateObject("Scripting.FileSystemObject")

if Application("hostshibie")="" then 
response.Write "缺少系统标识"
response.End()
end if

isnext="no"
		

						'txt文件分解
						isfenjie="no"
						txtstr=""
						rsto.open "select top 1 * from aytxtka where sytxtsj=0 and aytxtzt=0 and aytxthost='"&Application("hostshibie")&"'",conn,1,1
						if not(rsto.bof and rsto.eof) then 
						isfenjie="yes"
						aytxtid=rsto("aytxtid")				'ID
						aytxtuid=rsto("aytxtuid")			'所属会员
						aytxtgid=rsto("aytxtgid")			'所属商品
						aytxtname=trim(rsto("aytxtname"))	'文件目录
						aytxtjc=rsto("aytxtjc")				'检查重复
						else
						isnext="yes"
						end if
						rsto.close
						
						if isfenjie="yes" then
							'读取
							jishu=1
							set txtread=fso.opentextfile(server.mappath(aytxtname),1,true)
							do while not txtread.atendofstream
							txtstr=txtstr&txtread.readline&CHR(13)&CHR(10)
							
								if jishu mod fengesum = 0 then
								txtname=mulu&nowtime()&".txt"	'分割txt文件名
								
									if txtstr<>CHR(13)&CHR(10) then
										call addtxt(txtname)			'创建分割txt文件
										conn.Execute("Insert Into aytxtka(aytxtuid,aytxtgid,aytxthost,aytxtname,aytxtjc,sytxtsj) values('"&aytxtuid&"','"&aytxtgid&"','"&Application("hostshibie")&"','"&txtname&"','"&aytxtjc&"','"&aytxtid&"')")
										set txtwrite=fso.createtextfile(server.mappath(txtname),true)'写入分割文件
										txtwrite.writeline txtstr
										txtwrite.close
									end if
									
								txtstr=""
								end if
							
							jishu=jishu+1
							loop
							'不满分割数量要求的剩余数据 写入
							txtname=mulu&nowtime()&".txt"	'分割txt文件名
							
								if txtstr<>CHR(13)&CHR(10) then
									call addtxt(txtname)			'创建分割txt文件
									conn.Execute("Insert Into aytxtka(aytxtuid,aytxtgid,aytxthost,aytxtname,aytxtjc,sytxtsj) values('"&aytxtuid&"','"&aytxtgid&"','"&Application("hostshibie")&"','"&txtname&"','"&aytxtjc&"','"&aytxtid&"')")
									set txtwrite=fso.createtextfile(server.mappath(txtname),true)'写入分割文件
									txtwrite.writeline txtstr
									txtwrite.close
									txtread.close
								end if
								
						conn.execute "update aytxtka set aytxtzt=1 where aytxtid='"&aytxtid&"'"
						isnext="yes"	
						end if
						
						


						'写入数据库*********************************
						isadd="no"
						rsto.open "select top 1 * from aytxtka where sytxtsj<>0 and aytxtzt=0 and aytxthost='"&Application("hostshibie")&"'",conn,1,1
						if not(rsto.bof and rsto.eof) then 
						isadd="yes"
						aytxtid=rsto("aytxtid")
						aytxtuid=rsto("aytxtuid")			'所属会员
						aytxtgid=rsto("aytxtgid")			'所属商品
						aytxtname=trim(rsto("aytxtname"))	'文件目录
						aytxtjc=rsto("aytxtjc")				'检查重复
						kamiku=getkamikuname(aytxtuid)
						url=Replace(aytxtname,"/", "\")
						else
						isnext="yes"
						end if
						rsto.close

						
						if isadd="yes" then
							jishu=0
							strka=""
							strmi=0
							kstr=""
									
							set txt=fso.opentextfile(server.mappath(url),1,true) 
							do While not txt.atendofstream
							kstr=txt.readline
							kstr=Replace(kstr,CHR(9)," ") 
							kstr=trim(kstr)
			
								if trim(kstr)<>"" then	
								
									kstr=Replace(kstr," ","~~")
									
									mimastr=split(trim(kstr),"~~")
									if Ubound(mimastr)=0 then
									strka=trim(mimastr(0))
									strmi="0"
									elseif Ubound(mimastr)>0 then
									strka=trim(mimastr(0))
									if trim(mimastr(1))<>"" then strmi=trim(mimastr(1))
									end if
							
									if trim(strka)<>"" and cint(aytxtjc)=1 then	
										set rsnum=conn.execute("select count(*) as num from "&kamiku&" where ayka='"&strka&"' and aykapass='"&strmi&"' and aykagoodid="&aytxtgid&" and aykayesno=0")
										if cint(rsnum("num"))=0 then 
										jishu=jishu+1	
										conn.Execute("Insert Into "&kamiku&"(ayka,aykapass,aykasuoyou,aykagoodid) values('"&strka&"','"&strmi&"','"&aytxtuid&"','"&aytxtgid&"')")
										end if
									end if
									
									if trim(strka)<>"" and cint(aytxtjc)=0 then	
										jishu=jishu+1	
										conn.Execute("Insert Into "&kamiku&"(ayka,aykapass,aykasuoyou,aykagoodid) values('"&strka&"','"&strmi&"','"&aytxtuid&"','"&aytxtgid&"')")	
									end if
									
										
								end if
							loop
							txt.close

							
						conn.execute "update aytxtka set aytxtzt=2,aytxtsum="&jishu&" where aytxtid='"&aytxtid&"'"
						conn.Execute("Insert Into "&getrizhikuname(aytxtuid)&"(ayloguserid,aylogcon,aylogip,aylogleibie,aylogerr) values("&aytxtuid&",'"&aytxtgid&"@#-队列加卡"&jishu&"张','127.0.0.1','3','0')")
						isnext="yes"
						end if
						 


response.Write now()&"-"	'#################在通知工具使用 请注释此行#################################################################################################
response.Write "OK<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>"
%>


<%'##########################################在通知工具使用 请删除以下三行#################################################################################################%>
<%if isnext="yes" or err.number<>0 then%>
<script>setTimeout("location.href='/inc/txtaoto.asp'",5000)</script>
<%end if%>


