<!--#include virtual="/inc/conn.asp"-->
<%
Server.ScriptTimeOut = 999999

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

rs.open "select ayjihuayy,ayjihuaddwei,ayjihuaddbai,ayjihuacw,ayjihuakami,ayjihuauser,ayjihuarizhi,ayjihuaddday,ayjihuacwday,ayjihuakamiday,ayjihuauserday,ayjihuarizhiday,ayjihuaokddday,aychenbank,aychenalipay,aychentenpay from ayquanju" ,conn,1,1
ayjihuayy=rs("ayjihuayy")
ayjihuaddwei=rs("ayjihuaddwei")
ayjihuaddbai=rs("ayjihuaddbai")
ayjihuacw=rs("ayjihuacw")
ayjihuakami=rs("ayjihuakami")
ayjihuauser=rs("ayjihuauser")
ayjihuarizhi=rs("ayjihuarizhi")
ayjihuaddday=rs("ayjihuaddday")
ayjihuacwday=rs("ayjihuacwday")
ayjihuakamiday=rs("ayjihuakamiday")
ayjihuauserday=rs("ayjihuauserday")
ayjihuarizhiday=rs("ayjihuarizhiday")
ayjihuaokddday=rs("ayjihuaokddday")
aychenbank=rs("aychenbank")
aychenalipay=rs("aychenalipay")
aychentenpay=rs("aychentenpay")
rs.close

'清理session
if SafeRequest("act")="session" then
conn.execute("delete from logsession where datediff(day,logdate,'"&now()&"')>=1")
conn.execute("delete from userlog where datediff(day,userlogdate,'"&now()&"')>=90")
conn.execute("delete from aypayhuitiao where datediff(day,aypaytime,'"&now()&"')>=30")
response.Write "ok"
end if

'删除验证码信息
if SafeRequest("act")="yanzhengma" then
conn.execute("delete from ayyanzheng")
response.Write "ok"
end if


'删除验证码信息 year | quarter | month | week | day | hour | minute | second | millisecond
if SafeRequest("act")="weixinopen" then
conn.execute("delete from aywxhqopen where datediff(hour,aywxdate,'"&now()&"')>1")
response.Write "ok"
end if

'清理支付成功的订单
if SafeRequest("act")="dingdanqingli" then
For sum=0 To 5 '订单库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
if sum=0 then ddku="aydingdan"
if sum=1 then ddku="aydingdan01"
if sum=2 then ddku="aydingdan02"
if sum=3 then ddku="aydingdan03"
if sum=4 then ddku="aydingdan04"
if sum=5 then ddku="aydingdan05"
conn.execute("delete from "&ddku&" where datediff(day,aydingdansj,'"&now()&"')>'"&ayjihuaokddday&"' and aydingdanzt=1")
next
response.Write "ok"
end if

'提前清理 支付成功的订单
if SafeRequest("act")="dingdanqingli2" then

For sum=0 To 5 '订单库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
if sum=0 then ddku="aydingdan"
if sum=1 then ddku="aydingdan01"
if sum=2 then ddku="aydingdan02"
if sum=3 then ddku="aydingdan03"
if sum=4 then ddku="aydingdan04"
if sum=5 then ddku="aydingdan05"
conn.execute("delete from "&ddku&" where datediff(day,aydingdansj,'"&now()&"')>'"&clng(ayjihuaokddday)-1&"' and aydingdanzt=1")
next
response.Write "ok"
end if


'过期优惠券 手动清理
if SafeRequest("act")="guoqiyouhuiquan" then
	if cint(ayjihuayy)=1 then
	conn.execute("delete from ayyouhuiquan where datediff(day,ayyouhuidate,'"&now()&"')>ayyouhuishixiao")
	end if
response.Write "ok"
end if


'未支付订单 手动清理
if SafeRequest("act")="weizhifudingdan" then
	if cint(ayjihuaddwei)=1 then
	For sum=0 To 5 '订单库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
	if sum=0 then ddku="aydingdan"
	if sum=1 then ddku="aydingdan01"
	if sum=2 then ddku="aydingdan02"
	if sum=3 then ddku="aydingdan03"
	if sum=4 then ddku="aydingdan04"
	if sum=5 then ddku="aydingdan05"
	conn.execute("delete from "&ddku&" where datediff(day,aydingdansj,'"&now()&"')>'"&ayjihuaddday&"' and aydingdanzt=0")
	next
	end if
