<!-- #include file="include/config_shop.asp" -->
<%
dim shop_session
shop_session=trim(request.cookies(web_cookies)("shop"))
if len(shop_session)<1 then
  response.redirect "shop.asp"
  response.end
end if
%>
<!-- #include file="include/conn.asp" -->
<%
if login_username="" then
  set rs=nothing
  call close_conn()
  response.redirect "login.asp"
  response.end
end if
dim pid,num,sum,sdim,snum,tid,tnum,tprice,tprices
tit="收 银 台"

call web_head(0,0,0,0,0)
'------------------------------------left----------------------------------
call format_login()
call shop_sort()
call shop_left()
'----------------------------------left end--------------------------------
call web_center(0)
'-----------------------------------center---------------------------------
response.write ukong

select case action
case "step_2"
  call pay_2()
case "step_3"
  call pay_3()
case else
  call pay_1()
end select

response.write ukong
'---------------------------------center end-------------------------------
call web_end(0)

sub pay_3()
  dim nname,address,code,phone,email,payment,remark,isuser,oid,ordernum
  nname=code_form(request.form("nname"))
  address=code_form(request.form("address"))
  code=code_form(request.form("code"))
  phone=code_form(request.form("phone"))
  email=code_form(request.form("email"))
  payment=code_form(request.form("payment"))
  remark=code_form(request.form("remark"))
  isuser=1
  if login_mode="" then
    isuser=0:login_username=""
  end if
  sql="insert into orders(isuser,username,nname,address,code,phone,email,payment,remark,tim,types) " & _
      "values("&isuser&",'"&login_username&"','"&nname&"','"&address&"','"&code&"','"&phone&"','"&email&"','"&payment&"','"&remark&"','"&now_time&"',0)"
  conn.execute(sql)
  sql="select top 1 id from orders where types=0 order by id desc"
  set rs=conn.execute(sql)
  oid=rs(0)
  rs.close
  
  ordernum=rand_num(10-1-len(oid))&"0"&oid
  conn.execute("update orders set ordernum='"&ordernum&"' where id="&oid)
  
  sum=0
  sdim=split(shop_session,"#")
  snum=ubound(sdim)
  for i=0 to snum
    tid=left(sdim(i),instr(sdim(i),",")-1)
    tnum=right(sdim(i),len(sdim(i))-instr(sdim(i),","))
    sql="select serial,name,price_1,price_2 from product where hidden=1 and id="&tid
    set rs=conn.execute(sql)
    if not(rs.eof and rs.bof) then
      if login_mode="" then
        tprice=rs("price_1")
      else
        tprice=rs("price_2")
      end if
      tprices=tprice*tnum
      sum=sum+tprices
      sql="insert into oorders(oid,pid,serial,name,price,num) values("&oid&","&tid&",'"&rs("serial")&"','"&rs("name")&"',"&tprice&","&tnum&")"
      conn.execute(sql)
      conn.execute("update product set buy_counter=buy_counter+1 where id="&tid)
    end if
    rs.close:set rs=nothing
  next
  erase sdim
  
  response.cookies(web_cookies)("shop")=""
  if request.cookies(web_cookies)("iscookies")="yes" then
    response.cookies(web_cookies).expires=date+365
  end if
  
  response.write table1
%>
<tr<%response.write table2%>><td colspan=2 height=25 align=center class=end><b>购物结算　　（第三步）订购成功！请牢记您的订单号</b></td></tr>
<tr<%response.write table3%>><td align=center height=100>订单已经成功递交！订单号为：<font size=5 class=red><b><%response.write ordernum%></b></font></td></tr>
<tr<%response.write table3%>><td align=center height=50>收到您的货款后，我们将按您的订单发货。请牢记您的订单号(<font class=red><%response.write ordernum%></font>)，以便查询！</td></tr>
<tr<%response.write table2%>><td align=center height=30><input type=button value='继续购物' onClick="window.location='shop.asp';"></td></tr>
</table>
<%
end sub

sub pay_2()
  response.write table1
%>
<tr<%response.write table3%> align=center><td class=red height=30 colspan=6>以下是您所选购的物品清单</td></tr>
<tr height=22<%response.write table2%> align=center>
<td width='23%' class=end><b>产品编号</td>
<td width='39%' class=end><b>产品名称</td>
<td width='13%' class=end><b>产品单价</td>
<td width='12%' class=end><b>产品数量</td>
<td width='13%' class=end><b>产品总价</td>
</tr>
<%
  sum=0
  sdim=split(shop_session,"#")
  snum=ubound(sdim)
  for i=0 to snum
    tid=left(sdim(i),instr(sdim(i),",")-1)
    tnum=right(sdim(i),len(sdim(i))-instr(sdim(i),","))
    sql="select serial,name,price_1,price_2 from product where hidden=1 and id="&tid
    set rs=conn.execute(sql)
    if not(rs.eof and rs.bof) then
      if login_mode="" then
        tprice=rs("price_1")
      else
        tprice=rs("price_2")
      end if
      tprices=tprice*tnum
      sum=sum+tprices
