<!--#include file="conn.asp"-->
<!--#include file="ajax_cart_set.asp"-->


<%
act=request("action")
dingdan=request("orderId")
%>

<%
select case act
case "cancelOrder"

'删除前要返还库存及积分
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,username 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 rs("jifen_dk")<>0 then
	call jifen_record(session("user_xxx_name"),rs("jifen_dk")*cart_jfdk,0,"取消订单返还积分")
	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='orderList.asp';</script>"
response.end()

case "confirmReciveOrder"
	conn.execute "update shopxp_action set zhuangtai=5 where dingdan='"&dingdan&"' "
		priceZongji=0
		set rs=server.CreateObject("adodb.recordset")
		rs.Open "select jifeng from shopxp_action where dingdan='"&dingdan&"'",conn,1,3
		do while not rs.EOF
		priceZongji=rs("jifeng")+priceZongji
		rs.MoveNext
		loop
		rs.Close
		set rs=nothing
		
		if session("user_xxx_name")<>"" then
		usjifen=priceZongji
		set rsu=server.CreateObject("adodb.recordset")
		rsu.open "select * from [com_user] where username='"&trim(session("user_xxx_name"))&"'",conn,2,3
		
		if (rsu("jifen")+usjifen)>int(vip_two) and rsu("reglx")<3 then
				rsu("reglx")=3
				session("user_xxx_vip")=3
		elseif  (rsu("jifen")+usjifen)>int(vip_one) and rsu("reglx")<2 then
				rsu("reglx")=2
				session("user_xxx_vip")=2
		end if
		
		rsu("jifen")=rsu("jifen")+usjifen
		rsu.update
		rsu.close
		set rsu=nothing
		end if
		'记录积份消费
		if cart_jfdk<>0 then
		call jifen_record(session("user_xxx_name"),usjifen,0,"订单完成获得积分")
		end if
	
	
    response.Write "<script language=javascript>alert('订单状态修改成功！');location.href='orderDetail.asp?dingdan="&dingdan&"';</script>"
	response.end()
case else
	response.Write "<script language=javascript>alert('非法操作，确定返回列表！');location='orderList.asp';</script>"
end select
%>