response.Write "ok"
end if


'失败订单 手动清理
if SafeRequest("act")="shibaidingdan" then
	if cint(ayjihuaddbai)=1 then
	For sum=0 To 5 '订单库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
	if sum=0 then ddku="aydingdan"
	if sum=1 then ddku="aydingdan01"
	if sum=2 then ddku="aydingdan02"
	if sum=3 then ddku="aydingdan03"
	if sum=4 then ddku="aydingdan04"
	if sum=5 then ddku="aydingdan05"
	conn.execute("delete from "&ddku&" where aydingdanzt=2 and datediff(day,aydingdansj,'"&now()&"')>'"&ayjihuaddday&"'")
	next
	end if
response.Write "ok"
end if


'财务记录自动清理
if SafeRequest("act")="caiwujilu" then
	if cint(ayjihuacw)=1 then
	For sum=0 To 5 '财务库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
	if sum=0 then cwku="aycaiwu"
	if sum=1 then cwku="aycaiwu01"
	if sum=2 then cwku="aycaiwu02"
	if sum=3 then cwku="aycaiwu03"
	if sum=4 then cwku="aycaiwu04"
	if sum=5 then cwku="aycaiwu05"
	conn.execute("delete from "&cwku&" where datediff(day,aycaiwudate,'"&now()&"')>'"&ayjihuacwday&"' and (aycaiwuleibie<>6 and aycaiwuleibie<>7 and aycaiwuleibie<>9 and aycaiwuleibie<>1)")
	next
	end if
response.Write "ok"
end if

'提前清理 财务记录
if SafeRequest("act")="caiwujilu2" then
	if cint(ayjihuacw)=1 then
	For sum=0 To 5 '财务库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
	if sum=0 then cwku="aycaiwu"
	if sum=1 then cwku="aycaiwu01"
	if sum=2 then cwku="aycaiwu02"
	if sum=3 then cwku="aycaiwu03"
	if sum=4 then cwku="aycaiwu04"
	if sum=5 then cwku="aycaiwu05"
	conn.execute("delete from "&cwku&" where datediff(day,aycaiwudate,'"&now()&"')>'"&clng(ayjihuacwday)-1&"' and (aycaiwuleibie<>6 and aycaiwuleibie<>7 and aycaiwuleibie<>9 and aycaiwuleibie<>1)")
	next
	end if
response.Write "ok"
end if


'结算记录 手动清理
if SafeRequest("act")="jiesuan3" then
	For sum=0 To 5 '财务库数量  总数量-1 如增加库 需修改updata\tongji下的相应文件  case "A"
	if sum=0 then cwku="aycaiwu"
	if sum=1 then cwku="aycaiwu01"
	if sum=2 then cwku="aycaiwu02"
	if sum=3 then cwku="aycaiwu03"
	if sum=4 then cwku="aycaiwu04"
	if sum=5 then cwku="aycaiwu05"
	conn.execute("delete from "&cwku&" where datediff(day,aycaiwudate,'"&now()&"')>180 and (aycaiwuleibie=1 or aycaiwuleibie=9)")
	next
response.Write "ok"
end if




'卖出卡密 自动清理
if SafeRequest("act")="maichukami" then
if cint(ayjihuakami)=1 then

For sum=0 To 30 '卡密库数量  
if sum=0 then kamiku="ayka"
if sum=1 then kamiku="ayka01"
if sum=2 then kamiku="ayka02"
if sum=3 then kamiku="ayka03"
if sum=4 then kamiku="ayka04"
if sum=5 then kamiku="ayka05"
if sum=6 then kamiku="ayka06"
if sum=7 then kamiku="ayka07"
if sum=8 then kamiku="ayka08"
if sum=9 then kamiku="ayka09"
if sum=10 then kamiku="ayka10"
if sum=11 then kamiku="ayka11"
if sum=12 then kamiku="ayka12"
if sum=13 then kamiku="ayka13"
if sum=14 then kamiku="ayka14"
if sum=15 then kamiku="ayka15"
if sum=16 then kamiku="ayka16"
if sum=17 then kamiku="ayka17"
if sum=18 then kamiku="ayka18"
if sum=19 then kamiku="ayka19"
if sum=20 then kamiku="ayka20"

