<!-- #Include File="../Include/Channel_Shop.asp" -->
<!-- #Include File="Common.asp" -->
<%
'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

dim shop_session,sdim,ssum
shop_session=trim(request.cookies(Cls.web_cookies)("bag"))

tit_fir=Cls.ChannelName
tit="收 银 台"

call DoWebHead(0,0)
Call Channel_Load(0)
if Cls.Is_Null(shop_session)="" then
dim sTmp
sTmp="<table cellspacing=1 cellpadding=4 class=table>" & _
vbcrlf&"<tr class=tr><td align=center height=150><font class=red>您目前好像还没有选购"&Cls.ChannelTit&"！</font><br /><br /><input type=button value='点击继续购物' onClick=""javascript:window.location.href='Index.asp';""></td></tr>" & _
vbcrlf&"</table>"
Call ShowMsg(tit&" 错 误",sTmp)
else
  select case action
  case "pay"
    call shop_pay_chk()
  case else
    call shop_pay_bag()
  end select
end if
Call Channel_End(0)
call DoWebEnd()

sub shop_pay_chk()
dim sTmp,titel
titel=tit&"（生成订单）"
  if not Cls.chk() then
    Call ShowMsg(titel& "错误", "<table border=0><tr class=tr><td height=100 align=center><font class=red>"&web_nopost&"</font></td></tr></table>")
    exit sub
  end if
  dim oid,ordernum,isuser,nname,address,code,phone,email,payment,payment2,remark,carry_num,dim_carry,carry,carry_price,ispayment,ispay,found_err,p_order_true
  nname=Cls.Code_Var(request.form("nname"))
  address=Cls.Code_Var(request.form("address"))
  code=Cls.Code_Var(request.form("code"))
  phone=Cls.Code_Var(request.form("phone"))
  email=Cls.Code_Var(request.form("email"))
  payment=Cls.Code_Var(request.form("payment"))
  remark=Cls.Code_Var(request.form("remark"))
  remark=left(remark,250)
  carry_num=trim(request.form("carry_num"))
  if not isnumeric(carry_num) then carry_num=0
  found_err=""
  if nname="" or address="" then
    found_err=found_err&"+请输入 <font class=red>收货人姓名</font> 和 <font class=red>收货人地址</font>！<br />"
  end if
  if not isnumeric(code) or len(code)<>6 then
    found_err=found_err&"+请输入正确格式的 <font class=red>邮政编码</font>！<br />"
  end if
  if not isnumeric(phone) or len(phone)<6 then
    found_err=found_err&"+请输入 <font class=red>联系电话</font> 等信息！<br />"
  end if
  if Cls.Is_Email(email,50)=false then
    found_err=found_err&"+请输入正确格式的 <font class=red>电子信箱</font>！<br />"
  end if
   if Not Cls.CodeIsTrue() then
			Found_Err=Found_Err&"+您输入的 <font class=red>验 证 码</font> 为空或有错误，请勿非法提交！<br />"
		End If
  if found_err<>"" then 
    Call ShowMsg(tit&" 错 误",found_error(found_err,460))
    exit sub
  end if
  isuser=0
  carry=""
  ispayment=0
  ispay=0
  if login_mode<>"" then isuser=1
  dim_carry=split(val_carry,":")
  if int(carry_num)>ubound(dim_carry) then carry_num=0
  for i=0 to ubound(dim_carry)
    if int(i)=int(carry_num) then
      carry=left(dim_carry(i),instr(dim_carry(i),",")-1)
      carry_price=right(dim_carry(i),len(dim_carry(i))-instr(dim_carry(i),","))
      exit for
    end if
  next
  erase dim_carry
  if carry="" or not isnumeric(carry_price) then
    carry="未设定"
    carry_price=0
  end if
  payment2=payment
  select case payment
  	case "onlinepay"
    	payment="网银支付"
    	ispayment=1
  	case "alipay"
    	payment="支付宝支付"
    	ispayment=2
  end select
  ordernum=Cls.time_type(Cls.now_time,11)
  p_order_true=true
  sql="select top 1 id from AsaiMHShopOrders where ordernum='"&ordernum&"'"
  set rs=Cls.exec(sql,1)
  if not rs.eof then p_order_true=false
  rs.close
  if p_order_true=false then
    Call ShowMsg(titel& "错误","<table border=0><tr class=tr><td height=100 align=center><font class=red>对不起，购买"&web_shop(0)&"的用户太多，请稍候再提交购买！</font></td></tr></table>")
    exit sub
  end if
  sql="insert into AsaiMHShopOrders(username,isuser,ordernum,nname,address,code,phone,email,payment,remark,tim,types,carry,carry_price,ispayment,ispay) " & _
      "values ('"&login_username&"',"&isuser&",'"&ordernum&"','"&nname&"','"&address&"','"&code&"','"&phone&"','"&email&"','"&payment&"','"&remark&"','"&Cls.now_time&"',0,'"&carry&"',"&carry_price&","&ispayment&","&ispay&")"
  call Cls.exec(sql,0)
  oid=first_id("AsaiMHShopOrders","id")
  dim pid,n_serial,n_price,n_name,n_discount,n_num
  ssum=carry_price
  sdim=split(shop_session,",")
  for i=0 to ubound(sdim)
    pid=left(sdim(i),instr(sdim(i),"$")-1)
    n_num=right(sdim(i),len(sdim(i))-instr(sdim(i),"$"))
    if isnumeric(pid) and Cls.Is_Int(n_num) then
      sql="select top 1 name,serial,Price_Original,discount,is_emoney,emoney from AsaiMHShop where hidden=1 and id="&pid
      set rs=Cls.exec(sql,1)
      if not rs.eof then
        n_name=Cls.Code_Var(rs("name"))
        n_serial=Cls.Code_Var(rs("serial"))
        n_price=rs("Price_Original")
        n_discount=rs("discount")
        ssum=ssum+fm_price(n_price*(n_discount/100),1)*n_num
        sql="insert into AsaiMHShopOorders(oid,pid,serial,name,price,discount,num) " & _
            "values("&oid&","&pid&",'"&n_serial&"','"&n_name&"',"&n_price&","&n_discount&","&n_num&")"
        call Cls.exec(sql,0)
        call Cls.exec("update AsaiMHShop set buy_counter=buy_counter+1 where id="&pid,0)
        'call Cls.exec("update AsaiMHShop set stocks=stocks-"&n_num&" where id="&pid&" and stocks>0",0)
      end if
      rs.close
    end if
  next
  erase sdim
  call Cls.exec("update AsaiMHShopOrders set prices="&ssum&" where id="&oid,0)
  response.cookies(Cls.web_cookies)("bag")=""
