<!--#include file=conn.asp-->
<!--#include file=config.asp-->
<!--#include file=const.asp-->
<!--#include file=char.asp-->
<!--#include file=Visual_const.asp-->
<%
 '=========================================================
' File: visual_buy.asp
' Version:3.0
' Date: 2005-10-29
' Script Written by xmrxw
'=========================================================
' Copyright (C) 2004,2005 Xmrxw.Com All rights reserved.
' Web: http://www.xmrxw.com,http://www.xmzxw.com
' Email: info@mssky.com,super@mssky.com
' QQ：10689579　Msn：zdlmicr@hotmail.com
'=========================================================
dim CurItems,ItemName,rsvisual
dim SucFlag,CurItem,CartBag,SendMsg,CurType,SalePrice,Vipprice
response.buffer=true
if not Founduser then
		Errmsg=Errmsg+"<br>"+"<li>您还没有<a href=login.asp>登陆</a>，不能使用个人形象设计功能。如果您还没有<a href=reg.asp>注册</a>，请先<a href=reg.asp>注册</a>！"
	Founderr=true
end if
stats="个人形象设计"
CurItem=CheckStr(request("itemid"))
if isnull(curitem) then
	Errmsg=Errmsg+"<br>"+"<li>没有指定商品编号！"
	Founderr=true
else
	if not isnumeric(curitem) then
		Errmsg=Errmsg+"<br>"+"<li>提交的数据有错误！"
		Founderr=true
	end if
end if
call nav()
if founderr then
	call head_var("","")
	call Mslove_error()
else
	call head_var("个人形象设计","Visual.asp")
	call main()
if Founderr=true then call Mslove_error()
end if
call activeonline()
call footer()

sub main()
set rsvisual=server.createobject("ADODB.Recordset")
	sql="select top 1 itemid from visual_myitems where username='"&MemberName&"' and itemid="&CurItem
	rsvisual.open sql,conn,1,1
	if not (rsvisual.eof or rsvisual.bof) then
		Errmsg=Errmsg+"<br>"+"<li>已经拥有该商品，无须再次购买！"
		Founderr=true
		exit sub
	else
		if request("fromuser")<>"" then
			rsvisual.close
			sql="select m.username,m.saleprice,v.name,v.type from visual_myitems m inner join visual_items v on m.itemid=v.id where m.itemid="&CurItem&" and m.username='"&CheckStr(trim(request("fromuser")))&"'"
			rsvisual.open sql,conn,1,1
			ItemName=rsvisual("name")
			CurType=rsvisual("type") mod 100
			if CurType>=5 then CurType=4
			saleprice=rsvisual("salePrice")
			if cint(saleprice)>clng(mymoney) then
				Errmsg=Errmsg+"<br>"+"<li>购买此商品需要现金 "&saleprice&" 元，您的现金("&mymoney&" 元)不足，无法购买！"
				Founderr=true
				exit sub
			end if
		else
			rsvisual.close
			sql="select vip,quantity,flag,name from visual_items where id="&CurItem
			rsvisual.open sql,conn,1,1
			ItemName=rsvisual("name")
			if rsvisual("vip") and v_myvip<>1 then
				Errmsg=Errmsg+"<br>"+"<li>您不是VIP，不能购买VIP专用商品！"
				Founderr=true
				exit sub
			end if
			if rsvisual("quantity")<=0 then
				Errmsg=Errmsg+"<br>"+"<li>该商品库存不足，您无法购买！"
				Founderr=true
				exit sub
			end if
			if rsvisual("flag")=0 then
				Errmsg=Errmsg+"<br>"+"<li>保留商品，您无法购买！"
				Founderr=true
				exit sub
			end if
			if rsvisual("flag")=1 and MemberName="" then
				Errmsg=Errmsg+"<br>"+"<li>只有会员才能购买此商品，您无法购买！"
				Founderr=true
				exit sub
			end if
			if rsvisual("flag")=2 and not Master and not StandMaster and not SuperMaster then
				Errmsg=Errmsg+"<br>"+"<li>只有版主以上人员才能购买此商品，您无法购买！"
				Founderr=true
				exit sub
			end if
			if rsvisual("flag")=3 and not Master and not SuperMaster then
				Errmsg=Errmsg+"<br>"+"<li>只有超级版主和管理员才能购买此商品，您无法购买！"
				Founderr=true
				exit sub
			end if
			if rsvisual("flag")=4 and not Master then
				Errmsg=Errmsg+"<br>"+"<li>只有管理员才能购买此商品，您无法购买！"
				Founderr=true
				exit sub
			end if
		end if
			if request("fromuser")<>"" then
				conn.execute("update visual_myitems set type="&curtype&",price=saleprice,saleprice=0,fromuser=username,username='"&MemberName&"' where itemid="&curitem&" and type=5 and username='"&CheckStr(trim(request("fromuser")))&"'")
				conn.execute("update visual_events set username='"&MemberName&"' where itemid="&curitem&" and type=2 and fromuser='"&CheckStr(trim(request("fromuser")))&"' and (username='' or isnull(username))")
				conn.execute("insert into visual_events (ItemID,UserName,FromUser,DateAndTime,Price,Type) values ("&CurItem&",'"&MemberName&"','"&CheckStr(trim(request("fromuser")))&"','"&year(now())&"-"&month(now())&"-"&day(now())&"',"&saleprice&",0)")
				conn.execute("update [Ms_user] set userwealth=userwealth-"&saleprice&" where username='"&MemberName&"'")
				conn.execute("update [Ms_user] set userwealth=userwealth+"&saleprice&" where username='"&CheckStr(trim(request("fromuser")))&"'")
				conn.execute("insert into Ms_message (incept,sender,title,content,sendtime,flag,issend) values ('"&trim(request("fromuser"))&"','"&webname&"','您出售的商品有人购买了','您在二手市场出售的商品《[color=blue]"&itemName&"[/color]》已经被"&MemberName&"购买了！',Now(),0,1)")
				sucmsg=sucmsg+"<br>"+"<li>已经成功地购买了二手商品 <font color=blue>"&ItemName&"</font>！"
				call Mslove_suc()
				response.write "<script>"
				response.write "window.opener.document.execCommand('Refresh');"
				response.write "</script>"
			else
				CartBag=request.cookies("mybuy_"&Userid)
				if isnull(CartBag) then CartBag=""
				if instr(1,"|"&CartBag&"|","|"&CurItem&"|")<=0 then
					if ubound(split(CartBag,"|"))<CartLength-1 then
						if CartBag<>"" then CartBag=CartBag&"|"
						CartBag=CartBag&CurItem
						response.cookies("mybuy_"&Userid)=CartBag
						sucmsg=sucmsg+"<br>"+"<li>已将商品 <font color=blue>"&ItemName&"</font> 放到您的购物袋中！"
						call Mslove_suc()
					else
						Errmsg=Errmsg+"<br>"+"<li>您的购物袋已满，无法将此商品放入！"
						Founderr=true
						exit sub
					end if
				else
					Errmsg=Errmsg+"<br>"+"<li>购物袋中已有此商品，无须再次购买！"
					Founderr=true
					exit sub
				end if
			end if
	end if
	rsvisual.close
	set rsvisual=nothing
end sub
%>   
</body>
</html> 