<!--#include virtual="/inc/conn.asp"-->
<!--#include virtual="/inc/chkuser.asp"-->
<%

tongjiuser=SafeRequest("id")

sql="select aynameid,ddku,cwku from ayname where aynameid="&clng(tongjiuser)&""  
rs.open sql,conn,1,1
ddku=trim(rs("ddku"))
cwku=trim(rs("cwku"))
rs.close

sql="select top 15 * from aypttj where aypttjzq=3 and aypttjuid="&clng(tongjiuser)&" order by ayptdate desc"  
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
'response.Write rs("aypttjjl")&"<br>"
rs.delete
rs.movenext
loop
end if
rs.close

sql="select top 3 * from aypttj where aypttjzq=2 and aypttjuid="&clng(tongjiuser)&" order by ayptdate desc"  
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
'response.Write rs("aypttjjl")&"<br>"
rs.delete
rs.movenext
loop
end if
rs.close

'response.End()


sql="select top 1 * from aypttj where aypttjzq=1 and aypttjuid="&clng(tongjiuser)&" order by ayptdate desc"  
rs.open sql,conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof
'response.Write rs("aypttjjl")&"<br>"
rs.delete
rs.movenext
loop
end if
rs.close

'response.End()


'**********************************************************************

'平台账务统计
today=now()
yearno=Year(today)															'当年计时 2013
monthno=Year(today)&Right("0" & Month(today),2)  							'当月计时 201311
todayno=Year(today)&Right("0" & Month(today),2)&Right("0" & Day(today),2)  '当日计时 20131125
yyearno=Year(DateAdd("yyyy",-1,today))											 '去年计时2012
ymonthno=Year(DateAdd("m",-1,today))&Right("0" & Month(DateAdd("m",-1,today)),2) '上月计时201210
ytodayno=Year(DateAdd("d",-1,today))&Right("0" & Month(DateAdd("d",-1,today)),2)&Right("0" & Day(DateAdd("d",-1,today)),2)'昨日计时20121124
set rst=server.CreateObject("adodb.recordset")
set rsj=server.CreateObject("adodb.recordset")

'往日统计
n=1

tosum=180

for daynum=1 to tosum

wrinoda=DateAdd("d",-n,now()) '往日缩写 '20160118
wrino=Year(DateAdd("d",-n,today))&Right("0" & Month(DateAdd("d",-n,today)),2)&Right("0" & Day(DateAdd("d",-n,today)),2) '2016-1-18 21:26:56

'response.Write wrino&"<br>"
'response.Write wrinoda&"<br>"
'response.end

sqlt="select top 1 * from aypttj where aypttjuid="&clng(tongjiuser)&" and aypttjjl='"&wrino&"' and aypttjzq=3"  
rst.open sqlt,conn,1,3
if rst.bof and rst.eof then


	sqlj="select aydingdanin,aydingdanuser,aydingdansj,aydingdanzt,aydingdanzj,aydingdancb,ayddquantity,ayddzffangshi from "&ddku&" where aydingdanuser="&clng(tongjiuser)&" and datediff(day,aydingdansj,'"&wrinoda&"')=0 and aydingdanzt=1" 
	rsj.open sqlj,conn,1,3
	minje=0    '订单总价
	num=0     '成交笔数
	paybank=0  '网银成交
	payalipay=0 '支付宝成交
	paytenpay=0 '财付通成交
	paycard=0  '充值卡成交
	paybankj=0
	payalipayj=0
	paytenpayj=0
	paycardj=0
	ddlirun=0 '订单利润
	ayptsaoj=0          '微信金额
	ayptsaob=0          '微信笔数
	ayptsaol=0          '微信利润
	shoufei=0           '手续费
	
	wapalib=0
	wapalij=0
	waptenb=0
	waptenj=0
	qqsaob=0
	qqsaoj=0
	qqsaol=0
	
	if not(rsj.bof and rsj.eof) then
	do while not rsj.eof

			num=num+1   '成交笔数
			minje=ccur(minje)+ccur(rsj("aydingdanzj"))   '订单总价
			chengben=0
			chengben=ccur(rsj("aydingdancb"))*ccur(rsj("ayddquantity"))
			ddlirun=ccur(ddlirun)+ccur(rsj("aydingdanzj"))-ccur(chengben)
			fei=ccur(rsj("aydingdanzj"))-ccur(rsj("aydingdanin"))
			shoufei=ccur(shoufei)+ccur(fei)
			
			if rsj("ayddzffangshi")=0 then '0网银 1充值卡 2支付宝 3财付通 4扫码
			paybank=paybank+1
			paybankj=paybankj+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=1 then
			paycard=paycard+1
			paycardj=paycardj+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=2 then
			payalipay=payalipay+1
			payalipayj=payalipayj+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=3 then
			paytenpay=paytenpay+1
			paytenpayj=paytenpayj+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=4 or rsj("ayddzffangshi")=13 then
			ayptsaob=ayptsaob+1
			ayptsaoj=ayptsaoj+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=5 then
			qqsaob=qqsaob+1
			qqsaoj=qqsaoj+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=10 then  '10WAP支付宝
			wapalib=wapalib+1
			wapalij=wapalij+ccur(rsj("aydingdanzj"))
			elseif rsj("ayddzffangshi")=12 then  '12WAP财付通
			waptenb=waptenb+1
			waptenj=waptenj+ccur(rsj("aydingdanzj"))
			end if

	rsj.movenext  
	loop
	end if
	rsj.close
	