sTmp="<tr class=tr><td align=center height=50>恭喜：订单已经成功递交！订单号：<font size=3 class=red><b>"&ordernum&"</b></font></td></tr>" & _
vbcrlf&"<tr class=tr><td align=center>确认您的货款后，我们将按您的运送方式向您发货或与您联系。</td></tr>" & _
vbcrlf&"<tr class=tr><td align=center>请牢记您的订单号(<font class=red>"&ordernum&"</font>)，以便查询！</td></tr>" & _
vbcrlf&"<tr class=tr><td align=center height=50><input class=btn type=button value='继续购物' onClick=""javascript:window.location.href='Index.asp';"">"
  dim puser,obj_pay
select case int(ispayment)
  case 1  '网银支付
  puser=login_username
  if login_mode="" then
    puser="_"&nname
  end if
  sTmp=sTmp&"　　<input class=btn type=button value='网银支付' onClick=""javascript:AsaiMHOnline_Pay();"">"
  set obj_pay=new AsaiMHPay
  obj_pay.pay_sort="shop"
  obj_pay.pay_username=puser
  obj_pay.pay_address=address
  obj_pay.pay_post=code
  obj_pay.pay_phone=phone
  obj_pay.pay_email=email
  obj_pay.pay_carry=carry&"("&carry_price&"元)"
  obj_pay.pay_remark=remark
  obj_pay.back_url=Cls.own_http()&"Shop/Pay_Return_Shop.asp"
  obj_pay.pay_ordernum=ordernum
  obj_pay.pay_amount=ssum
  call obj_pay.pay_frm(1)
  set obj_pay=nothing
  case 2 '支付宝支付
   Dim return_url,show_url
  return_url=Cls.own_http()&"Shop/Pay_Alipay_Notify.asp"
  show_url=Cls.own_http()&"Shop/"
  sTmp=sTmp&"　　<input class=btn type=button value='支付宝支付' onClick=""javascript:AsaiMHOnline_alipay();"">"
  set obj_pay=new AsaiMHalipay
  obj_pay.myAlipay_Initialize()
  call obj_pay.CreatAlipayItemURL(Cls.Web_Name&"购买"&Cls.ChannelTit,"订单编号:"&ordernum,ordernum,ssum,show_url,1,"EXPRESS","0","BUYER_PAY",return_url,return_url)
  set obj_pay=nothing
