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

dim types
types=trim(request.querystring("types"))
if cstr(types)<>"1" and cstr(types)<>"5" then types="0"
if AsaiMHMod="all" then types=""
Index_Url="shop"
call AMH_master(1,0)
Data_Name="AsaiMHShopEmoneyNotes"
tit_fir="订单"
tit="订单管理"
call AMH_header(1)
dim Web_Shop
Call Cls.Channel_Initialize(3)
Web_Shop=split(Cls.ChannelOption,"|")
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?types=0'<%if cstr(types)="0" then Response.Write " class=red"%>>未处理的<%Response.Write Cls.web_unit&"支付"&tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?types=1'<%if cstr(types)="1" then Response.Write " class=red"%>>有问题的<%Response.Write Cls.web_unit&"支付"&tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?types=5'<%if cstr(types)="5" then Response.Write " class=red"%>>已处理的<%Response.Write Cls.web_unit&"支付"&tit_fir%></a></td>
  <td width=10></td>
  <td><a href='AMH_shop_order.asp'>一般支付<%Response.Write tit_fir%></a></td>
  </tr>
  </table>
</td></tr>
<tr><td colspan=2 align=center>
  <table border=0 cellspacing=0 cellpadding=2>
  <form action='?' method=get>
  <input type=hidden name=AsaiMHMod value='search'>
  <tr>
  <td>搜索（<%Response.Write tit_fir%>） 关键字：</td>
  <td><input type=text name=keyword value='<%Response.Write trim(request.querystring("keyword"))%>' size=15 maxlength=20></td>
  <td><select name=sea_type size=1>
<option value='ordernum'>按订单号</option>
<option value='username'>按注册用户</option>
<option value='nname'>按真实姓名</option>
</select></td>
  <td><select name=sea_term size=1><option value='all'>满足所有条件</option><option value='only'>满足一个条件</option></seelct></td>
  <td><input type=submit value='搜索' class=btn></td>
  </tr>
  </form>
  </table>
</td></tr>
</table>
<%
call AMH_table(1)
if action="handle" then call AsaiMHChk_Handle()
select case action
case "view"
  call AsaiMHChk_View()
case else
  call AsaiMHChk_Main()
end select
Call AMH_Ender(tit)

sub AsaiMHChk_Handle()
  dim sel_type,seltype,sel_id,hdim,hnum,hid,hi,htype,hintegral
  htype=1
  sel_type=trim(request.form("sel_type"))
  select case sel_type
  case "删除"
    seltype="delete"
  case else
    sel_type=""
    seltype=""
  end select
  if Cls.post_chk()=false or seltype="" then
    exit sub
  end if
  hintegral=mp_integral()
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id," ","")
  hdim=split(sel_id,",")
  hnum=ubound(hdim)
  select case seltype
  case "delete"
    for hi=0 to hnum
      hid=hdim(hi)
      if isnumeric(hid) then
        call Cls.exec("delete from "&Data_Name&" where id="&hid,0)
      end if
    next
  end select
  erase hdim
  action=""
  call AMH_msg("已成功删除了"&(hnum+1)&"条"&tit_fir,pageurl,1)
end sub