if sum=21 then kamiku="ayka21"
if sum=22 then kamiku="ayka22"
if sum=23 then kamiku="ayka23"
if sum=24 then kamiku="ayka24"
if sum=25 then kamiku="ayka25"
if sum=26 then kamiku="ayka26"
if sum=27 then kamiku="ayka27"
if sum=28 then kamiku="ayka28"
if sum=29 then kamiku="ayka29"
if sum=30 then kamiku="ayka30"

conn.execute("delete from "&kamiku&" where datediff(day,aykakai,'"&now()&"')>'"&ayjihuakamiday&"' and aykayesno=1")
next

end if
response.Write "ok"
end if




'提前清理 卖出卡密
if SafeRequest("act")="maichukami2" then
For sum=0 To 30 '卡密库数量  
if sum=0 then kamiku="ayka"
if sum=1 then kamiku="ayka01"
if sum=2 then kamiku="ayka02"
if sum=3 then kamiku="ayka03"
if sum=4 then kamiku="ayka04"
if sum=5 then kamiku="ayka05"
if sum=6 then kamiku="ayka06"
if sum=7 then kamiku="ayka07"
if sum=8 then kamiku="ayka08"
if sum=9 then kamiku="ayka09"
if sum=10 then kamiku="ayka10"
if sum=11 then kamiku="ayka11"
if sum=12 then kamiku="ayka12"
if sum=13 then kamiku="ayka13"
if sum=14 then kamiku="ayka14"
if sum=15 then kamiku="ayka15"
if sum=16 then kamiku="ayka16"
if sum=17 then kamiku="ayka17"
if sum=18 then kamiku="ayka18"
if sum=19 then kamiku="ayka19"
if sum=20 then kamiku="ayka20"

if sum=21 then kamiku="ayka21"
if sum=22 then kamiku="ayka22"
if sum=23 then kamiku="ayka23"
if sum=24 then kamiku="ayka24"
if sum=25 then kamiku="ayka25"
if sum=26 then kamiku="ayka26"
if sum=27 then kamiku="ayka27"
if sum=28 then kamiku="ayka28"
if sum=29 then kamiku="ayka29"
if sum=30 then kamiku="ayka30"
conn.execute("delete from "&kamiku&" where datediff(day,aykakai,'"&now()&"')>'"&clng(ayjihuakamiday)-1&"' and aykayesno=1")
next

response.Write "ok"
end if






'站内信 手动清理
if SafeRequest("act")="zhanneixin" then
	if cint(ayjihuauser)=1 then
	conn.execute("delete from aytongzhi where t4=1 and datediff(day,aytongzhidate,'"&now()&"')>'"&ayjihuauserday&"'")
	end if
response.Write "ok"
end if


'日志 手动清理
if SafeRequest("act")="rizhi" then
	if cint(ayjihuarizhi)=1 then
	For sum=0 To 5 '卡密库数量  
	if sum=0 then rzku="aylog"
	if sum=1 then rzku="aylog01"
	if sum=2 then rzku="aylog02"
	if sum=3 then rzku="aylog03"
	if sum=4 then rzku="aylog04"
	if sum=5 then rzku="aylog05"
	conn.execute("delete from "&rzku&" where datediff(day,aylogdate,'"&now()&"')>'"&ayjihuarizhiday&"'")
	next
	end if
response.Write "ok"
end if
 


'手动 清理已绑定的密保卡 



'商户统计信息 清理
if SafeRequest("act")="tongjiqingli" then
conn.execute("delete from aypttj where datediff(day,ayptdate,'"&now()&"')>180 and aypttjuid<>0 and aypttjzq=3")
response.Write "ok"
end if


'详细结算日志 清理
if SafeRequest("act")="xiangxijiesuan" then
conn.execute("delete from ayjslist where datediff(day,ayjsdate,'"&now()&"')>180")
response.Write "ok"
end if


'销售统计 清理
if SafeRequest("act")="xiaoshoutongji" then
conn.execute("delete from ayxiaoshou where datediff(day,ayxsdate,'"&now()&"')>15")
response.Write "ok"
end if