end select
sTmp=sTmp&"</td></tr></table>"
Call ShowMsg(titel,sTmp)
end sub

Function shop_pay_type()
dim sTmp,PaymentsTmp
 PaymentsTmp = Split(Cls.Web_Payment,"|")
sTmp=Vbcrlf&"<script language=javascript>" & _
Vbcrlf&"<!--" & _
Vbcrlf&"function pay_frm_submit(nfrm)" & _
Vbcrlf&"{" & _
Vbcrlf&"  if (nfrm.nname.value.length==0)" & _
Vbcrlf&"  {" & _
Vbcrlf&"    alert(""请输入收货人姓名！"");" & _
Vbcrlf&"    nfrm.nname.focus();" & _
Vbcrlf&"    return false;" & _
Vbcrlf&"  }" & _
Vbcrlf&"  if (nfrm.address.value.length==0)" & _
Vbcrlf&"  {" & _
Vbcrlf&"    alert(""请输入收货人具体地址！"");" & _
Vbcrlf&"    nfrm.address.focus();" & _
Vbcrlf&"    return false;" & _
Vbcrlf&"  }" & _
Vbcrlf&"  if (nfrm.code.value.length==0)" & _
Vbcrlf&"  {" & _
Vbcrlf&"    alert(""请输入邮政编码！"");" & _
Vbcrlf&"    nfrm.code.focus();" & _
Vbcrlf&"    return false;" & _
Vbcrlf&"  }" & _
Vbcrlf&"  if (nfrm.phone.value.length==0)" & _
Vbcrlf&"  {" & _
Vbcrlf&"    alert(""请输入联系电话！"");" & _
Vbcrlf&"    nfrm.phone.focus();" & _
Vbcrlf&"    return false;" & _
Vbcrlf&"  }" & _
Vbcrlf&"  if (nfrm.email.value.length==0)" & _
Vbcrlf&"  {" & _
Vbcrlf&"    alert(""请输入电子邮件！"");" & _
Vbcrlf&"    nfrm.email.focus();" & _
Vbcrlf&"    return false;" & _
Vbcrlf&"  }" & _
Vbcrlf&"  var cf=window.confirm(""您确定填写的收货信息准确无误吗？\n\n提交生成订单后将不可更改！"");" & _
Vbcrlf&"  if (cf)" & _
Vbcrlf&"  { return true; }" & _
Vbcrlf&"  else" & _
Vbcrlf&"  { return false; }" & _
Vbcrlf&"}" & _
Vbcrlf&"-->" & _
Vbcrlf&"</script>"
sTmp=sTmp&"<table cellspacing=1 cellpadding=4 class=table><form name=shop_pay_frm action='?action=pay' method=post onsubmit=""javascript:frm_submitonce(this);""><input type=hidden name=chk value='yes'><tr><td colspan=2 class=td align=center><b>填写收货信息</b></td></tr><tr class=tr><td width='20%'>收货人姓名：</td><td width='80%'><input type=text name=nname value='"&login_username&"' size=20 maxLength=20>"
if login_mode<>"" then
sTmp=sTmp&"　<font class=red>（会员："&login_username&"）</font>"
end if
sTmp=sTmp&"</td></tr><tr class=tr><td>收货人地址：</td><td><input type=text name=address size=50 maxLength=200></td></tr><tr class=tr><td>邮政编码：</td><td><input type=text name=code size=15 maxLength=6></td></tr><tr class=tr><td>联系电话：</td><td><input type=text name=phone size=30 maxLength=20></td></tr><tr class=tr><td>电子信箱：</td><td><input type=text name=email size=30 maxLength=50></td></tr><tr class=tr><td>付款方式：</td><td><table border='0' cellspacing='1' cellpadding='1'>"
if PaymentsTmp(0)<>"" then	'确认是否存在网银ID
sTmp=sTmp&"<tr><td><input name='payment' type='radio' value='onlinepay' checked></td><td><img src='"&Cls.Web_Dir&"Images/Bank/OnlinePayIocn.gif' alt='网银支付' width='171' height='50'></td></tr>"
end if
if PaymentsTmp(5)<>"" then	'确认是否存在支付宝ID
	if PaymentsTmp(0)<>"" then