sqlj="select aycaiwuuser,aycaiwudate,aycaiwuleibie,aycaiwuzt,aycaiwujine from aycaiwu where aycaiwuuser="&clng(tongjiuser)&" and datediff(day,aycaiwudate,'"&wrinoda&"')=0 and (aycaiwuleibie=3 or aycaiwuleibie=4 or aycaiwuleibie=8 or aycaiwuleibie=10 or aycaiwuleibie=17 or aycaiwuleibie=18) and aycaiwuzt=1" 

	rsj.open sqlj,conn,1,3
	cnum=0 '总笔数
	cjin=0  '财务入款
	djin=0  '代理商品入款
	fandian=0
	fandianj=0
	if not(rsj.bof and rsj.eof) then
	do while not rsj.eof
	
			cnum=cnum+1    
			cjin=ccur(cjin)+ccur(rsj("aycaiwujine"))   '发生金额
			if rsj("aycaiwuleibie")=18 then '代理入款
			djin=djin+ccur(rsj("aycaiwujine"))
			elseif rsj("aycaiwuleibie")=8 then '引荐返点
			fandian=fandian+1    
			fandianj=fandianj+ccur(rsj("aycaiwujine"))
			end if

	rsj.movenext  
	loop
	end if
	rsj.close
	

rst.addnew
rst("aypttjuid")=clng(tongjiuser)
rst("aypttjjl")=wrino 				'周期记录  年2013   月201301  日20130101
rst("ayptdate")=wrinoda '统计日期
rst("ayptcjbs")=ccur(num)+ccur(cnum) 			'成交笔数  默认0
rst("ayptcjje")=ccur(minje)+ccur(cjin)  				 '成交金额
rst("ayptcjlr")=ddlirun  '成交利润  默认0
rst("ayptbank")=paybank   '网银笔数 默认0
rst("ayptbankj")=paybankj  '网银金额 默认0
rst("ayptcard")=paycard  '充值卡笔数 默认0
rst("ayptcardj")=paycardj  '充值卡金额 默认0
rst("ayptalipay")=payalipay  '支付宝笔数 默认0
rst("ayptalipayj")=payalipayj  '支付宝金额 默认0
rst("aypttenpay")=paytenpay  '财付通笔数 默认0
rst("aypttenpayj")=paytenpayj  '财付通金额 默认0
rst("ayfandian")=fandian 
rst("ayfandianj")=fandianj
rst("qitain")=ccur(cjin)-ccur(djin)   '其他入款
rst("dailiin")=djin   '代理商品入款
rst("ayptsaoj")=ayptsaoj
rst("ayptsaob")=ayptsaob

rst("wapalib")=wapalib
rst("wapalij")=wapalij

rst("waptenb")=waptenb
rst("waptenj")=waptenj

rst("qqsaob")=qqsaob
rst("qqsaoj")=qqsaoj
rst("shoufei")=shoufei

rst.update

end if
rst.close


n=n+1
next


