<!--#include file="conn.asp"-->
<!--#include file="fuction.asp"-->
<%dim dingdan,action
action=nosql(request.QueryString("action"))
dingdan=nosql(request.QueryString("dan"))
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")=nosql(request("zhuangtai"))
		rs.Update
		rs.MoveNext
	loop
	rs.Close
	set rs=nothing
end if

if cint(request("zhuangtai"))=5 and old_zhuangtai<>5 then
	jifen=0
	ifhuka=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 wygkcn_shop where shopid="&rs("shopid"),conn,1,1
		jifen=jifen+rs("shopcount")*rs2("yeshu")
		rs2.close
		set rs2=nothing
		
		'if rs("shopid")=clng(vipid) then 
		'	ifhuka=1
		'end if
		
		rs.MoveNext
	wend
	rs.Close
	set rs=server.CreateObject("adodb.recordset")
	rs.Open "select jifen,reglx,vipdate from [shop_user] where username='"&session("username")&"'",conn,1,3
	rs("jifen")=rs("jifen")+jifen
	if ifhuka=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 ifhuka=1 then 
		response.Write "<script language=javascript>alert('Order has been successfully updated. You receive "&jifen&" bonus points for this order.');history.go(-1);</script>"
	else
		response.Write "<script language=javascript>alert('Order has been successfully updated. You receive "&jifen&" bonus points for this order.');history.go(-1);</script>"
	end if
else
	response.Write "<script language=javascript>alert('Order has been successfully updated. ');history.go(-1);</script>"
end if

case "del"
set rs=server.CreateObject("adodb.recordset")
rs.open "select username,dingdan from shop_action where dingdan='"&dingdan&"' " ,conn,1,1
'先判断此订单是不是操作人的
if nosql(session("username"))<>trim(rs("username")) then
response.Write "You are not authorized to remove the order."
response.End
end if
'删除前要返还库存及积分
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from shop_action where  dingdan='"&dingdan&"' and zhuangtai=1",conn,1,1
while not rs.eof
	set rs_s=server.CreateObject("adodb.recordset")
	rs_s.open "select * from wygkcn_shop 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='"&session("username")&"'",conn,1,3
rs("jifen")=rs("jifen")+z_jifen
rs.update
rs.close
set rs=nothing
'只能是订了未付款时删除
conn.execute "delete from shop_action where dingdan='"&dingdan&"' and zhuangtai=1"
conn.execute "delete from shop_action_jp where dingdan='"&dingdan&"'"
response.Write "<script language=javascript>alert('deleted successfully!');window.close();</script>"
end select
%>