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

dim p_id,psort,shop_session,sTmp,sdim,sdim1,sdim2,sdim3
p_id=trim(request.querystring("id"))
if p_id="" then
	shop_session=trim(request.cookies(Cls.web_cookies)("bag"))
	sdim=split(shop_session,",")
	sdim1=ubound(sdim)
	sdim2=sdim(0)
	sdim2=left(sdim2,instr(sdim2,"$")-1)
	if sdim1>=1 then
		sdim3=sdim(1)
		sdim3=left(sdim3,instr(sdim3,"$")-1)
		'sdim3=Replace(sdim3,"$","")
		sdim3=sdim2&sdim3
	else
		sdim3=sdim2
	end if
end if
psort=left(Index_Url,3)&"ep"
tit="("&web_dim(8)&")收 银 台"

call DoWebHead(0,0)
Call Channel_Load(0)
tit_fir=Cls.ChannelName

select case action
case "pay"
  call shop_emoney_pay_chk()
case else
	if p_id<>"" then
  		call shop_emoney_pay_bag()
	else
		if sdim2=sdim3 then
			p_id=sdim2
  			call shop_emoney_pay_bag()
		else
			sTmp="<table cellspacing=1 cellpadding=4 class=table>" & _
			vbcrlf&"<tr class=tr><td align=center height=150><font class=red>"&web_dim(8)&"收银台不支持多件"&Cls.ChannelTit&"同时支付，请重新选择"&Cls.ChannelTit&"或点击购物车"&Cls.ChannelTit&""&web_dim(8)&"支付下相对应的数值！</font><br /><br /><input type=button value='点击返回购物车' onClick=""javascript:window.location.href='Bag.asp';""></td></tr>" & _
			vbcrlf&"</table>"
			Call ShowMsg(tit&" 错 误",sTmp)
		end if
	end if
  'call shop_emoney_pay_bag()
end select
'----------------------------中间 结束----------------------------
call DoWebEnd()

sub shop_emoney_pay_chk()
  dim n_price,ordernum,nname,pnum,pname,address,code,phone,email,remark,serial,carry_num,dim_carry,carry,carry_price,found_err,p_order_true,allemoney,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
  sql="select top 1 emoney from AsaiMHshop where hidden=1 and is_emoney=1 and id="&p_id
  set rs=Cls.exec(sql,1)
  if rs.eof then
    rs.close
    Call ShowMsg(titel& "错误", "<table border=0><tr class=tr><td height=100 align=center><font class=red>您所要支付的"&Cls.ChannelTit&"不存在！</font></td></tr></table>")
    exit sub
  end if
  n_price=rs(0)
  rs.close
  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"))
  serial=Cls.Code_Var(request.form("serial"))
  pnum=Cls.Code_Var(request.form("pnum"))
  pname=Cls.Code_Var(request.form("pname"))
  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
  if not isnumeric(pnum) then pnum=1
  allemoney=int(pnum*n_price)
  if allemoney>int(login_emoney) then
    Response.Write  "<script language=javascript>alert('您所拥有的 "&Cls.web_unit&" 不够，请重新选择购买的数量！');history.back(-1)</script>"
    exit sub
  end if
  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 phone="" 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(titel& "错误",  found_error(found_err,460))
    exit sub
  end if
  carry=""
  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
  allemoney=allemoney+carry_price
  ordernum="E"&Cls.time_type(Cls.now_time,11)
  p_order_true=true
  sql="select top 1 id from AsaiMHShopEmoneyNotes 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>对不起，购买"&Cls.ChannelTit&"的用户太多，请稍候再提交购买！</font></td></tr></table>")
    exit sub
  end if
  sql="insert into AsaiMHShopEmoneyNotes(ordernum,pid,serial,name,emoney,num,emoneys,username,nname,address,code,phone,email,remark,tim,types,carry,carry_price) " & _
      "values ('"&ordernum&"',"&p_id&",'"&serial&"','"&pname&"',"&n_price&","&pnum&","&allemoney&",'"&login_username&"','"&nname&"','"&address&"','"&code&"','"&phone&"','"&email&"','"&remark&"','"&Cls.now_time&"',0,'"&carry&"',"&carry_price&")"
  call Cls.exec(sql,0)
  call Cls.exec("update AsaiMHUserData set emoney=emoney-"&allemoney&" where username='"&login_username&"'",0)
  call Cls.exec("update AsaiMHShop set buy_counter=buy_counter+1 where id="&p_id,0)
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 type=button value='继续购物' onClick=""javascript:window.location.href='./';"">" & _
vbcrlf&"</td></tr>" & _
vbcrlf&"</table>"
    Call ShowMsg(titel,sTmp)
end sub

Function shop_emoney_pay_type()
dim sTmp
sTmp="<table cellspacing=1 cellpadding=4 class=table>" & _
vbcrlf&"<input type=hidden name=chk value='yes'>" & _
vbcrlf&"<tr><td colspan=2 class=td align=center><b>填写收货信息</b></td></tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td width='20%'>收货人姓名：</td>" & _
vbcrlf&"<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>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>收货人地址：</td>" & _
vbcrlf&"<td><input type=text name=address size=50 maxLength=200></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>邮政编码：</td>" & _
vbcrlf&"<td><input type=text name=code size=15 maxLength=6></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>联系电话：</td>" & _
vbcrlf&"<td><input type=text name=phone size=30 maxLength=20></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>电子信箱：</td>" & _
vbcrlf&"<td><input type=text name=email size=30 maxLength=50></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>运送方式：</td>" & _
vbcrlf&"<td>" & _
vbcrlf&"<table border=0>"
  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>" & _