for yuenum=1 to 6
ymonthno=Year(DateAdd("m",-yuenum,today))&Right("0" & Month(DateAdd("m",-yuenum,today)),2)

				'上月统计
				sqlt="select top 1 * from aypttj where aypttjuid="&clng(tongjiuser)&" and aypttjjl='"&ymonthno&"' and aypttjzq=2"  
				rst.open sqlt,conn,1,3
				
				'response.Write sqlt
				'response.end
				if rst.bof and rst.eof then
				
					sqlj="select * from aypttj where aypttjzq=3 and aypttjuid="&clng(tongjiuser)&" and datediff(month,ayptdate,'"&DateAdd("m",-yuenum,now())&"')=0" 
					'response.Write sqlj
				    'response.end
					rsj.open sqlj,conn,1,3
					minje=0
					minjelast=0
					num=0
					paybank=0
					payalipay=0
					paytenpay=0
					paycard=0
					paybankj=0
					payalipayj=0
					paytenpayj=0
					paycardj=0
					fandian=0
					fandianj=0
					cjin=0
					djin=0
					ddlirun=0 '订单利润
					ayptsaoj=0          '微信金额
					ayptsaob=0          '微信笔数
					ayptsaol=0          '微信利润
					shoufei=0          '手续费
					
					wapalib=0
					wapalij=0
					waptenb=0
					waptenj=0
					qqsaob=0
					qqsaoj=0
					qqsaol=0
					if not(rsj.bof and rsj.eof) then
					do while not rsj.eof
				
						'response.Write rsj("aycaiwudate")&"<br>"
						num=num+ccur(rsj("ayptcjbs"))   
						minje=ccur(minje)+ccur(rsj("ayptcjje"))
						'minjelast=ccur(minjelast)+ccur(rsj("ayptcjjs"))
						paybank=paybank+ccur(rsj("ayptbank"))
						paybankj=paybankj+ccur(rsj("ayptbankj"))
						paycard=paycard+ccur(rsj("ayptcard"))
						paycardj=paycardj+ccur(rsj("ayptcardj"))
						payalipay=payalipay+ccur(rsj("ayptalipay"))
						payalipayj=payalipayj+ccur(rsj("ayptalipayj"))
						paytenpay=paytenpay+ccur(rsj("aypttenpay"))
						paytenpayj=paytenpayj+ccur(rsj("aypttenpayj"))
						fandian=fandian+ccur(rsj("ayfandian"))
						fandianj=fandianj+ccur(rsj("ayfandianj"))
						cjin=cjin+ccur(rsj("qitain"))
						djin=djin+ccur(rsj("dailiin"))
						ddlirun=ddlirun+ccur(rsj("ayptcjlr"))
						ayptsaoj=ayptsaoj+ccur(rsj("ayptsaoj"))
						ayptsaob=ayptsaob+ccur(rsj("ayptsaob"))
						
						wapalib=ccur(wapalib)+ccur(rsj("wapalib"))
						wapalij=ccur(wapalij)+ccur(rsj("wapalij"))
						waptenb=ccur(waptenb)+ccur(rsj("waptenb"))
						waptenj=ccur(waptenj)+ccur(rsj("waptenj"))
						
						qqsaob=ccur(qqsaob)+ccur(rsj("qqsaob"))
						qqsaoj=ccur(qqsaoj)+ccur(rsj("qqsaoj"))
						shoufei=ccur(shoufei)+ccur(rsj("shoufei"))
						
						'response.Write rsj("aypttjjl")&" "&rsj("ayptcjlr")&"<br>"
					rsj.movenext  
					loop
					end if
					rsj.close
					'response.end

				
				rst.addnew
				rst("aypttjuid")=clng(tongjiuser) 
				rst("aypttjzq")=2       					'  统计周期  1年 2月 3日 默认3
				rst("aypttjjl")=ymonthno 				'周期记录  年2013   月201301  日20130101
				rst("ayptdate")=DateAdd("m",-yuenum,now()) '统计日期
				rst("ayptcjbs")=clng(num) 			'成交笔数  默认0
				rst("ayptcjje")=minje  				 '成交金额
				'rst("ayptcjjs")=minjelast   		'结算金额
				rst("ayptcjlr")=ddlirun  '成交利润  默认0
				rst("ayptbank")=paybank   '网银笔数 默认0
				rst("ayptbankj")=paybankj  '网银金额 默认0
				rst("ayptcard")=paycard  '充值卡笔数 默认0
				rst("ayptcardj")=paycardj  '充值卡金额 默认0
				rst("ayptalipay")=payalipay  '支付宝笔数 默认0
				rst("ayptalipayj")=payalipayj  '支付宝金额 默认0
				rst("aypttenpay")=paytenpay  '财付通笔数 默认0
				rst("aypttenpayj")=paytenpayj  '财付通金额 默认0
				rst("ayfandian")=fandian  
				rst("ayfandianj")=fandianj 
				rst("qitain")=cjin   '其他入款
				rst("dailiin")=djin   '代理商品入款
				rst("ayptsaoj")=ayptsaoj 
				rst("ayptsaob")=ayptsaob 
				
				rst("wapalib")=wapalib 
				rst("wapalij")=wapalij 
				rst("waptenb")=waptenb 
				rst("waptenj")=waptenj 
				
				rst("qqsaob")=qqsaob 
				rst("qqsaoj")=qqsaoj 
				rst("shoufei")=shoufei 
				
				rst.update
				
				end if
				rst.close
				

next


