<%
if shopxpptid<>"" then
	if not isnumeric(shopxpptid) then 
	response.write"非法访问!"
	
	response.end
	else
	'if not isinteger(shopxpptid) then
	'response.write"<script>alert(""非法访问!"");window.close();<-/script>"
	'end if
	end if
end if

'总库存
set rs_s=server.CreateObject("adodb.recordset")
rs_s.open "select * from com_books where id="&shopxpptid,conn,1,1
danjia=rs_s("shopxphyjia")
danjifeng=rs_s("jifeng")
'kucun=rs_s("kucun")
shopxpptname=rs_s("titlecn")
rs_s.close
set rs_s=nothing

set rs_s=server.CreateObject("adodb.recordset")
rs_s.open "select * from com_PCR where proid="&shopxpptid&" and  colorid="&p_color_id&"  and  sizeid="&p_size_id,conn,1,1
kucun=rs_s("kucun")
rs_s.close
set rs_s=nothing
if kucun<=0 then
'response.write "你选购的商品“"&shopxpptname&"”暂时缺货不能放到购物车里，请选购其它商品！"
'response.write "你选购的商品暂时缺货不能放到购物车里，请选购其它商品!"
response.write "{""result"":""err"",""data"":""你选购的商品暂时缺货不能放到购物车里，请选购其它商品!""}"
response.end
end if


Quatity=num
if Quatity<>"" then
Quatity= cint(Quatity)
else
Quatity=1
end if
if Quatity<=0 then
Quatity=1
end if

set rs=server.CreateObject("adodb.recordset")
rs.open "select shopxpptid,username,productcount,zonger,jifeng from shopxp_action where username='"&username&"' and shopxpptid="&shopxpptid&" and pro_color_id="&p_color_id&" and pro_size_id="&p_size_id&" and zhuangtai=9",conn,1,3
if rs.recordcount=1 then
	if kucun<(rs("productcount")+Quatity) then
	'response.write "你选购的商品只剩下“"&kucun&"”份！"
	response.write "{""result"":""err"",""data"":""你选购的商品只剩下 "&kucun&" 份,您的购物车已选购了"&rs("productcount")&"份！""}"
	response.end
	end if
	if rs("productcount")<>"" then
	productcount=(rs("productcount"))+Quatity
	else
	productcount=Quatity
	end if
	zonger=danjia*productcount
	jifeng=danjifeng*productcount 
	rs("zonger")=zonger
	rs("jifeng")=jifeng
	rs("productcount")=productcount
	rs.update
	rs.close
	set rs=nothing

else
		'//添加购物
		rs.close
		set rs=server.CreateObject("adodb.recordset")
		rs.open "select userid,shopxpptid,username,pro_color,pro_size,pro_color_id,pro_size_id,zhuangtai,zonger,jifeng,productcount,niming from shopxp_action",conn,1,3
		rs.addnew
		rs("shopxpptid")=shopxpptid
		rs("username")=username
		set rs2=server.CreateObject("adodb.recordset")
		rs2.open "select UserID,username from com_user where username='"&username&"'",conn,1,3
		rs("userid")=rs2("UserID")
		rs("zhuangtai")=9
		rs("productcount")=Quatity
		rs("pro_color")=pro_color
		rs("pro_size")=pro_size
		rs("pro_color_id")=p_color_id
		rs("pro_size_id")=p_size_id
		rs("zonger")=Quatity*danjia
		rs("jifeng")=Quatity*danjifeng
		if session("user_xxx_name")="" then
		rs("niming")=1
		end if
		rs.update
		rs2.close
		set rs2=nothing
		rs.close
		set rs=nothing
		
end if


	set rs=server.CreateObject("adodb.recordset")
	rs.open "select shopxp_action.shopxpacid,shopxp_action.shopxpptid,shopxp_action.productcount,shopxp_action.zonger,com_books.titlecn,com_books.shichangjia,com_books.shopxphyjia,com_books.shopxpvjia from com_books inner join  shopxp_action on com_books.id=shopxp_action.shopxpptid where shopxp_action.username='"&username&"'  and shopxp_action.zhuangtai=9",conn,1,1 
	shuliang=rs.recordcount
	jianshu=0
	zongji=0
	do while not rs.eof
	bookiid=rs("shopxpptid")
	jianshu=jianshu+rs("productcount")
	zongji=zongji+rs("zonger")
	rs.movenext
	loop
	session("S[CART_COUNT]")=shuliang
	'response.write "<script>document.cookie='S[CART_COUNT]=5'; </script->"
	
	'response.write "添加成功，感谢你的购买，目前选购商品共["&shuliang&"]款["&jianshu&"]件 合计:￥"&Formatnumber(zongji,2,-1,-1,0)
	
	response.write "{""result"":""success"",""data"":{""privilegeProductHtml"":""<ul class=\""prodlist\"">\r\n\t<li><a href=\""#\""> <span class=\""pic\""><img\r\n\t\t\t\tsrc=\""/userfiles/productimages/20130217/60x60/1503117050__60x60.jpg\""></span>\r\n\t\t\t<span class=\""name\""> 新款男士时尚潮流夹克 JS164</span> <span\r\n\t\t\tclass=\""price\"">￥118.00</span>\r\n\t</a></li>\r\n\t<li><a href=\""#\""> <span class=\""pic\""><img\r\n\t\t\t\tsrc=\""/userfiles/productimages/20130217/60x60/1503117050__60x60.jpg\""></span>\r\n\t\t\t<span class=\""name\""> 新款男士时尚潮流夹克 JS164</span> <span\r\n\t\t\tclass=\""price\"">￥118.00</span>\r\n\t</a></li>\r\n</ul>"",""shoppingCartQuantity"":"&jianshu&",""shoppingCartPrice"":"&Formatnumber(zongji,2,-1,-1,0)&"}}"
	
	rs.close
	set rs=nothing
%>

