<%
'**************************************
'* 最后更新 2013-10-17 by 56770.Kingdge
'* Copyright www.56770.com
'**************************************
Dim basket_cash,sum1,sum2,js,totalcash,sum_weight,fei,fei1,fei2,fei_z,z_price,strdiscount,error_type
Dim yy,mm,dd,ymd,xiaoshi,fenzhong,miao,billno,order_number,userid,orderid,rss,order_coupon_price,sql,order_id,CookiesId
Dim from_name,from_adds,from_email,from_tel,from_zip,from_other,from_mobile,to_name,to_adds,to_tel,to_tel2,to_zip,to_other,to_mobile,sendtype1,fukuan_id,paymenttype_id,paymenttype,sendtype,jifen,fapiao_company,fapiao_adds,fapiao_zip,iffapiao,from_adds2,from_city,from_state,from_country
Dim Quatity,casherror,z_discount,dis_sum,z_str1,z_str2,z_str3,z_str4,Use_Coupon,coupon_num,Scoupon,coupon_type,coupon_price,coupon_discount,basketlastprice,fapiao_money,pro_money,fei_money,sum_money,packing_price,packing_id,is_booking,advance_money,sum4,odd_money,low_money
rem <-{增加外部提交检测 by 56770.Kingdge 2009-3-22
Dim server_v1,server_v2
server_v1 = Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2 = Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(server_v1,8,len(server_v2)) <> server_v2  Then
		response.redirect Eshop_url
		response.End
End If
rem }->
checkuser()
CookiesId = CheckNum(request.cookies(cookiesname&"_user")("cookiesid"),0)
If CookiesId = 0 Then
        response.redirect Eshop_url & PagePath(1) &"?action=nocookies"
		response.End
End If
If CInt(getGradePurview(0)) <> 1 Then
		response.redirect Eshop_url & PagePath(1) &"?action=notgrade&HTTP_REFERER="& server.urlencode(Eshop_url & PagePath(3)) &""
		response.End
End If 
Showpath = "<a href='"& Eshop_url & LangPath &"'>"& Lebi_word(0) &"</a> → "& Lebi_cart(57)
from_name=Safereplace(trim(request.form("from_name")))
from_adds=Safereplace(trim(request.form("from_adds")))
from_email=Safereplace(trim(request.form("from_email")))
from_tel=Replace(Safereplace(trim(request.form("from_tel")))," ","")
from_zip=Safereplace(trim(request.form("from_zip")))
from_other=Safereplace(trim(request.form("from_other")))
from_mobile=Safereplace(trim(request.form("from_mobile")))
from_adds2=Safereplace(trim(request.form("from_adds2")))
from_city=Safereplace(trim(request.form("from_city")))
from_state=Safereplace(trim(request.form("from_state")))
from_country=Safereplace(trim(request.form("from_country")))
to_name=Safereplace(trim(request.form("to_name")))
to_adds=Safereplace(trim(request.form("to_adds")))
to_tel=Safereplace(trim(request.form("to_tel")))
to_tel2=Safereplace(trim(request.form("to_tel2")))
to_zip=Safereplace(trim(request.form("to_zip")))
to_other=Safereplace(trim(request.form("to_other")))
to_mobile=Safereplace(trim(request.form("to_mobile")))
'        sendtype1=Safereplace(trim(request("sendtype1")))
'		fukuan_id=Safereplace(trim(request("fukuan_id")))
paymenttype_id=Safereplace(trim(request.form("paymenttype")))
Select Case paymenttype_id
	   Case "001"
	   paymenttype=Pay_chinabank(8)
	   Case "002"
	   paymenttype=Pay_alipay(10)
	   Case "003"
	   paymenttype=Pay_paypal(8)
	   Case "004"
	   paymenttype=Pay_bill(7)
	   Case "005"
	   paymenttype=Pay_tenpay(8)
	   Case "006"
	   paymenttype=Pay_tenpay2(8)
	   Case "007"
	   paymenttype=Pay_paypal_cn(8)
	   Case "008"
	   paymenttype=Pay_IPS(8)
	   Case "009"
	   paymenttype=Pay_baofu(8)
	   Case Else
			paymenttype=Safereplace(trim(request.form("paymenttype")))