sTmp=sTmp&"<tr><td><input name='payment' type='radio' value='alipay'></td><td><img src='"&Cls.Web_Dir&"Images/Bank/AlipayIocn.gif' alt='支付宝支付' width='171' height='50'></td></tr>"
	else
sTmp=sTmp&"<tr><td><input name='payment' type='radio' value='alipay' checked></td><td><img src='"&Cls.Web_Dir&"Images/Bank/AlipayIocn.gif' alt='支付宝支付' width='171' height='50'></td></tr>"
	end if
end if
if PaymentsTmp(0)="" And PaymentsTmp(5)="" then
sTmp=sTmp&"<tr><td><input name='payment' type='radio' value='银行转帐' checked></td><td>银行转帐</td></tr><tr><td><input name='payment' type='radio' value='邮局汇款'></td><td>邮局汇款</td></tr><tr><td><input name='payment' type='radio' value='现金支付'></td><td>现金支付</td></tr></table></td></tr><tr class=tr><td>运送方式：</td><td><table border=0>"
else
sTmp=sTmp&"<tr><td><input name='payment' type='radio' value='银行转帐'></td><td>银行转帐</td></tr><tr><td><input name='payment' type='radio' value='邮局汇款'></td><td>邮局汇款</td></tr><tr><td><input name='payment' type='radio' value='现金支付'></td><td>现金支付</td></tr></table></td></tr><tr class=tr><td>运送方式：</td><td><table border=0>"
end if
  dim dim_carry,carry,carry_price
  carry="未设定"
  carry=0
  dim_carry=split(val_carry,":")
  for i=0 to ubound(dim_carry)
    carry=left(dim_carry(i),instr(dim_carry(i),",")-1)
    carry_price=right(dim_carry(i),len(dim_carry(i))-instr(dim_carry(i),","))
    sTmp=sTmp&"  <tr><td><input type=radio name=carry_num value='"&i&"'"
    if i=0 then sTmp=sTmp&" checked"
    sTmp=sTmp&" >"&carry&"（"
    if int(carry_price)=0 then
      sTmp=sTmp&"免费"
    else
      sTmp=sTmp&"加"&carry_price&val_unit
    end if
    sTmp=sTmp&"）</td></tr>"
  next
  erase dim_carry
