<!--#include file="conn.asp"-->
<!--#include file="inc/cook2.asp"-->
<%
dingdan=request.QueryString("dan")
tid=request.QueryString("tid")
select case action
case "save"
if request("zhuangtai")<>"" then
	set rs=server.CreateObject("adodb.recordset")
	rs.Open "select zhuangtai,jifeng,expressOrder,expressDate,username from shopxp_action where dingdan='"&dingdan&"'",conn,1,3
	do while not rs.EOF
	old_zhuangtai=rs("zhuangtai")
		rs("zhuangtai")=request("zhuangtai")
		rs("expressOrder")=request("expressOrder")
		rs("expressDate")=now()
				jf=jf+rs("jifeng")
		username=rs("username")
		rs.Update
		rs.MoveNext
	loop
	rs.Close
	set rs=nothing
	
'			set rsu=server.CreateObject("adodb.recordset")
'		rsu.open "select * from [com_user] where username='"&username&"'",conn,2,3
'		rsu("jifen")=rsu("jifen")+jf
'		rsu.update
'		rsu.close
'		set rsu=nothing
		
		
end if

if request("zhuangtai")=4 then
fhsj=now()
conn.execute "update shopxp_action set fhsj=date() where dingdan='"&dingdan&"' "
end if
response.Write "<script language=javascript>alert('订单状态修改成功！');location.href='dingdan_view.asp?dan="&dingdan&"';</script>"

case "del"
'删除前要返还库存及积分
set rs=server.CreateObject("adodb.recordset")
rs.open "select productcount,dingdan,shopxpptid,UserName,jifen_dk,pro_color_id,pro_size_id,couponCodeNumber from shopxp_action where dingdan='"&dingdan&"'",conn,1,1
while not rs.eof

	set rs_s=server.CreateObject("adodb.recordset")
	rs_s.open "select * from com_PCR where colorid="&rs("pro_color_id")&" and  sizeid="&rs("pro_size_id")&" and proid="&rs("shopxpptid"),conn,1,3
	rs_s("kucun")=int(rs_s("kucun"))+int(rs("productcount"))
	rs_s.update
	rs_s.close
	set rs_s=nothing
	
	set rs_s=server.CreateObject("adodb.recordset")
	rs_s.open "select kucun,id,chengjiaocount from com_books where id="&rs("shopxpptid"),conn,1,3
	rs_s("kucun")=int(rs_s("kucun"))+int(rs("productcount"))
	rs_s("chengjiaocount")=int(rs_s("chengjiaocount"))-int(rs("productcount"))
	rs_s.update
	rs_s.close
	set rs_s=nothing
	
	set rs_s=server.CreateObject("adodb.recordset")
	rs_s.open "select UserID,jifen from com_user where username='"&rs("UserName")&"'",conn,1,3
	if not rs_s.eof or not rs_s.bof then  
	rs_s("jifen")=int(rs_s("jifen"))+(rs("jifen_dk")*cart_jfdk)
	rs_s.update
	end if
	rs_s.close
	set rs_s=nothing
	'记录积份消费
	if cart_jfdk<>0 then
	set rsjf=server.CreateObject("adodb.recordset")
	rsjf.open "select * from [com_jf] ",conn,1,3
	rsjf.addnew
	rsjf("username")=session("user_xxx_name")
	rsjf("acquisition")=rs("jifen_dk")*cart_jfdk
	rsjf("consumption")=0
	rsjf("textms")="删除订单返还积分"
	rsjf.update
	rsjf.close
	set rsjf=nothing
	end if
	
	if rs("couponCodeNumber")<>"" then
	set rs_s=server.CreateObject("adodb.recordset")
	rs_s.open "select * from com_coupon where CodeNumber='"&rs("couponCodeNumber")&"'",conn,1,3
	if not rs_s.bof or not rs_s.eof then
	rs_s("used")=0
	rs_s.update
	end if
	rs_s.close
	set rs_s=nothing
	end if	
	
rs.movenext
wend
rs.close

	

'只能是订了未付款时删除
conn.execute "delete from shopxp_action where dingdan='"&dingdan&"'"
response.Write "<script language=javascript>alert('订单删除成功！');location='user_order_manage.asp?tid="&tid&"';</script>"

case "del2"
conn.execute "delete from shopxp_action where dingdan='"&dingdan&"'"
response.Write "<script language=javascript>alert('订单删除成功！');location='user_order_manage.asp?tid="&tid&"';</script>"

case "modify"
zonger=request("zonger")
acid=request("acid")
dingdan=request("dan")
username=request("username")
set rs=server.CreateObject("adodb.recordset")
rs.Open "select zonger,shopxpacid from shopxp_action where shopxpacid="&acid&"",conn,1,3
rs("zonger")=zonger
rs.Update
rs.Close
set rs=nothing
response.redirect "dingdan_view.asp?dan="&dingdan&"&username="&username&"&tid="&tid&""

end select
%>