End Select
rem	<-{ 新配送方式 2008-3-14 b 56770.WangLei
sendtype=Safereplace(trim(request.form("sendtype")))
fei = CheckNum(request.form("deliver_price"),56770)
rem 当没有选择配送方式时 配送费用默认56770同时给予错误提示
rem	}->
rem	<-{ 商品包装 2008-3-14 b 56770.WangLei
packing_price = CheckNum(request.form("packing_price"),0)
packing_id = CheckNum(request.form("packing_id"),0)
rem	}->
'发票信息
fapiao_company=Safereplace(trim(request.form("fapiao_company")))
fapiao_adds=Safereplace(trim(request.form("fapiao_adds")))
fapiao_zip=Safereplace(trim(request.form("fapiao_zip")))
iffapiao=checknum(request.form("iffapiao"),0)
set checkbasket = conn.execute("select cpid from [Lebi_lsbuy] where (sessionid="& CookiesId &" or (User_Id = '"& Lebi_UserId &"' and User_Id <> ''))")
If checkbasket.eof Then 
		Response.redirect Eshop_url & PagePath(1) &"?action=nothing"
End If 
checkbasket.close : Set checkbasket = Nothing 
set rs = conn.execute("select l.sprice,l.price,l.basket_count,l.p_weight,l.IsGift,l.advance_money,l.is_booking,l.advance_money,l.p_jifen,l.product_type,l.cpid from [Lebi_lsbuy] as l where (l.sessionid="& CookiesId &" or (l.User_Id = '"& Lebi_UserId &"' and l.User_Id <> ''))")
Sum1 = 0
Sum2 = 0
If Not rs.eof Then
		Do While Not rs.EOF
		If IsNull(rs("product_type")) Or rs("product_type") = "" Then 
			Set rsproduct = conn.execute("select categoryid from [Lebi_Product] where id = "& rs("cpid") &"")
			If Not rsproduct.eof Then 
				categoryid = rsproduct(0)
			End If 
			rsproduct.close : Set rsproduct = Nothing 
		End If 
		If rs("IsGift") = 0 Then
				Sum1 = Sum1 + (rs("sprice") * rs("basket_count"))
				Sum2 = Sum2 + (rs("price") * rs("basket_count"))
		Else
				Sum1 = Sum1 + 0
				Sum2 = Sum2 + 0
		End If
		Sum1=FormatNumber2(Sum1)
		Sum2=FormatNumber2(Sum2)
		js=FormatNumber2((Sum1-Sum2)/moneyhl)
		If left(js,2)="0-" Then
				js=Replace(FormatNumber2((Sum1-Sum2)/moneyhl),"0-","-")
		End If
		rem 修正商品重量计算 2007-11-17 by 56770.kingdge
		If Config_Lebi_Eshop(2) = 1 Then
				sum_weight = sum_weight + (rs("p_weight") * rs("basket_count"))
		Else
				sum_weight = 0
		End If
		rem	<-{ 预付款 by 56770.WangLei
		If rs("is_booking") = 1 And CInt(getGradePurview(19))=1 Then
				advance_money = advance_money + (rs("advance_money")/moneyhl) * rs("Basket_count")
				is_booking = 1
		ElseIf rs("is_booking") = 1 And CInt(getGradePurview(19))=0 Then
				advance_money = advance_money + 0
				is_booking = 1
		Else
				advance_money = advance_money + (rs("price")/moneyhl) * rs("Basket_count")
		End If
		rem	}->
		rem <-{获取父级类别，计算积分返还比率 2011-2-3 by 56770.kingdge
		If rs("product_type") = "unite" Then 
				jifen2 = jifen2 + (rs("price") * rs("basket_count") * getGradePurview(2))
		Else 
				c_rate = GetCategoryRate(categoryid)
				If InStr(c_rate,"|") = 0 Then c_rate = "1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1"
				jifen1 = jifen1 + rs("p_jifen") * rs("basket_count")
				If IsNumeric(Split(c_rate,"|")(Lebi_UserGrade-1)) Then 
						jifen2 = jifen2 + (rs("price") * rs("basket_count") * Split(c_rate,"|")(Lebi_UserGrade-1))
				Else
						jifen2 = jifen2 + (rs("price") * rs("basket_count") * getGradePurview(2))
				End If 
		End If 
		rem }->
		rs.movenext
		loop
End If
rs.close()
Sum3 = Sum2
rem 计算购物折扣
Dim dis_grade : dis_grade = CheckNum(request.cookies(cookiesname&"_user")("user_grade"),0)
If IsSqlDataBase = 1 Then
Set rs=conn.execute("select top 1 z_price,z_discount from [Lebi_discount] where z_price<="& Sum2 &" and charindex('"& dis_grade &"',z_flag)>0 order by z_id desc")
Else
Set rs=conn.execute("select top 1 z_price,z_discount from [Lebi_discount] where z_price<="& Sum2 &" and instr(z_flag,"& dis_grade &")>0 order by z_id desc")
End If
If rs.eof And rs.bof Then
		z_price="0"
		z_discount="1.00"
Else
		z_price=rs("z_price")
		z_discount=rs("z_discount")
		strdiscount = inttotext(rs("z_discount"))
		jifen = jifen * rs("z_discount")
