<!-- #include file="include/onlogin.asp" -->
<!-- #include file="include/conn.asp" -->
<!-- #INCLUDE file="include/jk_page_cute.asp" -->
<%
dim nid,id,types,oname,rssum,nummer,thepages,viewpage,pageurl,page,pu
tit="<a href='admin_order.asp?types=0'>未处理订单</a>┋ " & _
    "<a href='admin_order.asp?types=1'>有问题订单</a> ┋ " & _
    "<a href='admin_order.asp?types=5'>已处理订单</a>"

response.write header(18,tit)
nummer=15:thepages=0:viewpage=1
pu="￥"

action=trim(request.querystring("action"))
id=trim(request.querystring("id"))
types=trim(request.querystring("types"))
if not(isnumeric(types)) then types=0
select case types
case 1
  oname="有问题订单"
case 5
  oname="已处理订单"
case else
  types=0:oname="未处理订单"
end select

if action="del" and isnumeric(id) then
  sql="delete from orders where id="&id
  conn.execute(sql)
  sql="delete from oorders where oid="&id
  conn.execute(sql)
  response.write "<script language=javascript>alert(""已成功删了一条订单！\n\n订单号："&id&""");</script>"
end if

select case action
case "view"
  call order_view()
case else
  call order_main()
end select

response.write ender()

sub order_view()
  dim isuser,sum,price,num,prices,accept_u,msg_topic,msg_word,msgs:num=0:msgs=""
  sql="select * from orders where id="&id
  if trim(request.form("view"))="yes" then
    set rs=server.createobject("adodb.recordset")
    response.write sql
    rs.open sql,conn,1,3
    if rs.eof and rs.bof then
      rs.close
      call order_main():exit sub
    end if
    accept_u=rs("username"):isuser=rs("isuser")
    types=trim(request.form("types"))
    if not(isnumeric(types)) then types=0
    types=int(types)
    if types<>1 and types<>5 then types=0
    rs("types")=types
    rs("dis_tim")=now_time
    rs("dis_remark")=left(request.form("dis_remark"),250)
    rs.update
    rs.close
    if isuser=true then
      msg_topic=replace(request.form("msg_topic"),"'","""")
      msg_word=left(replace(request.form("msg_word"),"'",""""),250)
      if trim(request.form("messages"))="yes" and len(msg_topic)>1 and len(msg_word)>1 then
        msgs="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
	     "values('"&login_username&"','"&accept_u&"','"&msg_topic&"','"&msg_word&"','"&now_time&"',1,0)"
	conn.execute(msgs)
	msgs="\n\n已给会员（"&accept_u&"）发送了一封站内短信！"
      end if
    end if
    response.write "<script javascript>alert(""成功处理了订单！订单号："&id&msgs&""");</script>"
  end if
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then
    rs.close
    call order_main():exit sub
  end if
%>
<table border=1 width=500 cellspacing=0 cellpadding=1 bordercolorlight=#C0C0C0 bordercolordark=#ffffff>
<form action='?action=view&types=<%response.write types%>&id=<%response.write id%>' method=post>
<input type=hidden name=view value='yes'>
<tr><td colspan=2 align=center bgcolor=#ffffff class=red>处理订单　　订单号：<b><%response.write rs("ordernum")%></b></td></tr>
<tr><td>收货人姓名：</td><td><%
response.write rs("nname")
isuser=rs("isuser")
if isuser=true then response.write "　<font class=red>（会员："&format_user_view(rs("username"),1,"")&"）</font>"%></td></tr>
<tr><td>收货人地址：</td><td><%response.write rs("address")%></td></tr>
<tr><td>邮政编码：</td><td><%response.write rs("code")%></td></tr>
<tr><td>联系电话：</td><td><%response.write rs("phone")%></td></tr>
<tr><td>电子信箱：</td><td><%response.write rs("email")%></td></tr>
<tr><td>付款方式：</td><td><%response.write rs("payment")%></td></tr>
<tr><td>订购时间：</td><td><%response.write rs("tim")%></td></tr>
<tr><td valign=top>备注信息：</td><td><pre><%response.write rs("remark")%></td></tr>
<tr><td>订单类型：</td><td><select name=types>
<option value='0'<%if int(types)=0 then response.write " selected"%>>未处理订单</option>
<option value='1'<%if int(types)=1 then response.write " selected"%>>有问题订单</option>
<option value='5'<%if int(types)=5 then response.write " selected"%>>已处理订单</option>
</select>&nbsp;&nbsp;&nbsp;&nbsp;上次处理时间：<%response.write rs("dis_tim")%></td></tr>
<tr><td valign=top><br>处理信息：<br><=250</td><td><textarea name=dis_remark cols=50 rows=5><%response.write rs("dis_remark")%></textarea></td></tr>
<%if isuser=true then%>
<tr><td>发送短信：</td><td>&nbsp;<input type=checkbox name=messages value='yes'>&nbsp;选上为处理订单时发送一封站内短信给该会员，在下面填写短信内容</td></tr>
<tr><td>短信标题：</td><td><input type=text name=msg_topic size=40 maxlength=20><%response.write redx%>不能超过20个字</td></tr>
<tr><td valign=top><br>短信内容：<br><=250</td><td><textarea name=msg_word cols=50 rows=5></textarea></td></tr>
<%end if%>
<tr><td colspan=2 align=center height=30><input type=submit value='处理该订单'>　　　<input type=reset value='重新填写'></td></tr>
</form>
</table>
<br>
<table border=1 width='100%' cellspacing=0 cellpadding=1 bordercolorlight=#C0C0C0 bordercolordark=#ffffff>
<tr height=22 align=center bgcolor=#ffffff>
<td width='8%'>商品ID</td>
<td width='22%'>商品编号</td>
<td width='35%'>商品名称</td>
<td width='12%'>商品单价</td>
<td width='11%'>商品数量</td>
<td width='12%'>商品总价</td>
</tr>
<%
  sql="select * from oorders where oid="&id&" order by id"
  set rs=conn.execute(sql)
  do while not rs.eof
    nid=rs("pid"):price=rs("price"):num=rs("num")
    prices=price*num
    sum=sum+prices
%>
<tr align=center>
<td><%response.write nid%></td>
<td><%response.write rs("serial")%></td>
<td><a href='shop_view.asp?id=<%response.write nid%>' title='浏览该商品信息' target=_blank><%response.write rs("name")%></a></td>
<td><%response.write pu&price%></td>
<td><%response.write num%></td>
<td><%response.write pu&prices%></td>
</tr>
<%
    rs.movenext
  loop
  rs.close
  set rs=nothing
%>
<tr><td colspan=6 align=right class=red>总价格：<%response.write pu&sum%>&nbsp;&nbsp;&nbsp;</td></tr>
</table>
<%
end sub

sub order_main()
  dim sqladd,sea_type,keyword:sqladd=""
  pageurl="?action="&action&"&types="&types&"&"
  sea_type=trim(request.querystring("sea_type"))
  keyword=replace(trim(request.querystring("keyword")),"'","")
  if len(keyword)>1 then
    select case sea_type
    case "ordernum"
      sqladd=" and ordernum like '%"&keyword&"%'"
    case "name"
      sqladd=" and (username like '%"&keyword&"%' or nname like '%"&keyword&"%')"
    case "payment"
      sqladd=" and payment like '%"&keyword&"%'"
    end select
    pageurl=pageurl&"sea_type="&sea_type&"&keyword="&keyword&"&"
  end if
  sql="select id,ordernum,isuser,username,nname,payment,tim from orders where types="&types&sqladd&" order by id desc"
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,1
  if rs.eof and rs.bof then
    rssum=0
  else
    rssum=rs.recordcount
  end if
  call format_pagecute()
%>
<script language=JavaScript>
<!--
function Do_del_data(data1)
{
if (confirm("此操作将删除id为 "+data1+" 的订单！\n真的要删除吗？\n删除后将无法恢复！"))
  window.location="?action=del&types=<%response.write types%>&id="+data1
}
//--></script>
<table border=1 width='98%' cellspacing=0 cellpadding=1 bordercolorlight=#C0C0C0 bordercolordark=#ffffff>
<tr><td colspan=5 align=center height=30>现在有 <font class=red><%response.write rssum%></font> 个 <font class=red_3><%response.write oname%></font>　　每页 <font class=red><%response.write nummer%></font> 个</td></tr>
<tr align=center bgcolor=#ffffff>
<td width='16%'>订单号</td>
<td width='23%'>收货人帐号</td>
<td width='23%'>收货人姓名</td>
<td width='24%'>付款方式</td>
<td width='14%'>操作</td>
</tr>
<%
  if int(viewpage)<>1 then
    rs.move (viewpage-1)*nummer
  end if
  for i=1 to nummer
    if rs.eof then exit for
    nid=rs("id")
%>
<tr align=center>
<td><%response.write rs("ordernum")%></td>
<td><%
if rs("isuser")=true then
  response.write format_user_view(rs("username"),1,"")
else
  response.write "非会员"
end if
%></td>
<td><%response.write rs("nname")%></td>
<td><%response.write rs("payment")%></td>
<td><a href='?action=view&types=<%response.write types%>&id=<%response.write nid%>'>详细</a> 
<a href="javascript:Do_del_data('<%response.write nid%>');">删除</a></td>
</tr>
<%
    rs.movenext
  next
  rs.close:set rs=nothing
%>
<tr align=center><td colspan=5>
  <table border=0 width='100%'>
  <tr align=center><td><%response.write pagecute_fun(viewpage,thepages,pageurl)%></td><td>
<table border=0>
<form action='?' method=get>
<input type=hidden name=action value='main'>
<input type=hidden name=types value='<%response.write types%>'>
<tr><td>关键字：<input type=text name=keyword size=10 maxlength=20></td><td>&nbsp;<select name=sea_type>
<option value='ordernum'>订单号</option>
<option value='name'>收货人</option>
<option value='payment'>付款方式</option>
</select></td><td>&nbsp;<input type=submit value='搜索'></td></tr>
</form>
</table>
  </td>  </tr>
</table>
</td></tr>
</table>
<%
end sub
%>