vbcrlf&"</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td valign=top><br />备注信息：<br /><=250</td>" & _
vbcrlf&"<td><textarea name=remark cols=50 rows=5></textarea></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>验 证 码：</td>" & _
vbcrlf&"<td>"&Cls.GetCode()&"</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=trs><td colspan=2 align=center height=40><input type=submit value=' 提 交 支 付 ' onclick=""javascript:return pay_frm_submit(this.form);"">　　<input type=reset value='重新填写'></td></tr>" & _
vbcrlf&"</form>"
	%>
<script language=javascript>
<!--
function pay_frm_submit(nfrm)
{
  if (nfrm.nname.value.length==0)
  {
    alert("请输入收货人姓名！");
    nfrm.nname.focus();
    return false;
  }
  if (nfrm.address.value.length==0)
  {
    alert("请输入收货人具体地址！");
    nfrm.address.focus();
    return false;
  }
  if (nfrm.code.value.length==0)
  {
    alert("请输入邮政编码！");
    nfrm.code.focus();
    return false;
  }
  if (nfrm.phone.value.length==0)
  {
    alert("请输入联系电话！");
    nfrm.phone.focus();
    return false;
  }
  if (nfrm.email.value.length==0)
  {
    alert("请输入电子邮件！");
    nfrm.email.focus();
    return false;
  }
  var cf=window.confirm("您确定填写的收货信息准确无误吗？\n\n提交生成订单后将不可更改！");
  if (cf)
  { return true; }
  else
  { return false; }
}
-->
</script>
<%
shop_emoney_pay_type=sTmp
End Function

sub shop_emoney_pay_bag()
  dim sTmpl,epname,epprice,epserial,epemoney,ds,chk_emoney
  ds=false
  chk_emoney=true
  sql="select top 1 * from AsaiMHShop where is_emoney=1 and id="&p_id
sTmpl="<table cellspacing=1 cellpadding=4 class=table>" & _
vbcrlf&"<form name=shop_pay_frm action='?id="&p_id&"&action=pay' method=post onsubmit=""javascript:frm_submitonce(this);"">"
  set rs=Cls.exec(sql,1)
  if not rs.eof then
    epname=Cls.code_js(rs("name"),0)
    epemoney=rs("emoney")
    epserial=rs("serial")
sTmpl=sTmpl&"<tr class=tr>" & _
vbcrlf&"<td width='20%'>"&Cls.ChannelTit&"名称：</td>" & _
vbcrlf&"<td width='80%'><b><font class=red>"&epname&"</font></b></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<input type=hidden name=pname value='"&epname&"'>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>"&Cls.ChannelTit&"编号：</td>" & _
vbcrlf&"<td>"&epserial&"</td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<input type=hidden name=serial value='"&epserial&"'>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>所需"&Cls.web_unit&"：</td>" & _
vbcrlf&"<td><font class=red2>"&epemoney&"</font>&nbsp;&nbsp;"&Cls.web_unit&"</font></td>" & _
vbcrlf&"</tr>" & _
vbcrlf&"<tr class=tr>" & _
vbcrlf&"<td>购买数量：</td>" & _
vbcrlf&"<td><input type=text name=pnum size=6 maxlength=6 value='1'></td>" & _
vbcrlf&"</tr>"
    ds=true
  end if
  rs.close
  if not Is_LoginTrue then
       sTmpl=sTmpl&"<tr class=trs><td colspan=2 height=30 align=center class=red>"& web_nologin &"&nbsp;</td></tr>"
       chk_emoney=false
  else
  if ds=false then
     sTmpl=sTmpl&"<tr class=trs><td colspan=2 height=30 align=center>您目前还没有选购"& Cls.ChannelTit&"或"& Cls.ChannelTit&"ID错误！</td></tr>"
  chk_emoney=false
  end if
  if int(login_emoney)<int(epemoney) then
     sTmpl=sTmpl&"<tr class=trs><td colspan=2 height=30 align=center>您目前有 <font class=red2>"&login_emoney&"</font> "&Cls.web_unit&"，暂时还不够支付此"& Cls.ChannelTit&"！&nbsp;</td></tr>"
  chk_emoney=false
  end if
  end if
  if chk_emoney=true then
sTmpl=sTmpl&"<tr class=trs><td colspan=2 height=30 align=right>" & _
vbcrlf&"您目前拥有的&nbsp;<b><font class=blue>"&Cls.web_unit&"</font></b>&nbsp;数量为：<font class=red2>"&login_emoney&"</font>&nbsp;个" & _
vbcrlf&"&nbsp;</td></tr>" & _
vbcrlf&""&shop_emoney_pay_type()&""
  end if
sTmpl=sTmpl&"</table>"
Call ShowMsg(tit,sTmpl)
end sub
%>
