<!--#include file="conn.asp"-->
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆！');window.location.href='login.asp';</script>"
response.End
else
if session("flag")>2 then
response.Write "<div align=center><font size=80 color=red><b>您没有此项目管理权限！</b></font></div>"
response.End
end if
end if
dim action,dingdan,username
action=request.QueryString("action")
dingdan=request.QueryString("dan")
username=request.QueryString("username")
select case action
case "save"
if request("zhuangtai")<>"" then
	set rs=server.CreateObject("adodb.recordset")
	rs.Open "select zhuangtai from shop_action where dingdan='"&dingdan&"'",conn,1,3
	do while not rs.EOF
	old_zhuangtai=rs("zhuangtai")
		rs("zhuangtai")=request("zhuangtai")
		rs.Update
		rs.MoveNext
	loop
	rs.Close
	set rs=nothing
'conn.execute "update shop_action set zhuangtai="&request("zhuangtai")&" where dingdan='"&dingdan&"' "
end if
if request("zhuangtai")=4 then
fhsj=now()
conn.execute "update shop_action set fhsj=date() where dingdan='"&dingdan&"' "
end if

if cint(request("zhuangtai"))=5 and old_zhuangtai<>5 then
	jifen=0
	ifhuyuanka=0
		set rs2=server.CreateObject("adodb.recordset")
		rs2.Open "select vipid from shop_sys",conn,1,1
		vipid=rs2("vipid")
		rs2.close
		set rs2=nothing
	set rs=server.CreateObject("adodb.recordset")
	rs.Open "select shopcount,shopid from shop_action where dingdan='"&dingdan&"'",conn,1,1
	while not rs.eof
		set rs2=server.CreateObject("adodb.recordset")
		rs2.Open "select shopid,yeshu from shop_snsn where shopid="&rs("shopid"),conn,1,1
		jifen=jifen+rs("shopcount")*rs2("yeshu")
		rs2.close
		set rs2=nothing
		
		if rs("shopid")=cint(vipid) then 
			ifhuyuanka=1
		end if
		
		rs.MoveNext
	wend
	rs.Close
	'response.write ifhuyuanka&"'"&vipid
	'response.end
	set rs=server.CreateObject("adodb.recordset")
	rs.Open "select jifen,reglx,vipdate from [shop_user] where username='"&username&"'",conn,1,3
	rs("jifen")=rs("jifen")+jifen
	if ifhuyuanka=1 then 
		rs("reglx")=2
		if rs("vipdate")<>"" then 
		if rs("vipdate")<date then
		rs("vipdate")=date+365
		else
		rs("vipdate")=rs("vipdate")+365
		end if
		else
		rs("vipdate")=date+365
		end if
	end if
	rs.Update
	rs.Close
	set rs=nothing
	
	if ifhuyuanka=1 then 
		response.Write "<script language=javascript>alert('订单状态修改成功！本次购物获得积分:"&jifen&"，本次购买了会员卡，现在已经成为本站的VIP用户！！');history.go(-1);</script>"
	else
		response.Write "<script language=javascript>alert('订单状态修改成功！本次购物获得积分:"&jifen&"');history.go(-1);</script>"
	end if
else
	response.Write "<script language=javascript>alert('订单状态修改成功！');history.go(-1);</script>"
end if


'response.Write "<script language=javascript>alert('订单状态修改成功!');history.go(-1);window.opener.location.reload();</script>"
'response.Write dingdan
case "del"
'删除时要判断状态，未收到货时要返还积分和库存的
set rs=server.createobject("adodb.recordset")
rs.open "select zhuangtai from shop_action where dingdan='"&dingdan&"' ",conn,1,1
if rs("zhuangtai")=>5 then
rs.close

set rs=server.CreateObject("adodb.recordset")
rs.open "select * from shop_action where  dingdan='"&dingdan&"'",conn,1,1
while not rs.eof
	set rs_s=server.CreateObject("adodb.recordset")
	rs_s.open "select * from shop_snsn where shopid="&rs("shopid"),conn,1,3
	rs_s("kucun")=rs_s("kucun")+rs("shopcount")
	rs_s("chengjiaocount")=rs_s("chengjiaocount")-rs("shopcount")
	rs_s.update
	rs_s.close
	set rs_s=nothing
rs.movenext
wend
rs.close

z_jifen=0
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from shop_action_jp where  dingdan='"&dingdan&"'",conn,1,1
while not rs.eof
z_jifen=z_jifen+rs("jifen")
rs.movenext
wend
rs.close
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [shop_user] where username='"&request.Cookies("snsn")("username")&"'",conn,1,3
rs("jifen")=rs("jifen")+z_jifen
rs.update
rs.close
set rs=nothing

else
rs.close
set rs=nothing
end if
conn.execute "delete from shop_action where dingdan='"&dingdan&"' "
response.Write "<script language=javascript>alert('订单删除成功！');window.close();window.opener.location.reload();</script>"

end select

%>