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

<%
'用于 商户后台 商品列表 显示库存数

Response.CharSet="GB2312"
Response.ContentType="text/html"


chastr=split(SafeRequest("id"),",") 

fanhuistr=""

For sum=0 To Ubound(chastr)
sjgoodid=0 '顶级代理ID

'response.Write chastr(sum)&"<br>"

	sql="select aygoodsuoyouid,aygooddlid,aygoodid,aysjgid from aygood where aygoodid="&clng(chastr(sum))&" and aygoodsuoyouid="&request.Cookies("aynameid")&"" 
	rs.open sql,conn,1,1
	if rs.bof and rs.eof then 
	call PopErr("未找到商品err1")
	response.End()
	end if
	if not(rs.bof and rs.eof) then 
	aygooddlid=rs("aygooddlid")  '上级代理ID 默认0无代理
	aysjgid=rs("aysjgid") 		 '上级商品ID
	aygoodsuoyouid=request.Cookies("aynameid")
	end if
	rs.close
	
	

derr="no"
if clng(aygooddlid)<>0 then '是代理商品  
derr="no"

		For dsum=1 To 10 '10层代理关系
		
			'aysjgid 上级商品ID 
			'aygoodsuoyouid 代理商 商户ID  
			'aygooddlid 上级代理 商户ID 
	
			'验证代理关系                                                                               '代理商 商户ID                        上级代理 商户ID 
			rs.open "select aydluserid,aydlsjuserid,aydlistongguo from aydailishang where aydluserid='"&aygoodsuoyouid&"' and aydlsjuserid='"&clng(aygooddlid)&"' and aydlistongguo=1",conn,1,1
			if rs.bof and rs.eof then 
			derr="yes"
			end if
			rs.close
			 
            '获取代理商品ID                                                                                 '上级商品ID                          上级代理 商户ID 
			rs.open "select aygsumid,aygoodsuoyouid,aysjgid,aygooddlid,aygoodid from aygood where aygoodid="&clng(aysjgid)&" and aygoodsuoyouid="&clng(aygooddlid)&"",conn,1,1
			if not(rs.bof and rs.eof) then 
				if clng(rs("aygooddlid"))=0 then '已是顶级代理  
				sjgoodid=aygooddlid
				aysjgid=aysjgid
				rs.close
				exit for
				else
				aysjgid=rs("aysjgid") 			    '上级商品ID 
				aygoodsuoyouid=rs("aygoodsuoyouid") '代理商 商户ID  
				aygooddlid=rs("aygooddlid")		    '上级代理 商户ID 
				end if
			else
			derr="yes"								'未找到代理商品
			end if
			rs.close

			
			if derr="yes" then 
			exit for
			end if
			
		next 
		
end if

'response.Write derr
'response.Write aysjgid
'response.end





	if derr="no" then
			


			
		if clng(sjgoodid)<>0 then
			'总代 卡密数据库
			set rsdg=server.CreateObject("adodb.recordset")
			rsdg.open "select aynameid,kamiku from ayname where aynameid="&clng(sjgoodid)&"",conn,1,1
			kamiku=trim(rsdg("kamiku"))
			rsdg.close
			
			'sql="select aykagoodid,aykayesno from "&kamiku&" where aykagoodid="&clng(aysjgid)&" and aykadstr like '%"&tocunid(request.Cookies("aynameid"))&"%' and aykayesno=1" 
			
			set rs2=conn.execute("select count(*) as num from "&kamiku&" where aykagoodid="&clng(aysjgid)&" and aykadstr like '%"&tocunid(request.Cookies("aynameid"))&"%' and aykayesno=1")
			fanhuistr=fanhuistr&chastr(sum)&"|"&"1|"&rs2("num")&"|"
		
		else
		
			'sql="select aykagoodid,aykayesno from "&request.Cookies("kamiku")&" where aykagoodid="&clng(chastr(sum))&" and aykasuoyou="&clng(request.Cookies("aynameid"))&" and aykayesno=1" 
			
			set rs2=conn.execute("select count(*) as num from "&request.Cookies("kamiku")&" where aykagoodid="&clng(chastr(sum))&" and aykasuoyou="&clng(request.Cookies("aynameid"))&" and aykayesno=1")
			fanhuistr=fanhuistr&chastr(sum)&"|"&"0|"&rs2("num")&"|"
		
		end if
		

		'rs.open sql,conn,1,1
		'if not(rs.bof and rs.eof) then
		'	if clng(sjgoodid)<>0 then
		'	fanhuistr=fanhuistr&chastr(sum)&"|"&"1|"&rs.RecordCount&"|"
		'	else
		'	fanhuistr=fanhuistr&chastr(sum)&"|"&"0|"&rs.RecordCount&"|"
		'	end if
		'else
		'	fanhuistr=fanhuistr&chastr(sum)&"|"&"0|0|"
		'end if
		'rs.close
		
		'1|5|0
		'代理|已出数量|库存数量
		'0|5|0
		'本地|已出数量|库存数量
		'0|0|0
		'已出|0|库存数量
		'******************************************


		
		
		if clng(sjgoodid)<>0 then
		

		set rs2=conn.execute("select count(*) as num from "&kamiku&" where aykagoodid="&clng(aysjgid)&" and aykayesno=0")
		Countsum=rs2("num")
		
		else

		set rs2=conn.execute("select count(*) as num from "&request.Cookies("kamiku")&" where aykagoodid="&clng(chastr(sum))&" and aykasuoyou="&clng(request.Cookies("aynameid"))&" and aykayesno=0")
		Countsum=rs2("num")
		
		end if
		
		fanhuistr=fanhuistr&Countsum&"^"
		
		'rs.open sql,conn,1,1
		'if not(rs.bof and rs.eof) then
        'fanhuistr=fanhuistr&rs.RecordCount&"^"
		'else
		'fanhuistr=fanhuistr&"0"&"^"
		'end if
		'rs.close
	
	
	else
	fanhuistr=fanhuistr&chastr(sum)&"|"&"1|0|0|^"
	end if
		
		
	
	
	
	
	
next

	
if trim(fanhuistr)<>"" then fanhuistr=mid(fanhuistr,1,len(fanhuistr)-1)

response.Write fanhuistr
		


conn.close
set conn=nothing
%>