%>
<tr align=center<%response.write table3%>> 
<td><%response.write rs("serial")%></td>
<td><%response.write rs("name")%></td>
<td><%response.write tprice&pu%></td>
<td><%response.write tnum%></td>
<td><%response.write tprices&pu%></td>
</tr>
<%
    end if
    rs.close:set rs=nothing
  next
  erase sdim
%>
<tr<%response.write table4%>><td align=right colspan=6 height=25 class=red>总价格:&nbsp;<%response.write sum&pu%>&nbsp;&nbsp;</td></tr>
</table>
<br>
<% response.write table1 %>
<form name=pay_frm action='?action=step_3' method=post>
<tr<%response.write table2%>><td colspan=2 height=25 align=center class=end><b>购物结算　　（第二步）收货人信息确认</b></td></tr>
<tr<%response.write table3%>><td width='20%'>收货人姓名：</td><td width='80%'><input type=hidden name=nname readonly value='<%response.write code_form(request.form("nname"))%>'><%response.write code_form(request.form("nname"))%><%if login_mode<>"" then response.write "　<font class=red>（会员："&login_username&"）</font>"%></td></tr>
<tr<%response.write table3%>><td>收货人地址：</td><td><input type=hidden name=address value='<%response.write code_form(request.form("address"))%>'><%response.write code_form(request.form("address"))%></td></tr>
<tr<%response.write table3%>><td>邮政编码：</td><td><input type=hidden name=code value='<%response.write code_form(request.form("code"))%>'><%response.write code_form(request.form("code"))%></td></tr>
<tr<%response.write table3%>><td>联系电话：</td><td><input type=hidden name=phone value='<%response.write code_form(request.form("phone"))%>'><%response.write code_form(request.form("phone"))%></td></tr>
<tr<%response.write table3%>><td>电子信箱：</td><td><input type=hidden name=email value='<%response.write code_form(request.form("email"))%>'><%response.write code_form(request.form("email"))%></td></tr>
<tr<%response.write table3%>><td>付款方式：</td><td><input type=hidden name=payment value='<%response.write code_form(request.form("payment"))%>'><%response.write code_form(request.form("payment"))%></td></tr>
<tr<%response.write table3%>><td valign=top><br>备注信息：</td><td><input type=hidden name=remark value='<%response.write code_form(request.form("remark"))%>'><pre><%response.write code_form(request.form("remark"))%></td></tr>
<tr<%response.write table3%>><td colspan=2 align=center height=30 class=red>您可以点击“上一步”返回修改以上内容</td></tr>
<tr<%response.write table2%>><td colspan=2 align=center height=30> <input type=button value='上一步' onclick="javascript:window.history.go(-1);">　　<input type=submit value='信息正确！提交订单'></td></tr>
</form>
</table>
<%
end sub

sub pay_1()
%>
<SCRIPT language=javascript>
<!--
function pay_frm_submit()
{
  if (pay_frm.nname.value.length==0)
  {
    alert("请输入收货人姓名！");
    return false;
  }
  if (pay_frm.address.value.length==0)
  {
    alert("请输入收货人具体地址！");
    return false;
  }
  if (pay_frm.code.value.length==0)
  {
    alert("请输入邮政编码！");
    return false;
  }
  if (pay_frm.phone.value.length==0)
  {
    alert("请输入联系电话！");
    return false;
  }
  if (pay_frm.email.value.length==0)
  {
    alert("请输入电子邮件！");
    return false;
  }
}
-->
</SCRIPT>
<%response.write table1%>
<form name=pay_frm action='?action=step_2' method=post>
<tr<%response.write table2%>><td colspan=2 height=25 align=center class=end><b>购物结算　　（第一步）填写收货人信息</b></td>
</tr>
<tr<%response.write table3%>><td>收货人姓名：</td><td><input type=text name=nname value='<%response.write login_username%>' readonly size=20 maxLength=20><%if login_mode<>"" then response.write "　<font class=red>（会员："&login_username&"）</font>"%></td></tr>
<tr<%response.write table3%>><td>收货人地址：</td><td><input type=text name=address size=50 maxLength=200></td></tr>
<tr<%response.write table3%>><td>邮政编码：</td><td><input type=text name=code size=15 maxLength=6></td></tr>
<tr<%response.write table3%>><td>联系电话：</td><td><input type=text name=phone size=30 maxLength=20></td></tr>
<tr<%response.write table3%>><td>电子信箱：</td><td><input type=text name=email size=30 maxLength=50></td></tr>
<tr<%response.write table3%>><td>付款方式：</td><td><select type=text name=payment>
<option>通过邮局汇款</option>   
<option>现金支付，上门提货</option>   
<option>银行转帐</option>       
<option>招行一卡通支付</option>
<option>电汇支付</option>
</select></td></tr>
<tr<%response.write table3%>><td valign=top><br>备注信息：<br><=250</td><td><textarea name=remark cols=50 rows=5></textarea></td></tr>
<tr<%response.write table3%>><td colspan=2 align=center height=30 class=red>您可以修改以上内容</td></tr>
<tr<%response.write table2%>><td colspan=2 align=center height=30> <input type=button value='上一步' onclick="javascript:window.history.go(-1);">　　<input type=submit value='下一步' onclick="return pay_frm_submit(pay_frm)"></td></tr>
</form>
</table>
<%
end sub
%>