<%temp_shopping_order_make_handle=site.object_p%>
<!-- object[<%=site.object_p%>]::temp_shopping_order_make_handle -->
<%
Dim id_goods
Dim price_goods
Dim num_goods
dim fee '订单总金额

site.temp.shopping.cart.ReadCart()

If site.temp.shopping.cart.total = 0 Then
	site.Error.info = "您的购物车内没有商品！"
	site.Error.location = "back"
	site.Error.err()
End If

site.temp.customer.order.CheckForm()
site.temp.customer.order.CheckDeliverment()
total_money=site.temp.shopping.cart.total_money
CountDelivementFee=site.temp.customer.order.CountDelivementFee()
CountPremiumPrice=site.temp.customer.order.CountPremiumPrice(total_money)
CountPremiumDeliverFee=site.temp.customer.order.CountPremiumDeliverFee(CountDelivementFee)

fee=(total_money-CountPremiumPrice)+(CountDelivementFee-CountPremiumDeliverFee)
'response.write CountPremiumPrice
'response.end
'支付方式//////////////////////////////////////////////////////////////////
site.temp.customer.order.CheckPayment()

If site.temp.customer.Order.account_consume = 1 Then '~{UJ;'S`6nV'86~}
	If site.temp.customer.info.account_rest < fee Then
		site.Error.info = "您的帐户余额不够！"
		site.Error.location = "back"
		site.Error.err()
	End If
End If

'生成订单//////////////////////////////////////////////////////////////////
price_goods=0
num_goods=0
For i = 0 To site.temp.shopping.cart.total - 1

	id_goods = site.temp.shopping.cart.goods_id(i)
	price_goods = site.temp.shopping.cart.goods_price(i)
	num_goods = site.temp.shopping.cart.goods_num(i)

	If i > 0 Then
		site.temp.customer.order.str_time_c=site.temp.customer.order.str_time&"_"&i
	Else
		site.temp.customer.Order.str_time_c = site.temp.customer.Order.str_time
	End If

	site.temp.customer.Order.order_kind = "购买商品"
	site.temp.customer.Order.order_money = fee
	site.temp.customer.Order.goods_price = price_goods / num_goods
	site.temp.customer.Order.goods_id = id_goods
	site.temp.customer.Order.goods_num = num_goods

	site.temp.customer.Order.MakeOrder (0)

	conn.execute("update jins_goods_list set goods_stocks=goods_stocks-"&num_goods&" where goods_id="&id_goods&" ")

Next

'接口支付//////////////////////////////////////////////////////////////////
If site.temp.customer.Order.payup_interface = 1 Then

	site.temp.customer.account.consume_sum = fee
	site.temp.customer.account.consume_kind = "购买商品"
	site.temp.customer.account.consume_out = site.temp.customer.Order.payup_interface_name
	site.temp.customer.account.consume_temp = 0 '临时
	site.temp.customer.account.order_mark = site.temp.customer.Order.order_mark

	If Not site.temp.customer.account.MakeConsume() Then

		site.temp.customer.order.DropOrder(site.temp.customer.order.order_mark) '删除已创建的订单
		site.Error.info = "系统错误！" & site.Error.info
		site.Error.location = "back"
		site.Error.err()

	End If
	
End If

'帐户余额支付//////////////////////////////////////////////////////////////////
If site.temp.customer.Order.account_consume = 1 Then
	site.temp.customer.account.consume_sum = fee
	site.temp.customer.account.consume_kind = "购买商品"
	site.temp.customer.account.consume_out = "出帐"
	site.temp.customer.account.consume_temp = 1
	site.temp.customer.account.order_mark = site.temp.customer.Order.order_mark

	If Not site.temp.customer.account.MakeConsume() Then
		site.temp.customer.order.DropOrder(site.temp.customer.order.order_mark) '删除已创建的订单
		site.Error.info = "系统错误！" & site.Error.info
		site.Error.location = "back"
		site.Error.err()
	else
	    conn.execute("update jins_customer_order_list set customer_order_stat=2,customer_order_stat_description='确认到款' where customer_order_mark='"&site.temp.customer.order.order_mark&"' ")
	
	    site.temp.customer.Order.AddCount(site.temp.customer.order.order_mark) '增加积分
	    site.temp.customer.Order.EditSellnum(site.temp.customer.order.order_mark) '修改销售量
	
	End If
	
End If

'清空购物车//////////////////////////////////////////////////////////////////
session("FB_EM_1_SQL_jins_customer_cart") = ""

'发送邮件//////////////////////////////////////////////////////////////////
site.temp.customer.Order.SendMail (site.temp.customer.Order.sort_id)

site.Error.info=site.Error.info+"<br><br>订单生成成功！您此次订单的订单号为："&site.temp.customer.order.order_mark&""

site.Error.location = "back"

'接口支付//////////////////////////////////////////////////////////////////
If site.temp.customer.Order.payup_interface = 1 Then

site.Error.info=site.Error.info+"<br><br>您选择的支付方式是[ "&site.temp.customer.Order.payup_interface_name&"] ，请点击下一步开始进入相应的支付接口！"
site.Error.info=site.Error.info+"<br><br>注意：如果您的支付成功，系统将自动将您的订单状态改为[确认到款]，否则系统将自动删除已经创建的订单。<br>"
site.Error.location = "javascript:window.open('do.asp?tr=interface|defray|in&order_mark="&site.temp.customer.order.order_mark&"&consume_id="&site.temp.customer.account.consume_id&"');window.close();"

End If

site.Error.suc()
%>