sTmp=sTmp&"</table></td></tr><tr class=tr><td valign=top><br />备注信息：<br /><=250</td><td><textarea name=remark cols=60 rows=6></textarea></td></tr><tr class=tr><td>验 证 码：</td><td>"&Cls.GetCode()&"</td></tr><tr class=trs><td colspan=2 align=center height=40><input class=btn type=button value='返回上一步' onclick=""javascript:window.history.go(-1);"">　　<input class=btn type=submit value='执行下一步' onclick=""javascript:return pay_frm_submit(this.form);""></td></tr></form></table>"
shop_pay_type=sTmp
End Function

sub shop_pay_bag()
  dim sTmp,nid,nnum,price,price_now,discount,name,ds
  ssum=0
  ds=" disabled"
  sdim=split(shop_session,",")
sTmp="<table cellspacing=1 cellpadding=4 class=table><tr class=trb><td colspan=7 height=30 align=center><font class=red>以下是您所选购的"&Cls.ChannelTit&"清单</font></td></tr><tr height=22 align=center><td width='8%' class=td>序号</td><td width='38%' class=td>"&Cls.ChannelTit&"名称</td><td width='8%' class=td>数量</td><td width='13%' class=td>原价("&val_unit&")</td><td width='8%' class=td>折扣</td><td width='13%' class=td>现价("&val_unit&")</td><td width='12%' class=td>"&web_dim(8)&"支付</td></tr>"
  for i=0 to ubound(sdim)
    nid=left(sdim(i),instr(sdim(i),"$")-1)
    nnum=right(sdim(i),len(sdim(i))-instr(sdim(i),"$"))
    if isnumeric(nid) and Cls.Is_Int(nnum) then
      sql="select top 1 name,serial,Price_Original,discount,is_emoney,emoney from AsaiMHShop where hidden=1 and id="&nid
      set rs=Cls.exec(sql,1)
      if not rs.eof then
        name=Cls.Code_Html(rs("name"),1,0)
        price=fm_price(rs("Price_Original"),1)
        discount=rs("discount")
        price_now=fm_price(price*(discount/100),1)
        discount=Cls.FM_Discount(discount)
        ssum=ssum+price_now*nnum
sTmp=sTmp&"<tr class=tr align=center><td>"&i+1&"</td><td align=left><a href='#' title='"&Cls.ChannelTit&"编号："&rs("serial")&"<br />点击浏览"&Cls.ChannelTit&"详细信息' onclick=""javascript:open_view('View.asp?id="&nid&"',1);"">"&name&"</a></td><td>"&nnum&"</td><td align=right>"&price&"</td><td>"
        if discount=Cls.FM_Discount(100) then
          sTmp=sTmp&"<font class=Gys>"&discount&"</font>"
        else
          sTmp=sTmp&"<font class=red2>"&discount&"</font>"
        end if
sTmp=sTmp&"</td><td align=right><font class=blue>"&price_now&"</font></td><td>"
        if rs("is_emoney") then
          sTmp=sTmp& rs("emoney")
        else
          sTmp=sTmp&"<font class=Gys>不可用</font>"
        end if
sTmp=sTmp&"</td></tr>"
        ds=""
      end if
      rs.close
    end if
  next
sTmp=sTmp&"<tr class=trs><td colspan=7 height=30 align=right>"
  if ds="" then
    sTmp=sTmp&"您所选购的"&Cls.ChannelTit&"总的有效金额：<font class=red>"&fm_price(ssum,1)&"</font>&nbsp;"&val_unit
  else
    sTmp=sTmp&"您目前还没有选购"&Cls.ChannelTit
  end if
sTmp=sTmp&"&nbsp;</td></tr>"&shop_pay_type()&"</table>"
  erase sdim
Call ShowMsg(tit,sTmp)
end sub
%>