'上一年统计
sqlt="select top 1 * from aypttj where aypttjuid="&clng(tongjiuser)&" and aypttjjl='"&yyearno&"' and aypttjzq=1"  
rst.open sqlt,conn,1,3
if rst.bof and rst.eof then

	sqlj="select * from aypttj where aypttjzq=2 and aypttjuid="&clng(tongjiuser)&" and datediff(yyyy,ayptdate,'"&now()&"')=1" 
	rsj.open sqlj,conn,1,3
	minje=0
	minjelast=0
	num=0
	paybank=0
	payalipay=0
	paytenpay=0
	paycard=0
	paybankj=0
	payalipayj=0
	paytenpayj=0
	paycardj=0
	fandian=0
	fandianj=0
	cjin=0
	djin=0
	ddlirun=0 '订单利润
	ayptsaoj=0          '微信金额
	ayptsaob=0          '微信笔数
	ayptsaol=0          '微信利润
	shoufei=0   '手续费
	
	wapalib=0
	wapalij=0
	waptenb=0
	waptenj=0
	qqsaob=0
	qqsaoj=0
	qqsaol=0
	
	if not(rsj.bof and rsj.eof) then
	do while not rsj.eof

		'response.Write rsj("aycaiwudate")&"<br>"
		num=num+ccur(rsj("ayptcjbs"))   
		minje=ccur(minje)+ccur(rsj("ayptcjje"))
		'minjelast=ccur(minjelast)+ccur(rsj("ayptcjjs"))
		paybank=paybank+ccur(rsj("ayptbank"))
		paybankj=paybankj+ccur(rsj("ayptbankj"))
		paycard=paycard+ccur(rsj("ayptcard"))
		paycardj=paycardj+ccur(rsj("ayptcardj"))
		payalipay=payalipay+ccur(rsj("ayptalipay"))
		payalipayj=payalipayj+ccur(rsj("ayptalipayj"))
		paytenpay=paytenpay+ccur(rsj("aypttenpay"))
		paytenpayj=paytenpayj+ccur(rsj("aypttenpayj"))
		fandian=fandian+ccur(rsj("ayfandian"))
		fandianj=fandianj+ccur(rsj("ayfandianj"))
		cjin=cjin+ccur(rsj("qitain"))
		djin=djin+ccur(rsj("dailiin"))
		ddlirun=ddlirun+ccur(rsj("ayptcjlr"))
		ayptsaoj=ayptsaoj+ccur(rsj("ayptsaoj"))
		ayptsaob=ayptsaob+ccur(rsj("ayptsaob"))
				
		wapalib=ccur(wapalib)+ccur(rsj("wapalib"))
		wapalij=ccur(wapalij)+ccur(rsj("wapalij"))
		waptenb=ccur(waptenb)+ccur(rsj("waptenb"))
		waptenj=ccur(waptenj)+ccur(rsj("waptenj"))
		qqsaob=ccur(qqsaob)+ccur(rsj("qqsaob"))
		qqsaoj=ccur(qqsaoj)+ccur(rsj("qqsaoj"))
		shoufei=ccur(shoufei)+ccur(rsj("shoufei"))
		
	rsj.movenext  
	loop
	end if
	rsj.close
	

rst.addnew
rst("aypttjuid")=clng(tongjiuser) 
rst("aypttjzq")=1       					'  统计周期  1年 2月 3日 默认3
rst("aypttjjl")=yyearno 				'周期记录  年2013   月201301  日20130101
rst("ayptdate")=DateAdd("yyyy",-1,now()) '统计日期
rst("ayptcjbs")=clng(num) 			'成交笔数  默认0
rst("ayptcjje")=minje  				 '成交金额
'rst("ayptcjjs")=minjelast   		'结算金额
rst("ayptcjlr")=ddlirun  '成交利润  默认0
rst("ayptbank")=paybank   '网银笔数 默认0
rst("ayptbankj")=paybankj  '网银金额 默认0
rst("ayptcard")=paycard  '充值卡笔数 默认0
rst("ayptcardj")=paycardj  '充值卡金额 默认0
rst("ayptalipay")=payalipay  '支付宝笔数 默认0
rst("ayptalipayj")=payalipayj  '支付宝金额 默认0
rst("aypttenpay")=paytenpay  '财付通笔数 默认0
rst("aypttenpayj")=paytenpayj  '财付通金额 默认0
rst("ayfandian")=fandian
rst("ayfandianj")=fandianj
rst("qitain")=cjin   '其他入款
rst("dailiin")=djin   '代理商品入款
rst("ayptsaoj")=ayptsaoj
rst("ayptsaob")=ayptsaob

rst("wapalib")=wapalib 
rst("wapalij")=wapalij 
rst("waptenb")=waptenb 
rst("waptenj")=waptenj 
rst("qqsaob")=qqsaob 
rst("qqsaoj")=qqsaoj
rst("shoufei")=shoufei
rst.update

end if
rst.close

response.Write "ok"

%>