sub AsaiMHChk_View()
  dim username,carry_price,ordernum,dis_remark,ntypes,accept_u,msgs,msg_topic,msg_word,pid,name,serial,num,emoney,ptim,emoneys,ptypes,dis_tims
  sql="select top 1 * from "&Data_Name&" where id="&id
  set rs=Cls.exec(sql,1)
  if rs.eof then
    rs.close
    call AMH_msg(tit_fir&"（ID："&ordernum&"）不存在！","?",1)
    exit sub
  end if
  username=rs("username")
  carry_price=rs("carry_price")
  ordernum=rs("ordernum")
  pid=rs("pid")
  name=rs("name")
  serial=rs("serial")
  num=rs("num")
  emoney=rs("emoney")
  ptim=rs("tim")
  emoneys=rs("emoneys")
  ptypes=rs("types")
  dis_tims=rs("dis_tim")
  call AMH_td("浏览"&tit_fir&"（"&ordernum&"）")
  if chk() then
    accept_u=rs("username")
    rs.close
    ntypes=trim(request.form("types"))
    if dis_tims="" then
    	if cstr(ntypes)="1" and ptypes<>"1" then
		Call Cls.exec("update "&Cls.ChannelTable&" set stocks=stocks-"&num&" where id="&pid,0)
    	end if
	if cstr(ntypes)="5" and ptypes<>"5" then
		Call Cls.exec("update "&Cls.ChannelTable&" set stocks=stocks-"&num&" where id="&pid,0)
	end if
    else
   	if cstr(ntypes)="0" and ptypes<>"0" then
		Call Cls.exec("update "&Cls.ChannelTable&" set stocks=stocks+"&num&" where id="&pid,0)
    	end if
   	if cstr(ntypes)="1" and ptypes="0" then
		Call Cls.exec("update "&Cls.ChannelTable&" set stocks=stocks-"&num&" where id="&pid,0)
    	end if
	if cstr(ntypes)="5" and ptypes="0" then
		Call Cls.exec("update "&Cls.ChannelTable&" set stocks=stocks-"&num&" where id="&pid,0)
	end if
    end if
    if cstr(ntypes)<>"1" and cstr(ntypes)<>"5" then ntypes=0
    dis_remark=Cls.Code_Admin("dis_remark",1,250)
    if dis_tims="" and ntypes=0 then
    	sql="update "&Data_Name&" set types="&ntypes&",dis_tim='',dis_remark='"&dis_remark&"' where id="&id
    else
    	sql="update "&Data_Name&" set types="&ntypes&",dis_tim='"&Cls.now_time&"',dis_remark='"&dis_remark&"' where id="&id
    end if
    call Cls.exec(sql,0)
    msg_topic=Cls.Code_Admin("msg_topic",1,0)
    msg_word=Cls.Code_Admin("msg_word",1,250)
    if trim(request.form("messages"))="yes" and len(msg_topic)>1 and len(msg_word)>1 then
      sql="insert into AsaiMHusermail(send_u,accept_u,topic,word,tim,types,isread) " & _
	    "values('"&login_username&"','"&accept_u&"','"&msg_topic&"','"&msg_word&"','"&Cls.now_time&"',1,0)"
      call Cls.exec(sql,0)
      msgs="\n\n已给会员（"&accept_u&"）发送了一封站内短信！"
    end if
    call AMH_msg("成功处理了订单（"&ordernum&"，ID："&id&"）！"&msgs,"?types="&types&"&AsaiMHMod="&AsaiMHMod,1)
    exit sub
  end if
  call form_first()
%>
<tr>
<td><%Response.Write Web_Shop(0)%>名称：</td>
<td><a href='<%Response.Write Cls.Web_Dir&Cls.ChannelDir%>/View.asp?id=<%Response.Write pid%>' class=blue alt='点击浏览<%Response.Write Web_Shop(0)%>详细信息' onclick="javascript:open_view('shop_view.asp?id=<%Response.Write pid%>',1);" target=_blank><b><%Response.Write name%></b></a></td>
</tr>
<tr>
<td><%Response.Write Web_Shop(0)%>编号：</td>
<td><%Response.Write rs("serial")%></td>
</tr>
<tr>
<td><%Response.Write Web_Shop(0)%>单价：</td>
<td><font class=red2><%Response.Write emoney%></font> <%Response.Write Cls.web_unit%>　　购买数量：<font class=red><%Response.Write num%></font></td>
</tr>
<tr>
<td>运送方式：</td>
<td><%Response.Write rs("carry")%>&nbsp;（<%
  if int(carry_price)>0 then
    Response.Write "加"&carry_price&Cls.web_unit
  else
    Response.Write "免费"
  end if
%>）</td>
</tr>
<tr>
<td>订单总<%Response.Write Cls.web_unit%>：</td>
<td><font class=red><%Response.Write fm_price(rs("emoneys"),1)%></font>&nbsp;<%Response.Write Cls.web_unit%></td>
</tr>
<tr>
<td>购买时间：</td>
<td><%Response.Write Cls.time_type(ptim,2)%></td>
</tr>
<tr>
<td>收货人姓名：</td>
<td><%
  Response.Write rs("nname")
  Response.Write "　会员："&format_user_view(rs("username"),1,0)
%></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>
  <table border=0 width='100%' class=tf>
  <tr><td class=bw><%Response.Write Cls.Code_Html(rs("remark"),2,0)%></td></tr>
  </table>