'投诉率更新
if SafeRequest("act")="tousulv" then
	set rs3=server.CreateObject("adodb.recordset")
	set rs4=server.CreateObject("adodb.recordset")
	rs.open "select distinct ayjubaouid from ayjubao where ayjubaosjid=0",conn,1,1
	do while not rs.eof
	'response.Write rs("ayjubaouid")&"---"
		
		rs2.open "select top 1 aynameid,ddku,tousulv from ayname where aynameid="&rs("ayjubaouid")&"",conn,1,3
		if not(rs2.eof) then
		
			'rs3.open "select aydingdanuser,aydingdanzt from "&trim(rs2("ddku"))&" where aydingdanuser="&rs2("aynameid")&" and aydingdanzt=1",conn,1,1
			'response.Write rs3.RecordCount&"---"
			'ddsum=rs3.RecordCount
			'rs3.close
			
			set rs3=conn.execute("select count(*) as num from "&trim(rs2("ddku"))&" where aydingdanuser="&rs2("aynameid")&" and aydingdanzt=1")
			ddsum=rs3("num")
			
			'rs4.open "select ayjubaouid,ayjubaosjid from ayjubao where ayjubaouid="&rs2("aynameid")&" and ayjubaosjid=0",conn,1,1
			'response.Write rs4.RecordCount&"<br>"
			'tssum=rs4.RecordCount
			'rs4.close
			
			set rs4=conn.execute("select count(*) as num from ayjubao where ayjubaouid="&rs2("aynameid")&" and ayjubaosjid=0")
			tssum=rs4("num")
		
		if ccur(tssum)>ccur(ddsum) then 
		tousulv=0
		else
		tousulv=Formatnumber(tssum/ddsum*100,2,true,-1,0)
		end if
		
		rs2("tousulv")=tousulv
		rs2.update
			
		else
		'response.Write "无<br>"
		end if
		rs2.close
		
	rs.movenext
	loop
	rs.close
	response.Write "ok"
end if


'自动 清理已删除卡密
if SafeRequest("act")="delka" then

end if


'提前 清理已删除卡密
if SafeRequest("act")="delka2" then

end if



'VIP到期时间 邮件群发删除
if SafeRequest("act")="vip" then

	'VIP到期通知 检测
	rs.open "select aymail,isvipid,vipdate from ayname where isvipid=1",conn,1,3
	if not(rs.bof and rs.eof) then
	do while not rs.eof
		if DateDiff("d",now(),rs("vipdate"))<4 then
		conn.Execute("Insert Into mailto(mto,mti,mcon) values('"&trim(rs("aymail"))&"','VIP即将到期通知','亲爱的商家<br><br>您的VIP特权即将到期，请及时续费，感谢您的支持')")
		end if
		
		if DateDiff("d",now(),rs("vipdate"))<1 then
		rs("isvipid")=0
		rs.update
		end if
	rs.movenext 
	loop
	end if
	rs.close

	
	'套餐到期通知 检测
	rs.open "select aytczt,aytcbuyd,aytcsj,aytcuid from aytaocanlog where aytczt=0",conn,1,3
	if not(rs.bof and rs.eof) then
	do while not rs.eof
		if DateDiff("d",rs("aytcbuyd"),now())+3>=clng(rs("aytcsj")) then
			rs2.open "select aymail,aynameid from ayname where aynameid="&rs("aytcuid")&"",conn,1,1
			conn.Execute("Insert Into mailto(mto,mti,mcon) values('"&trim(rs2("aymail"))&"','商家套餐即将到期通知','亲爱的商家<br><br>您的商家套餐即将到期，请及时再次开通，感谢您的支持')")
			rs2.close
		end if
	
		if DateDiff("d",rs("aytcbuyd"),now())>=clng(rs("aytcsj")) then
		rs("aytczt")=1
		rs.update
		end if
	rs.movenext 
	loop
	end if
	rs.close

	conn.execute("delete from aylastsid")
	conn.execute("delete from ayjubao where datediff(day,aydate,'"&now()&"')>180 and ayjuzt=1")
	
	set linkw=fso.createtextfile(server.mappath("\updata\istongji.txt"),true)
	linkw.writeline now()
	linkw.close
	
	response.Write "ok"

end if


'买家联系方式 清理
if SafeRequest("act")="maijia" then
conn.execute("delete from aybuylx where datediff(day,aylogdate,'"&now()&"')>90")
response.Write "ok"
end if

%>