<!--#include virtual="/inc/conn.asp"-->
<%
Response.CharSet="GB2312"
Response.ContentType="text/html"
 
 
if SafeRequest("act")="chadh" then 
	id=SafeRequest("id")
	sql="select * from ayduihuan where aydhhao='"&trim(id)&"' and aydhisok=0" 
	rs.open sql,conn,1,1
	if not(rs.bof and rs.eof) then
	
	if cint(rs("aydhlei"))=1 then response.Write "0|"&rs("aydhlei")&"|"&rs("aydhmj")
	if cint(rs("aydhlei"))=3 then response.Write "0|"&rs("aydhlei")&"|"&rs("aydhsms")
	if cint(rs("aydhlei"))=2 or cint(rs("aydhlei"))=4 then response.Write "0|"&rs("aydhlei")&"|0"
		
	else
	response.Write "1|0|0"
	end if
	rs.close
	response.End()
end if



fenleiid=SafeRequest("fenleiid")
goodid=SafeRequest("goodid")
uid=SafeRequest("uid")
gid=SafeRequest("gid")
act=SafeRequest("act")
isduliurl=SafeRequest("isduliurl")
isduliurlg=SafeRequest("isduliurlg")





'查询分类数据
if act="chafenlei" then 

shangpinstr=""

	rs.open "select aykanamesuoyou,ayfldlmd5url,aykafenleiid,aykafenleishuoming,aykafenleiqq,aykafenleiurl from aykafenlei where aykafenleiid="&trim(fenleiid)&" and aykanamesuoyou="&clng(uid)&"",conn,1,1

	fid=rs("aykafenleiid")
	aykafenleishuoming=trim(rs("aykafenleishuoming"))
	aykafenleiqq=trim(rs("aykafenleiqq"))
	aykafenleiurl=trim(rs("aykafenleiurl"))

	sql="select * from aygood where aygoodsuoyouid="&clng(uid)&" and aygoodfl="&rs("aykafenleiid")&" and aygoodzhuangtai=0 and aygoodisydl=0 order by aygoodsx asc" 
	rs.close



rs.open sql,conn,1,1
if rs.bof and rs.eof then
shangpinstr="<select name=shangid id=shangid onChange=good(this.value);>"
shangpinstr=shangpinstr&"<option value=0 >未找到商品</option>"
shangpinstr=shangpinstr&"</select>"
else

	if trim(isduliurlg)="y" then
	shangpinstr=trim(rs("aygoodname"))&"<input type=hidden name=shangid id=shangid value="&gid&"/>"
	else
		shangpinstr="<select name=shangid id=shangid onChange=good(this.value);>"
		shangpinstr=shangpinstr&"<option value=0>请选择商品</option>"
			do while not rs.eof
				shangpinstr=shangpinstr&"<option value="&rs("aygoodid")&""   '数字ID
				if trim(gid)<>"" then 
				if clng(gid)=clng(rs("aygoodid")) then shangpinstr=shangpinstr&" selected"    '数字ID
				end if
				shangpinstr=shangpinstr&">"&trim(rs("aygoodname"))&"</option>"
			rs.movenext 
			loop
			shangpinstr=shangpinstr&"</select>"
	end if
rs.close
end if

shangpinstr=shangpinstr&"|"&fid
shangpinstr=shangpinstr&"|"&""
shangpinstr=shangpinstr&"|"&aykafenleishuoming
shangpinstr=shangpinstr&"|"&aykafenleiqq
shangpinstr=shangpinstr&"|"&aykafenleiurl
response.Write shangpinstr
response.end
end if




'查询商品数据
if act="chagood" then 

goodstr=""

rs.open "select aynameid,kamiku from ayname where aynameid="&clng(uid)&"",conn,1,1
kamiku=trim(rs("kamiku"))'卡密数据库
rs.close