End if
rs.close:Set rs=Nothing
z_str1 = dw & formatnumber2(z_price/moneyhl/moneyhl) & dw2
z_str2 = strdiscount
z_str3 = dw & formatnumber2(sum2*z_discount/moneyhl) & dw2
jifen = CLng(jifen1 + (jifen2 * z_discount))
Set rs = conn.execute("select coupon_num from [Lebi_lshy] where sessionid="& CookiesId &"")
If Not rs.eof Then
		If Trim(rs(0)) <> "" Then
				coupon_num = rs(0)
				Set Scoupon = conn.execute("select c_type,c_price,c_discount from [Lebi_coupon] where c_num = '"& coupon_num &"'")
				coupon_type = Scoupon(0)
				coupon_price = Scoupon(1)
				coupon_discount = Scoupon(2)
				Scoupon.close : Set Scoupon = Nothing
				If coupon_type = 0 Then coupon_price = coupon_price
				If coupon_type = 1 Then coupon_price = CDbl(Replace(formatnumber2((Sum2*z_discount) * (100-coupon_discount)/100),",",""))
				dis_sum = Sum2*z_discount
		Else
				dis_sum = Sum2*z_discount
		End If
Else
		dis_sum = Sum2*z_discount
End If
rs.close : Set rs = Nothing
If Iffapiao=1 Then
		If Config_Lebi_Eshop(2)="1" Then
				fapiao_money=(((Sum2*z_discount)+packing_price)*Config_Lebi_Eshop(14)/100)
		Else
				fapiao_money=0
		End If
Else
		fapiao_money=0
End If
sum_money=dis_sum+fei+fapiao_money+packing_price-coupon_price
low_money = FormatNumber2(advance_money*z_discount)
Dim Lang_low_money : Lang_low_money = FormatNumber2((advance_money*z_discount)/moneyhl)
odd_money = FormatNumber2(CDbl(dis_sum)+CDbl(fei)+CDbl(packing_price)+CDbl(fapiao_money)-CDbl((advance_money*z_discount)))
Dim Lang_odd_money : Lang_odd_money = FormatNumber2((CDbl(dis_sum)+CDbl(fei)+CDbl(packing_price)+CDbl(fapiao_money)-CDbl((advance_money*z_discount)))/moneyhl)
Dim Lang_advance_money : Lang_advance_money = FormatNumber2((advance_money*z_discount)/moneyhl)
advance_money = formatnumber2(advance_money*z_discount)
Dim Lang_dis_sum : Lang_dis_sum = FormatNumber2(dis_sum/moneyhl)
dis_sum = formatnumber2(dis_sum)
Dim Lang_fei : Lang_fei = formatnumber2(fei/moneyhl)
fei = formatnumber2(fei)
Dim Lang_packing_price : Lang_packing_price = formatnumber2(packing_price/moneyhl)
packing_price = formatnumber2(packing_price)
Dim Lang_fapiao_money : Lang_fapiao_money = formatnumber2(fapiao_money/moneyhl)
Dim Lang_coupon_price : Lang_coupon_price = formatnumber2(coupon_price/moneyhl)
fapiao_money = formatnumber2(fapiao_money)

If Len(from_name)<2 Or Len(from_name)>30 Or from_name="" Then
		casherror=True
		error_type = error_type &",6,"
End If
If Len(from_tel)<6 Or Len(from_tel)>50 Then
		casherror=True
		error_type = error_type &",2,"
End If
If IsValidEmail(from_email)=false Then
		casherror=True
		error_type = error_type &",3,"
End If
If Len(from_zip)>7 or Len(from_zip)<3 Then
		casherror=True
		error_type = error_type &",4,"
End If
If Len(from_adds)<2 Or Len(from_adds)>100 Or from_adds="" Then
		casherror=True
		error_type = error_type &",7,"
End If
If sys_soft = 0 Then 
		If Len(to_name)<2 Or Len(to_name)>30 Or to_name="" Then
				casherror=True
				error_type = error_type &",1,"
		End if
		If Len(to_tel)<6 Or Len(to_tel)>50 Then
				casherror=True
				error_type = error_type &",2,"
		End If
		If Len(to_zip)>7 or Len(to_zip)<3 Then
				casherror=True
				error_type = error_type &",4,"
		End If
		If Len(to_adds)<2 Or Len(to_adds)>100 Or to_adds="" Then
				casherror=True
				error_type = error_type &",5,"
		End If
End If 
If trim(sendtype)="" Or fei=56770 Then
		casherror=True
		error_type = error_type &",8,"
End If
If casherror=true Then
		response.redirect Eshop_url & PagePath(1) &"?action=basket_cashsave&error_type="& error_type
End If
%>