<!-- #include file="include/config.asp" -->
<!-- #include file="../include/jk_email.asp" -->
<!-- #include file="../include/jk_md5.asp" -->
<%
dim shop_session,sdim,ssum
shop_session=trim(request.cookies(joekoe_cms.web_cookies&"_shop")("bag_"&n_sort))
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)
'----------------------------中间 开始----------------------------
call shop_bag_close()

if var_null(shop_session)="" then
  dim tmp1
  tmp1=vbcrlf&"<table border=0>" & _
       vbcrlf&"<tr class=bg_td><td align=center height=150><font class=red>您目前好像还没有选购"&web_dim(44)&"！</font><br><br><input type=button class=btn value='点击继续购物' onClick=""javascript:window.location.href='index.asp';""></td></tr>" & _
       vbcrlf&"</table>"
  call shop_center_table(tit,tmp1,1,0)
else
  select case action
  case "pay"
    call shop_pay_chk()
  case else
    call shop_pay_bag()
    call shop_pay_type()
  end select
end if

response.write ukong
'----------------------------中间 结束----------------------------
call shop_end()
call web_end(0,0)

sub shop_pay_chk()
  dim tmp1,n_title
  n_title=tit&"（生成订单）"
  if not joekoe_cms.chk() then
    tmp1=vbcrlf&"<table border=0>" & _
         vbcrlf&"<tr class=bg_td><td align=center height=150><font class=red>"&web_nopost&"</font></td></tr>" & _
         vbcrlf&"</table>"
  call shop_center_table(n_title,tmp1,1,3)
    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=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"))
  payment=joekoe_cms.code_form(request.form("payment"))
  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
  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,240)
    response.write vbcrlf&"</table>"
    exit sub
  end if
  
  isuser=0
  carry=""
  ispayment=0
  ispay=0
  if login_mode<>"" then isuser=1
  dim_carry=split(web_dim(48),":")
  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
  if payment="onlinepay" then
    payment="在线支付"
    ispayment=1
  end if
  
  ordernum=joekoe_cms.time_type(joekoe_cms.now_time,11)
  p_order_true=true
  sql="select top 1 id from shop_orders 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 align=center height=150><font class=red>对不起，购买"&web_dim(44)&"的用户太多，请稍候再提交购买！</font></td></tr>" & _
         vbcrlf&"</table>"
  call shop_center_table(n_title,tmp1,1,3)
    exit sub
  end if
  
  sql="insert into shop_orders(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&"','"&joekoe_cms.now_time&"',0,'"&carry&"',"&carry_price&","&ispayment&","&ispay&")"
  call joekoe_cms.exec(sql,0)
  oid=first_id("shop_orders","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 joekoe_cms.int_true(n_num) then
      sql="select top 1 name,serial,price,discount,is_emoney,emoney from shop_product where hidden=1 and id="&pid
      set rs=joekoe_cms.exec(sql,1)
      if not rs.eof then
        n_name=joekoe_cms.code_form(rs("name"))
        n_serial=joekoe_cms.code_form(rs("serial"))
        n_price=rs("price")
        n_discount=rs("discount")
        ssum=ssum+fm_price(n_price*(n_discount/100),1)*n_num
        sql="insert into shop_oorders(oid,pid,serial,name,price,discount,num) " & _
            "values("&oid&","&pid&",'"&n_serial&"','"&n_name&"',"&n_price&","&n_discount&","&n_num&")"
        call joekoe_cms.exec(sql,0)
        call joekoe_cms.exec("update shop_product set buy_counter=buy_counter+1 where id="&pid,0)
      end if
      rs.close
    end if
  next
  erase sdim
  call joekoe_cms.exec("update shop_orders set prices="&ssum&" where id="&oid,0)
  response.cookies(joekoe_cms.web_cookies&"_shop")("bag_"&n_sort)=""
  tmp1=vbcrlf&"<table border=0>" & _
       vbcrlf&"<tr><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 height=50>请牢记您的订单号(<font class=red>"&ordernum&"</font>)，以便查询！</td></tr>" & _
       vbcrlf&"<tr><td align=center><input type=button class=btn value='继续购物' onClick=""javascript:window.location.href='index.asp';"">"
if int(ispayment)=1 then
  dim puser
  puser=login_username
  if login_mode="" then
    puser="_"&nname
  end if
  tmp1=tmp1&"　　<input type=button class=btn value='在线支付' onClick=""javascript:window.location.href='pay_shop.asp?type=other&ordernum="&ordernum&"'"">"


end if
  tmp1=tmp1&"</td></tr>" & _
       vbcrlf&"</table>"
  call shop_center_table(n_title,tmp1,1,3)
end sub

sub shop_pay_type()
 dim tmp1
tit=tit&"（填写收货信息）"  
 %>
<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&"<form name=shop_pay_frm action='?action=pay' method=post onsubmit=""javascript:frm_submitonce(this);"">" & _
       vbcrlf&"<input type=hidden name=chk value='yes'>" & _
	   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&"<select type=text name=payment>" & _
       vbcrlf&"<option value='onlinepay' class=red>在线支付 ☆推荐☆</option>" & _
       vbcrlf&"<option value='银行转帐'>银行转帐</option>" & _
       vbcrlf&"<option value='邮局汇款'>邮局汇款</option>" & _
       vbcrlf&"<option value='现金支付'>现金支付</option>" & _
       vbcrlf&"</select></td>" & _
       vbcrlf&"</tr>" & _
       vbcrlf&"<tr class=bg_td>" & _
       vbcrlf&"<td>运送方式：</td>" & _
       vbcrlf&"<td>" & _
       vbcrlf&"  <table border=0>"
  dim dim_carry,carry,carry_price
  carry="未设定"
  carry=0
  dim_carry=split(web_dim(48),":")
  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&" checked"
    tmp1=tmp1&" class=bg_td>"&carry&"（"
    if int(carry_price)=0 then
      tmp1=tmp1&"免费"
    else
      tmp1=tmp1&"加"&carry_price&web_dim(45)
    end if
    tmp1=tmp1&"）</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=trz><td colspan=2 align=center height=40><input type=button class=btn value='返回上一步' onclick=""javascript:window.history.go(-1);"">　　<input type=submit class=btn value='执行下一步' onclick=""javascript:return pay_frm_submit(this.form);""></td></tr>" & _
       vbcrlf&"</form>"
  call shop_center_table(tit,tmp1,1,1)
end sub

sub shop_pay_bag()
  dim tmp1,nid,nnum,price,price_now,discount,name,ds
  ssum=0
  ds=" disabled"
  sdim=split(shop_session,",")
  tmp1=vbcrlf&"<tr><td class=bg_td colspan=7 height=30 align=center><font class=red>以下是您所选购的"&web_dim(44)&"清单</font></td></tr>" & _
       vbcrlf&"<tr align=center>" & _
       vbcrlf&"<td width='7%' class=trs>序号</td>" & _
       vbcrlf&"<td width='38%' class=trs>"&web_dim(44)&"名称</td>" & _
       vbcrlf&"<td width='9%' class=trs>数量</td>" & _
       vbcrlf&"<td width='13%' class=trs>原价("&web_dim(45)&")</td>" & _
       vbcrlf&"<td width='8%' class=trs>折扣</td>" & _
       vbcrlf&"<td width='13%' class=trs>现价("&web_dim(45)&")</td>" & _
       vbcrlf&"<td width='12%' class=trs>"&web_dim(9)&"支付</td>" & _
       vbcrlf&"</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 joekoe_cms.int_true(nnum) then
      sql="select top 1 name,serial,price,discount,is_emoney,emoney from shop_product where hidden=1 and id="&nid
      set rs=joekoe_cms.exec(sql,1)
      if not rs.eof then
        name=joekoe_cms.code_html(rs("name"),1,0)
        price=fm_price(rs("price"),1)
        discount=rs("discount")
        price_now=fm_price(price*(discount/100),1)
        discount=fm_discount(discount)
        ssum=ssum+price_now*nnum
        tmp1=tmp1&vbcrlf&"<tr class=bg_td align=center>" & _
             vbcrlf&"<td>"&i+1&"</td>" & _
             vbcrlf&"<td align=left><a href='###' alt='"&web_dim(44)&"编号："&rs("serial")&"<br>点击浏览"&web_dim(44)&"详细信息' onclick=""javascript:open_view('view.asp?id="&nid&"',1);"">"&name&"</a></td>" & _
             vbcrlf&"<td>"&nnum&"</td>" & _
             vbcrlf&"<td align=right>"&price&"</td>" & _
             vbcrlf&"<td>"
        if discount=fm_discount(100) then
          tmp1=tmp1&"<font class=gray>"&discount&"</font>"
        else
          tmp1=tmp1&"<font class=red2>"&discount&"</font>"
        end if
        tmp1=tmp1&"</td>" & _
             vbcrlf&"<td align=right><font class=blue>"&price_now&"</font></td>" & _
             vbcrlf&"<td>"
        if rs("is_emoney") then
          tmp1=tmp1&rs("emoney")
        else
          tmp1=tmp1&"<font class=gray>不可用</font>"
        end if
        tmp1=tmp1&"</td>" & _
             vbcrlf&"</tr>"
        ds=""
      end if
      rs.close
    end if
  next
  tmp1=tmp1&vbcrlf&"<tr class=trz><td colspan=7 height=30 align=right>"
  if ds="" then
    tmp1=tmp1&"您所选购的"&web_dim(44)&"总的有效金额：<font class=red>"&fm_price(ssum,1)&"</font>&nbsp;"&web_dim(45)
  else
    tmp1=tmp1&"您目前还没有选购"&web_dim(44)
  end if
  tmp1=tmp1&vbcrlf&"&nbsp;</td></tr>"
  erase sdim
  call shop_center_table(tit,tmp1,1,1)
end sub
%>