sql="select * from aygood where aygoodid="&clng(goodid)&" and aygoodsuoyouid="&clng(uid)&" and aygoodzhuangtai=0 order by aygoodsx asc" 
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
'0零售价格|1成本价格|2隐藏价格|3是否批发|4批发数量1|5批发数量2|6批发数量3|7批发数量4|8批发数量5|9批发价1|10批发价2|11批发价3|12批发价4|13批发价5|14限购数量|15是否使用优惠券|16售卡通知|17邮件通知买家|18提卡密码|
'19显示库存|20网银支付|21支付宝支付|22财付通支付|23充值卡支付|24商户描述|25商户qq|26上级代理ID|27上级代理价格|28上级商品ID|29库存卡|30商品ID|31扫码支付|32点卡信息|33商品URL|34qq扫码支付|35扩展信息|36购买密码
'|37买家下单指定预留方式
aygoodid=rs("aygoodid")      			'商品ID
aygooddlid=rs("aygooddlid")  			'上级代理ID 默认0无代理
aysjgid=rs("aysjgid")        			'上级商品ID
aygoodsuoyouid=rs("aygoodsuoyouid")     '商品所属会员
aygsumid=rs("aygsumid")                 '商品唯一标示
ayissaopay=rs("ayissaopay")             '扫码支付是否开启
aysjjiage=rs("aysjjiage")               '代理价格
aychenben=rs("aychenben")               '成本价格
ayshurl=trim(rs("ayshurl"))
ayisqqpay=rs("ayisqqpay")				'QQ扫码
ayisjdpay=rs("ayisjdpay")				'京东
buylx=rs("buylx")
bugpass="0"
if trim(rs("bugpass"))<>"" and isnull(trim(rs("bugpass")))=false then bugpass="1" '购买密码

kuozhanstr="-"
'kuozhanstr=kuozhanstr&rs("ayyujing")&"^"      '剩余预警数量
'kuozhanstr=kuozhanstr&rs("ayyujingmss")&"^"   '站内信通知
'kuozhanstr=kuozhanstr&rs("ayyujingmail")&"^"  '邮箱通知
'kuozhanstr=kuozhanstr&rs("ayyujingtel")&"^"   '手机通知
'kuozhanstr=kuozhanstr&rs("ayjujingwx")&"^"    '微信通知 
'kuozhanstr=kuozhanstr&rs("ayshoukatz")&"^"    '是否售卡通知
'kuozhanstr=kuozhanstr&rs("shoukamail")&"^"    '售卡邮件通知
'kuozhanstr=kuozhanstr&rs("shoukatel")&"^"     '售卡手机通知
'kuozhanstr=kuozhanstr&rs("shouikawx")&"^"     '售卡微信通知
'kuozhanstr=kuozhanstr&trim(rs("aygoodname"))  '商品名称


