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

jid=SafeRequest("jid")

'平台账务统计
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")

	
rs.open "select aynameid,ddku,cwku,ayjibie,aysanrie,ayusersuo,isjihuo from ayname where ayjibie="&jid&" and isjihuo=0 and ayusersuo=0",conn,1,3
if not(rs.bof and rs.eof) then
do while not rs.eof

ischongxinsanri="no"  '是否重新计数 三日额
sanrie=0    		'三日额
sanriej=0 			'三日额

daynum=1			'天数

tongjiuser=rs("aynameid")
ddku=trim(rs("ddku"))
cwku=trim(rs("cwku"))


		wrinoda=DateAdd("d",-daynum,now()) '昨日缩写 '20160118
		wrino=Year(DateAdd("d",-daynum,today))&Right("0" & Month(DateAdd("d",-daynum,today)),2)&Right("0" & Day(DateAdd("d",-daynum,today)),2) '昨日缩写2016-1-18 21:26:56
			
		rst.open "select top 1 * from aypttj where aypttjjl='"&wrino&"' and aypttjuid="&clng(tongjiuser)&" and aypttjzq=3",conn,1,3
		
		if rst.bof and rst.eof then
		ischongxinsanri="yes"
		
				rsj.open "select aydingdanin,aydingdanuser,aydingdansj,aydingdanzt,aydingdanzj,aydingdancb,ayddquantity,ayddzffangshi from "&ddku&" where datediff(day,aydingdansj,'"&wrinoda&"')>=0 and datediff(day,aydingdansj,'"&wrinoda&"')<3 and aydingdanuser="&clng(tongjiuser)&" and aydingdanzt=1",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
								
								sanrie=ccur(sanrie)+ccur(rsj("aydingdanzj"))'三日额统计
									 
											if datediff("d",rsj("aydingdansj"),now())=1 then   '昨日  
														
														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"))
														end if
														if rsj("ayddzffangshi")=1 then
														paycard=paycard+1
														paycardj=paycardj+ccur(rsj("aydingdanzj"))
														end if
														if rsj("ayddzffangshi")=2 then
														payalipay=payalipay+1
														payalipayj=payalipayj+ccur(rsj("aydingdanzj"))
														end if
														if rsj("ayddzffangshi")=3 then
														paytenpay=paytenpay+1
														paytenpayj=paytenpayj+ccur(rsj("aydingdanzj"))
														end if
														if rsj("ayddzffangshi")=4 or rsj("ayddzffangshi")=13 then
														ayptsaob=ayptsaob+1
														ayptsaoj=ayptsaoj+ccur(rsj("aydingdanzj"))
														end if
														if rsj("ayddzffangshi")=5 then
														qqsaob=qqsaob+1
														qqsaoj=qqsaoj+ccur(rsj("aydingdanzj"))
														end if
														if rsj("ayddzffangshi")=10 then  '10WAP支付宝
														wapalib=wapalib+1
														wapalij=wapalij+ccur(rsj("aydingdanzj"))
														end if
														if rsj("ayddzffangshi")=12 then  '12WAP财付通
														waptenb=waptenb+1
														waptenj=waptenj+ccur(rsj("aydingdanzj"))
														end if
												
											end if
								
								rsj.movenext  
								loop
						end if
				rsj.close
			
			
				
				sqlj="select aycaiwuuser,aycaiwudate,aycaiwuleibie,aycaiwuzt,aycaiwujine from "&cwku&" where datediff(day,aycaiwudate,'"&wrinoda&"')>0 and datediff(day,aycaiwudate,'"&wrinoda&"')<4 and aycaiwuuser="&clng(tongjiuser)&" 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
						if rsj("aycaiwuleibie")=18 then sanriej=ccur(sanriej)+ccur(rsj("aycaiwujine"))
						
									if datediff("d",rsj("aycaiwudate"),now())=1 then   '昨日
											cnum=cnum+1    
											cjin=ccur(cjin)+ccur(rsj("aycaiwujine"))   '发生金额
											if rsj("aycaiwuleibie")=18 then '代理入款
											djin=ccur(djin)+ccur(rsj("aycaiwujine"))
											end if
											if rsj("aycaiwuleibie")=8 then '引荐返点
											fandian=fandian+1    
											fandianj=ccur(fandianj)+ccur(rsj("aycaiwujine"))
											end if
									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
			daynum=daynum+1
		
			
							
			'上月统计
			ymonthno=Year(DateAdd("m",-1,today))&Right("0" & Month(DateAdd("m",-1,today)),2)
			rst.open "select top 1 * from aypttj where aypttjzq=2 and aypttjjl='"&ymonthno&"' and aypttjuid="&clng(tongjiuser)&"" ,conn,1,3
			if rst.bof and rst.eof then
				rsj.open "select * from aypttj where datediff(month,ayptdate,'"&DateAdd("m",-1,now())&"')=0 and aypttjuid="&clng(tongjiuser)&" and aypttjzq=3",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
						num=num+ccur(rsj("ayptcjbs"))   
						minje=ccur(minje)+ccur(rsj("ayptcjje"))
						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")=2       					'  统计周期  1年 2月 3日 默认3
		rst("aypttjjl")=ymonthno 				'周期记录  年2013   月201301  日20130101
		rst("ayptdate")=DateAdd("m",-1,now()) '统计日期
		rst("ayptcjbs")=clng(num) 			'成交笔数  默认0
		rst("ayptcjje")=minje  				 '成交金额
		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

			
			
			
			
			
			
				
		'上一年统计
		rst.open "select top 1 * from aypttj where aypttjzq=1 and aypttjjl='"&yyearno&"' and aypttjuid="&clng(tongjiuser)&"",conn,1,3
		if rst.bof and rst.eof then
			rsj.open "select * from aypttj where datediff(yyyy,ayptdate,'"&now()&"')=1 and aypttjzq=2 and aypttjuid="&clng(tongjiuser)&"",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
			num=num+ccur(rsj("ayptcjbs"))   
			minje=ccur(minje)+ccur(rsj("ayptcjje"))
			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("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
		
if ischongxinsanri="yes" then
sanri=ccur(sanrie)+ccur(sanriej)
rs("aysanrie")=sanri
rs.update	
'else
'rs("aysanrie")=0
'rs.update	
end if

rs.movenext  
loop
end if
rs.close	



response.Write "ok"
%>

