<!--#include virtual="/inc/conn.asp"-->
<%
Response.CharSet="GB2312"
Response.ContentType="text/html"
	
'获取库存卡
if SafeRequestform("act")="kucunka" then
gid=SafeRequestform("gid")
uid=SafeRequestform("uid")

str= "[{"
str=str&"""ERR"":""0"","	

rs.open "select aynameid,kamiku from ayname where aynameid="&uid&"",conn,1,1
if not(rs.eof) then
kamiku=trim(rs("kamiku"))
end if
rs.close


rs.open "select * from aygood where aygoodid="&gid&"",conn,1,1
if not(rs.eof) then
aygooddlid=rs("aygooddlid")
aysjgid=rs("aysjgid")
aychenben=rs("aychenben")
aysjjiage=rs("aysjjiage")               '代理价格
aygoodsuoyouid=rs("aygoodsuoyouid")     '商品所属会员

bugpass="0"
if trim(rs("bugpass"))<>"" and isnull(trim(rs("bugpass")))=false then bugpass="1"

str=str&"""B"":"""&rs("buylx")&""","				'B 买家下单指定预留方式  
str=str&"""C"":"""&rs("aychenben")&""","			'C 成本价格
str=str&"""D"":"""","								'D 点卡信息  
str=str&"""J"":"""&rs("ayjiage")&""","				'J 价格
str=str&"""X"":"""&rs("ayxiangou")&""","			'X 限购
str=str&"""S"":"""&trim(rs("ayshmiaoshu"))&""","	'S 商品说明
str=str&"""Q"":"""&trim(rs("ayshqq"))&""","			'Q 商品QQ
str=str&"""U"":"""&trim(rs("ayshurl"))&""","		'U 商品URL链接
str=str&"""N"":"""&trim(ReplaceTrim(rs("aygoodname")))&""","				'N 商品名称  
str=str&"""SK"":"""&rs("ayshoukatz")&""","			'SK 售卡通知  
str=str&"""PF"":"""&rs("aypifayes")&""","			'PF 是否批发
str=str&"""P1"":"""&rs("aypifa1")&""","				'P1 数量
str=str&"""P2"":"""&rs("aypifa2")&""","				'P2 数量
str=str&"""P3"":"""&rs("aypifa3")&""","				'P3 数量
str=str&"""P4"":"""&rs("aypifa4")&""","				'P4 数量
str=str&"""P5"":"""&rs("aypifa5")&""","				'P5 数量
str=str&"""J1"":"""&rs("aypifaj1")&""","			'J1 价格
str=str&"""J2"":"""&rs("aypifaj2")&""","			'J2 价格
str=str&"""J3"":"""&rs("aypifaj3")&""","			'J3 价格
str=str&"""J4"":"""&rs("aypifaj4")&""","			'J4 价格
str=str&"""J5"":"""&rs("aypifaj5")&""","			'J5 价格
str=str&"""ZB"":"""&rs("ayisbankpay")&""","			'ZB 网银支付
str=str&"""ZA"":"""&rs("ayisalipay")&""","			'ZA 支付宝支付
str=str&"""ZC"":"""&rs("ayistenpay")&""","			'ZC 财付通支付
str=str&"""ZW"":"""&rs("ayissaopay")&""","			'ZW 微信支付
str=str&"""ZQ"":"""&rs("ayisqqpay")&""","			'ZQ QQ扫码支付
str=str&"""ZJ"":"""&rs("ayisjdpay")&""","			'ZJ 京东扫码支付
str=str&"""XS"":"""&rs("aygoodiskucun")&""","		'XS 显示库存方式
str=str&"""TI"":"""&rs("ayggodispass")&""","		'TI 提卡密码
str=str&"""BP"":"""&bugpass&""","					'BP 购卡密码
str=str&"""YH"":"""&rs("ayyouhuiyes")&""","			'YH 是否使用优惠券

'str=str&"""GXX"":"""&trim(rs("goodxx"))&""","			'GXX 是否有详细说明

if trim(rs("goodxx"))<>"" and isnull(trim(rs("goodxx")))=false then
	if trim(rs("goodxx"))="<br />" then
	str=str&"""GXX"":""no"","						'GXX  是否有详细说明
	else
	str=str&"""GXX"":""yes"","
	end if
else
str=str&"""GXX"":""no"","
end if

end if
rs.close

	'卡库存
	sqlka="select count(*) as num from "&kamiku&" where aykagoodid="&clng(gid)&" 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 "[{""ERR"":""ERR01""}]"  '商品ID错误，请联系商家ERR01
			response.end 
			end if
			if clng(aysjgid)=0 then 
			response.Write "[{""ERR"":""ERR02""}]"  '商品ID错误，请联系商家ERR02
			response.end
			end if
			if ccur(aysjjiage)=0 then  
			response.Write "[{""ERR"":""ERR03""}]"  '商品代理价格有误，请联系商家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 "[{""ERR"":""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 "[{""ERR"":""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 "[{""ERR"":""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
'str=str&"""KU"":"&rska.RecordCount&""		
'rska.close

set rsnum=conn.execute(sqlka)
kazongshu=rsnum("num")
str=str&"""KU"":"&kazongshu&""	

str=str&"}]"

response.Write str

end if
%>