goodstr=goodstr&rs("ayjiage")&"|"     		 '0零售价格
goodstr=goodstr&aychenben&"|"   			 '1成本价格
goodstr=goodstr&rs("ayycj")&"|"  '    		 '2隐藏价格
goodstr=goodstr&rs("aypifayes")&"|"   		 '3是否批发
goodstr=goodstr&rs("aypifa1")&"|"     		 '4批发数量1
goodstr=goodstr&rs("aypifa2")&"|"     		 '5批发数量2
goodstr=goodstr&rs("aypifa3")&"|"     		 '6批发数量3  
goodstr=goodstr&rs("aypifa4")&"|"     		 '7批发数量4
goodstr=goodstr&rs("aypifa5")&"|"     		 '8批发数量5
goodstr=goodstr&rs("aypifaj1")&"|"    		 '9批发价1
goodstr=goodstr&rs("aypifaj2")&"|"    		 '10批发价2
goodstr=goodstr&rs("aypifaj3")&"|"    		 '11批发价3
goodstr=goodstr&rs("aypifaj4")&"|"    		 '12批发价4
goodstr=goodstr&rs("aypifaj5")&"|"    		 '13批发价5
goodstr=goodstr&rs("ayxiangou")&"|"   		 '14限购数量
goodstr=goodstr&rs("ayyouhuiyes")&"|"    	 '15是否使用优惠券
goodstr=goodstr&rs("ayshoukatz")&"|"    	 '16售卡通知
goodstr=goodstr&"1|"      					 '17邮件通知买家
goodstr=goodstr&rs("ayggodispass")&"|"       '18提卡密码
goodstr=goodstr&rs("aygoodiskucun")&"|"      '19显示库存
goodstr=goodstr&rs("ayisbankpay")&"|"        '20网银支付
goodstr=goodstr&rs("ayisalipay")&"|"         '21支付宝支付
goodstr=goodstr&rs("ayistenpay")&"|"         '22财付通支付
goodstr=goodstr&"|"    						 '23充值卡支付
goodstr=goodstr&trim(rs("ayshmiaoshu"))&"|"  '24商户描述
goodstr=goodstr&trim(rs("ayshqq"))&"|"       '25商户qq
goodstr=goodstr&aygooddlid&"|"        		 '26上级代理ID
goodstr=goodstr&aysjjiage&"|"  		         '27上级代理价格
goodstr=goodstr&aysjgid&"|"    		         '28上级商品ID
end if
rs.close

	'卡库存
	sqlka="select count(*) as num from "&kamiku&" where aykagoodid="&clng(aygoodid)&" and aykayesno=0" 

	if clng(aygooddlid)<>0 then '是代理商品  
	dailistr=""
	set rsdaili=server.CreateObject("adodb.recordset")     
	set rsgd=server.CreateObject("adodb.recordset")
	  
		For sum=1 To 10 '10层代理关系
		
			'aysjgid 上级商品ID 
			'aysjjiage 商品代理价格
			'aygoodsuoyouid 代理商 商户ID  
			'aygooddlid 上级代理 商户ID 
			'aygsumid 商品唯一标示
			
			if isnull(trim(aysjgid))=true or trim(aysjgid)="" then  'aysjgid上级商品ID
			response.Write "ERR01"     '商品ID错误，请联系商家ERR01
			response.end 
			end if
			if clng(aysjgid)=0 then 
			response.Write "ERR02"     '商品ID错误，请联系商家ERR02
			response.end
			end if
			if ccur(aysjjiage)=0 then  '商品代理价格有误，请联系商家ERR03
			response.Write "ERR03"    
			response.end
			end if
		
			
			'验证代理关系                                                                      '代理商 商户ID                            上级代理 商户ID 
			rsdaili.open "select aydluserid,aydlsjuserid,aydlistongguo from aydailishang where aydluserid='"&clng(aygoodsuoyouid)&"' and aydlsjuserid='"&clng(aygooddlid)&"' and aydlistongguo=1",conn,1,1
			if rsdaili.bof and rsdaili.eof then 
			response.Write "ERR04"    '未找到代理关系
			response.end
			end if
			rsdaili.close
			
			'获取代理商品ID                                                                                                     '上级商品ID                           上级代理 商户ID 
			rsgd.open "select aygsumid,aygoodsuoyouid,aychenben,aysjgid,aysjjiage,aygooddlid,aygoodid from aygood where aygoodid="&clng(aysjgid)&" and aygoodsuoyouid="&clng(aygooddlid)&"",conn,1,1
			if not(rsgd.bof and rsgd.eof) then 
					   '代理商品成本    '上级商品成本价
				if ccur(aychenben)<ccur(rsgd("aychenben")) then
				response.Write "ERR06"    '代理成本价格低于上级代理成本价格
				response.end
				end if
				
				if clng(rsgd("aygooddlid"))=0 then
				exit for
				rsgd.close
				else
				aysjgid=rsgd("aysjgid") 			  '上级商品ID 
				aysjjiage=rsgd("aysjjiage") 		  '商品代理价格
				aygoodsuoyouid=rsgd("aygoodsuoyouid") '代理商 商户ID  
				aygooddlid=rsgd("aygooddlid")		  '上级代理 商户ID 
				aygsumid=rsgd("aygsumid") 			  '商品唯一标示
				end if
				
			else
			response.Write "ERR05"    '未找到代理商品
			response.end
			end if
			rsgd.close
			
		next 
		
		'上级代理卡密数据库
		rs.open "select aynameid,kamiku from ayname where aynameid="&clng(aygooddlid)&"",conn,1,1
		kamiku=trim(rs("kamiku"))'卡密数据库
		rs.close

		sqlka="select count(*) as num from "&kamiku&" where aykagoodid="&clng(aysjgid)&" and aykayesno=0" 
		rsgd.close
		
	end if
	
'set rska=server.CreateObject("adodb.recordset")
'rska.open sqlka,conn,1,1
'kazongshu=rska.RecordCount
'rska.close

set rsnum=conn.execute(sqlka)
kazongshu=rsnum("num")

goodstr=goodstr&kazongshu&"|"      '29库存卡
goodstr=goodstr&aygoodid&"|"       '30商品ID
goodstr=goodstr&ayissaopay&"|"     '31扫码支付
goodstr=goodstr&"|"   '32点卡信息
goodstr=goodstr&ayshurl&"|"        '33商品URL
goodstr=goodstr&ayisqqpay&"|"      '34QQ扫码
goodstr=goodstr&kuozhanstr&"|"     '35扩展信息
goodstr=goodstr&bugpass&"|"        '36购买密码 0无 1有
goodstr=goodstr&buylx&"|"     	   '37买家下单指定预留方式
goodstr=goodstr&ayisjdpay     	   '38京东支付开关

response.Write goodstr
end if



'查询商品详细说明
if act="chagoodx" then 

	if goodid<>"" and uid<>"" then
	
		sql="select aygoodsuoyouid,aygoodid,goodxx,aygdlmd5url,aygoodmd5 from aygood where aygoodid="&clng(goodid)&" and aygoodsuoyouid="&clng(uid)&"" 
		rs.open sql,conn,1,1
		if not(rs.bof and rs.eof) then
		response.Write trim(rs("goodxx"))
		end if
		rs.close
		
	end if

end if


conn.close
set conn=nothing
%>