</td>
</tr>
<form action='?action=view&AsaiMHMod=<%Response.Write AsaiMHMod%>&id=<%Response.Write id%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td>订单类型：</td>
<td><select name=types>
<option value='0'<%if cstr(types)="0" then Response.Write " selected"%>>未处理订单</option>
<option value='1'<%if cstr(types)="1" then Response.Write " selected"%>>有问题订单</option>
<option value='5'<%if cstr(types)="5" then Response.Write " selected"%>>已处理订单</option>
</select>&nbsp;&nbsp;上次处理时间：<%Response.Write rs("dis_tim")%>&nbsp;&nbsp;&nbsp;&nbsp;<%Call AMH_Read("","处理注意事项","第一次处理订单将自动减去相应商品数，处理过后在选择未处理将加上相应商品数。")%></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>
<tr class=tr1>
<td>发送短信：</td>
<td><input type=checkbox name=messages value='yes'>&nbsp;选上为处理订单时发送一封站内短信给该会员，在下面填写短信内容</td>
</tr>
<tr class=tr1>
<td>短信标题：</td>
<td><input type=text name=msg_topic value='系统：<%Response.Write tit_fir&ordernum%>' size=40 maxlength=20><%Response.Write redx%>不能超过20个字</td>
</tr>
<tr class=tr1>
<td valign=top><br />短信内容：<br /><=250</td>
<td><textarea name=msg_word cols=50 rows=5></textarea></td>
</tr>
<tr class=tr1><td colspan=2 align=center height=30><input type=submit value='处理该订单'>　　　<input type=reset value='重新填写'></td></tr>
</form>
<%
  rs.close
end sub

sub AsaiMHChk_Main()
  dim n_id,n_ordernum,n_tim
%>
<form name=sel_form action='?AsaiMHMod=<%Response.Write AsaiMHMod%>&types=<%Response.Write types%>&action=handle' method=post>
<tr align=center>
<td class=td width='6%'>序号</td>
<td class=td width='23%'>订 单 号</td>
<td class=td width='15%'>收货人</td>
<td class=td width='16%'>订购时间</td>
<td class=td width='12%'>订购单价</td>
<td class=td width='12%'>订购数量</td>
<td class=td width='10%'>总<%Response.Write Cls.web_unit%></td>
<td class=td width='6%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
</tr>
<%
  if AsaiMHMod="search" then
    call format_search("ordernum","ordernum,username,nname",2,1)
  else
    if types<>"" then
     sql_add=" types="&types
     pageurl=pageurl&"types="&types&"&"
    end if
  end if
  dim obj_page
  set obj_page=new Cls_PageCute
  obj_page.pageurl=pageurl			
  obj_page.nummer=nummer						
  obj_page.page_t=1									
  obj_page.page_p=5									
  obj_page.page_unit="条"
  obj_page.page_tit=tit_fir
  obj_page.v_id="id"
  call obj_page.p_init("*",Data_Name,sql_add,"id desc")
  sql=obj_page.sql_count
  set rs=Cls.exec(sql,1)
  obj_page.rssum=rs(0)
  rs.close
  call obj_page.p_main("*",Data_Name,sql_add,"id desc")
  for i=1 to obj_page.page_num
    id=rs("id")
    n_ordernum=rs("ordernum")
    n_tim=rs("tim")
%>
<tr align=center>
<td><%Response.Write obj_page.page_now+i%></td>
<td align=left><a href='?action=view&types=<%Response.Write types%>&AsaiMHMod=<%Response.Write AsaiMHMod%>&id=<%Response.Write id%>'><%Response.Write n_ordernum%></a></td>
<td align=left><%Response.Write format_user_view(rs("username"),1,0)%></td>
<td><font alt='<%Response.Write Cls.time_type(n_tim,2)%>' class=tims><%Response.Write Cls.time_type(n_tim,3)%></td>
<td align=right><%Response.Write fm_price(rs("emoney"),1)%></td>
<td align=right><%Response.Write rs("num")%></td>
<td align=right><%Response.Write fm_price(rs("emoneys"),1)%></td>
<td><input type=checkbox name=sel_id value='<%Response.Write id%>'></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=tr1>
<td colspan=5>
  <table border=0>
  <tr class=tr1>
  <td></td>
  <td><%Response.Write obj_page.page_var%></td>
  <td width=3></td>
  <td>分页：</td>
  <td><%Response.Write obj_page.page_cute%></td>
  </tr>
  </table>
</td>
<td colspan=3 align=center>
<select name=sel_type size=1>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);" class=btn>
</td>
</tr>
</form>
<%
end sub
%>
