<!-- #include file="include/config.asp" -->
<!-- #include file="../include/jk_email.asp" -->
<!-- #include file="../include/jk_val_code.asp" -->
<%
dim p_id,psort
p_id=trim(request.querystring("id"))
if not joekoe_cms.int_true(p_id) then p_id=0
psort=left(index_url,3)&"ep"

tit="收 银 台"

call web_head(0,0,0,0,0)
call shop_load()
'----------------------------左边 开始----------------------------
call shop_left()
call shop_left_nsort(0)
call shop_top(10,10)
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------

select case action
case "pay"
  call shop_emoney_pay_chk()
case else
  call shop_emoney_pay_bag()
  call shop_emoney_pay_type()
end select

'----------------------------中间 结束----------------------------
call web_end(0,0)

sub shop_emoney_pay_chk()
  dim tmp1,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,n_title
  n_title=tit&"（生成订单）"
  if not joekoe_cms.chk() then
    tmp1=vbcrlf&"<table border=0>" & _
         vbcrlf&"<tr class=bg_td><td height=100 align=center><font class=red>"&web_nopost&"</font></td></tr>" & _
         vbcrlf&"</table>"
  call shop_center_table(n_title,tmp1,1,1)
    exit sub
  end if
  if val_chk(psort)=false then
    tmp1=vbcrlf&"<table border=0>" & _
         vbcrlf&"<tr class=bg_td><td align=center height=150>您提交的 <font class=red>验 证 码</font> 为空或有错误，请勿非法提交！</td></tr>"
  call shop_center_table(n_title,tmp1,1,1)
    exit sub
  end if
  sql="select top 1 emoney from shop_product where hidden=1 and is_emoney=1 and id="&p_id
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    response.write "<tr class=bg_td><td height=100 align=center><font class=red>您所要支付的"&web_dim(44)&"不存在！</font></td></tr>"
    response.write vbcrlf&"</table>"
    exit sub
  end if
  n_price=rs(0)
  rs.close
  nname=joekoe_cms.code_form(request.form("nname"))
  address=joekoe_cms.code_form(request.form("address"))
  code=joekoe_cms.code_form(request.form("code"))
  phone=joekoe_cms.code_form(request.form("phone"))
  email=joekoe_cms.code_form(request.form("email"))
  serial=joekoe_cms.code_form(request.form("serial"))
  pnum=joekoe_cms.code_form(request.form("pnum"))
  pname=joekoe_cms.code_form(request.form("pname"))
  remark=joekoe_cms.code_form(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>login_emoney then
    response.write "<script language=javascript>alert('您所拥有的 "&joekoe_cms.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 email_ok(email,50)=false then
    found_err=found_err&"+请输入正确格式的 <font class=red>电子信箱</font>！<br>"
  end if
  if found_err<>"" then
    response.write found_error(found_err,340)
    response.write vbcrlf&"</table>"
    exit sub
  end if
  
  carry=""
  dim_carry=split(web_dim(49),":")
  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"&joekoe_cms.time_type(joekoe_cms.now_time,11)
  p_order_true=true
  sql="select top 1 id from shop_emoney_notes where ordernum='"&ordernum&"'"
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then p_order_true=false
  rs.close
  if p_order_true=false then
    tmp1=vbcrlf&"<table border=0>" & _
         vbcrlf&"<tr class=bg_td><td height=100 align=center><font class=red>对不起，购买"&web_dim(44)&"的用户太多，请稍候再提交购买！</font></td></tr>" & _
         vbcrlf&"</table>"
  call shop_center_table(n_title,tmp1,1,1)
    exit sub
  end if
  
  sql="insert into shop_emoney_notes(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&"','"&joekoe_cms.now_time&"',0,'"&carry&"',"&carry_price&")"
  call joekoe_cms.exec(sql,0)
  call joekoe_cms.exec("update user_data set emoney=emoney-"&allemoney&" where username='"&login_username&"'",0)
  tmp1=vbcrlf&"<table border=0>" & _
       vbcrlf&"<tr class=bg_td><td align=center height=50>恭喜：订单已经成功递交！订单号：<font size=3 class=red><b>"&ordernum&"</b></font></td></tr>" & _
       vbcrlf&"<tr><td align=center>确认您的货款后，我们将按您的运送方式向您发货或与您联系。</td></tr>" & _
       vbcrlf&"<tr><td align=center>请牢记您的订单号(<font class=red>"&ordernum&"</font>)，以便查询！</td></tr>" & _
       vbcrlf&"<tr><td align=center height=50><input type=button class=btn value='继续购物' onClick=""javascript:window.location.href='index.asp';""></td></tr>"
  call val_chk_end(psort)
  call shop_center_table(n_title,tmp1,1,1)
end sub

sub shop_emoney_pay_bag()
  dim epname,epprice,epserial,epemoney,ds,chk_emoney,tmp1
  ds=false
  chk_emoney=true
  tmp1=vbcrlf&"<form name=shop_pay_frm action='?id="&p_id&"&action=pay' method=post onsubmit=""javascript:frm_submitonce(this);"">" & _  
       vbcrlf&""&val_code_num(psort,1)&"" & _
       vbcrlf&"<tr><td colspan=2 class=bg_tds height=30 align=center><b>以下是您所选购的"&web_dim(44)&"</b></td></tr>"
sql="select top 1 * from shop_product where is_emoney=1 and id="&p_id
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    epname=joekoe_cms.code_js(rs("name"),0)
    epemoney=rs("emoney")
    epserial=rs("serial") 
   tmp1=tmp1&vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td width='20%'>"&web_dim(44)&"名称：</td>" & _
       vbcrlf&"<td width='80%'><b><a class=red href='view.asp?id="&p_id&"' target=_blank>"&epname&"</font></b></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<input type=hidden name=pname value='"&epname&"'>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>"&web_dim(44)&"编号：</td>" & _
       vbcrlf&"<td>"&epserial&"</td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<input type=hidden name=serial value='"&epserial&"'>" & _	   
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>所需"&joekoe_cms.web_unit&"：</td>" & _
       vbcrlf&"<td><font class=red2>"&epemoney&"</font>&nbsp;&nbsp;"&joekoe_cms.web_unit&"</font></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       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 ds=false then 
tmp1=tmp1&vbcrlf&"<tr class=bg_tds><td colspan=2 height=30 align=center>您目前还没有选购"&web_dim(44)&"&nbsp;</td></tr>"
  chk_emoney=false
  end if
  if login_emoney<epemoney then 
tmp1=tmp1&vbcrlf&"<tr class=bg_tds><td colspan=2 height=30 align=center>您目前有 <font class=red2>"&login_emoney&"</font> "&joekoe_cms.web_unit&"，暂时还不够支付此"&web_dim(44)&"！&nbsp;</td></tr>"
  chk_emoney=false
  end if
  if chk_emoney=true then
    tmp1=tmp1&vbcrlf&"<tr class=bg_tds><td colspan=2 height=50 align=center>" & _
         "您目前拥有的&nbsp;<b><font class=blue>"&joekoe_cms.web_unit&"</font></b>&nbsp;数量为：<font class=red2>"&login_emoney&"</font>&nbsp;个" & _
         "&nbsp;</td></tr>"
  end if
  tmp1=tmp1&vbcrlf&""
  call shop_center_table(tit,tmp1,1,1)
end sub

sub shop_emoney_pay_type()
dim tmp1,dim_carry,carry,carry_price
%>
<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>
<%
  tmp1=vbcrlf&"<input type=hidden name=chk value='yes'>" & _
       vbcrlf&"<tr><td colspan=2 class=trs align=center><b>"&tit&"　　填写收货信息</b></td></tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       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 
  tmp1=tmp1&vbcrlf&"<font class=red>（会员："&login_username&"）</font>"
       end if
  tmp1=tmp1&"</td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>收货人地址：</td>" & _
       vbcrlf&"<td><input type=text name=address size=50 maxLength=200></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>邮政编码：</td>" & _
       vbcrlf&"<td><input type=text name=code size=15 maxLength=6></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>联系电话：</td>" & _
       vbcrlf&"<td><input type=text name=phone size=30 maxLength=20></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>电子信箱：</td>" & _
       vbcrlf&"<td><input type=text name=email size=30 maxLength=50></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>运送方式：</td>" & _
       vbcrlf&"<td>" & _
       vbcrlf&"  <table border=0>"
  carry="未设定"
  carry=0
  dim_carry=split(web_dim(49),":")
  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),","))
    tmp1=tmp1&vbcrlf&"  <tr><td><input type=radio name=carry_num value='"&i&"'"
    if i=0 then tmp1=tmp1&vbcrlf& " checked"
    tmp1=tmp1&vbcrlf& " class=bg_td>"&carry&"（"
    if int(carry_price)=0 then
      tmp1=tmp1&vbcrlf& "免费"
    else
      tmp1=tmp1&vbcrlf& "加"&carry_price&joekoe_cms.web_unit
    end if
    tmp1=tmp1&vbcrlf& "）</td></tr>"
  next
  erase dim_carry
  tmp1=tmp1&vbcrlf&"  </table>" & _
       vbcrlf&"</td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td valign=top><br>备注信息：<br><=250</td>" & _
       vbcrlf&"<td><textarea name=remark cols=50 rows=5></textarea></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_tds><td colspan=2 align=center height=40><input type=submit class=btn value=' 提 交 支 付 ' onclick=""javascript:return pay_frm_submit(this.shop_pay_frm);"">　　<input type=reset class=btn value='重新填写'></td></tr>"
 call shop_center_table(tit,tmp1,1,1)
end sub

%>