<!-- #include file="include/admin_onlogin.asp" -->
<%
dim tim,nid,card_max_num
card_max_num=1000
index_url="notes"
call admin_master(0,0)
call admin_header(0,0)
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?'><%response.write tit%></a></td>
  <td width=10></td>
  <td><a href='?jk_mod=emoney'<%if jk_mod="emoney" then response.write " class=red"%>>购买<%response.write joekoe_cms.web_unit&tit_fir%></a></td>
  <td width=10></td>
  <td><a href='?jk_mod=card'<%if jk_mod="card" then response.write " class=red"%>>会员卡管理</a></td>
  </tr>
  </table>
</td></tr>
</table>
<%
call admin_table(1,1)

select case jk_mod
case "card"
  call admin_td("会员卡管理")
%>
<tr align=center valign=top>
<td>
  <table border=0>
  <tr><td><%response.write img_admin("","")%>&nbsp;<a href='?jk_mod=<%response.write jk_mod%>'>会员卡列表</a></td></tr>
  <tr><td><%response.write img_admin("","")%>&nbsp;<a href='?jk_mod=<%response.write jk_mod%>&action=add'<%if action="add" then response.write " class=red"%>>添加会员卡</a></td></tr>
  </table>
</td>
<td>
  <table cellspacing=1 cellpadding=3 class=table0>
<%
  select case action
  case "delete"
    call joekoe_chk_card_delete()
  case "edit"
    call joekoe_chk_card_edit()
  case "add"
    call joekoe_chk_card_add()
  case else
    call joekoe_chk_card()
  end select
%>
  </table>
</td>
</tr>
<%
case "emoney"
  call joekoe_chk_emoney()
case else
  call joekoe_chk_main()
end select

call admin_ender(1)

sub joekoe_chk_card_delete()
  dim sel_ids,sdim,snum
  sel_ids=trim(request.form("sel_id"))
  sel_ids=replace(sel_ids," ","")
  sdim=split(sel_ids,",")
  snum=ubound(sdim)
  for i=0 to snum
    if isnumeric(sdim(i)) then
      call joekoe_cms.exec("delete from cards where c_id="&sdim(i),0)
    end if
  next
  erase sdim
  call admin_msg("已成功删除 "&snum&" 条会员卡信息！","?jk_mod="&jk_mod,1)
end sub

sub joekoe_chk_card_edit()
  dim c_name,c_pass,c_emoney,c_hidden
  call admin_td("修改会员卡")
  sql="select top 1 * from cards where c_id="&id
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,3
  if rs.eof then
    call admin_msg("会员卡ID（"&id&"）不存在！","?jk_mod="&jk_mod,1)
    rs.close
  end if
  if chk() then
    c_name=code_admin("c_name",1,10)
    c_pass=code_admin("c_pass",1,10)
    c_emoney=code_admin("c_emoney",1,10)
    if not int_true(c_emoney) then c_emoney=0
    c_hidden=0
    if trim(request.form("c_hidden"))="yes" then c_hidden=1
    if c_name="" or c_pass="" then
      call admin_error("会员卡的 卡号和密码 不能为空！")
      exit sub
    end if
    if int(c_emoney)<1 then
      call admin_error("会员卡的 充值数量 必须为大于等于1的整数！")
      exit sub
    end if
    rs("c_name")=c_name
    rs("c_pass")=c_pass
    rs("c_emoney")=c_emoney
    rs("c_hidden")=c_hidden
    rs.update
    rs.close
    call admin_msg("成功修改一条 会员卡 信息！","?jk_mod="&jk_mod,0)
    exit sub
  end if
  call form_first()
  c_hidden=rs("c_hidden")
%>
<form name=add_frm action='?jk_mod=<%response.write jk_mod%>&action=edit&id=<%response.write id%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td width='20%'>会员卡号：</td>
<td width='80%'><input type=text name=c_name value='<%response.write rs("c_name")%>' size=30 maxlength=20><%response.write redx%></td>
</tr>
<tr>
<td>卡号密码：</td>
<td><input type=text name=c_pass value='<%response.write rs("c_pass")%>' size=30 maxlength=20><%response.write redx%></td>
</tr>
<tr>
<td>充值数量：</td>
<td><input type=text name=c_emoney value='<%response.write rs("c_emoney")%>' size=10 maxlength=10>&nbsp;<%response.write joekoe_cms.web_unit&redx%></td>
</tr>
<tr>
<td>是否使用：</td>
<td><input type=radio name=c_hidden value='yes'<%if int(c_hidden)<>0 then response.write " checked"%>>&nbsp;已使用&nbsp;&nbsp;<input type=radio name=c_hidden value='no'<%if int(c_hidden)=0 then response.write " checked"%>>&nbsp;未使用</td>
</tr>
<%
  rs.close
  call submit_edit()
end sub

sub joekoe_chk_card_add()
  dim c_name,c_pass,c_emoney,c_hidden
  call admin_td("添加会员卡")
  if chk() then
    c_name=code_admin("c_name",1,10)
    c_pass=code_admin("c_pass",1,10)
    c_emoney=code_admin("c_emoney",1,10)
    if not int_true(c_emoney) then c_emoney=0
    c_hidden=0
    if trim(request.form("c_hidden"))="yes" then c_hidden=1
    if c_name="" or c_pass="" then
      call admin_error("会员卡的 卡号和密码 不能为空！")
      exit sub
    end if
    if int(c_emoney)<1 then
      call admin_error("会员卡的 充值数量 必须为大于等于1的整数！")
      exit sub
    end if
    sql="select * from cards"
    call joekoe_cms.exec("",-1)
    rs.open sql,conn,1,3
    rs.addnew
    rs("c_name")=c_name
    rs("c_pass")=c_pass
    rs("c_emoney")=c_emoney
    rs("c_hidden")=c_hidden
    rs.update
    rs.close
    call admin_msg("成功添加一条 会员卡 信息！","?jk_mod="&jk_mod,0)
    exit sub
  end if
  call form_first()
%>
<form name=add_frm action='?jk_mod=<%response.write jk_mod%>&action=add' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td width='20%'>会员卡号：</td>
<td width='80%'><input type=text name=c_name value='' size=30 maxlength=20><%response.write redx%></td>
</tr>
<tr>
<td>卡号密码：</td>
<td><input type=text name=c_pass value='' size=30 maxlength=20><%response.write redx%></td>
</tr>
<tr>
<td>充值数量：</td>
<td><input type=text name=c_emoney value='' size=10 maxlength=10>&nbsp;<%response.write joekoe_cms.web_unit&redx%></td>
</tr>
<tr>
<td>是否使用：</td>
<td><input type=radio name=c_hidden value='yes'>&nbsp;已使用&nbsp;&nbsp;<input type=radio name=c_hidden value='no' checked>&nbsp;未使用</td>
</tr>
<%
  call submit_add()
end sub

sub joekoe_chk_card()
  dim c_hidden
%>
  <form name=sel_form action='?jk_mod=<%response.write jk_mod%>&action=delete' method=post>
  <tr align=center>
  <td class=td width='7%'>序号</td>
  <td class=td width='30%'>卡号</td>
  <td class=td width='30%'>密码</td>
  <td class=td width='12%'><%response.write joekoe_cms.web_unit%></td>
  <td class=td width='16%'>相关属性</td>
  <td class=td width='5%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
  </tr>
<%
  sql="select count(c_id) from cards"
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from cards order by c_id desc"
  call joekoe_cms.exec(sql,-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    id=rs("c_id")
    c_hidden=rs("c_hidden")
%>
  <tr align=center>
  <td class=tims><%response.write (viewpage-1)*nummer+i%></td>
  <td align=left><%response.write rs("c_name")%></td>
  <td align=left><%response.write rs("c_pass")%></td>
  <td align=right class=red2><%response.write rs("c_emoney")%>&nbsp;</td>
  <td align=left><%
    response.write pro_edit("?jk_mod="&jk_mod&"&action=edit&id="&id,"编辑该会员卡")&"&nbsp;"
    if int(c_hidden)=0 then
      response.write "<font class=gray>未使用</font>"
    else
      response.write "<font class=red>已使用</font>"
    end if
%></td>
  <td><input type=checkbox name=sel_id value='<%response.write id%>'></td>
  </tr>
<%
    rs.movenext
  next
  rs.close
%>
  <tr class=tr1>
  <td colspan=3>
现有<font class=red><%response.write rssum%></font>篇<%response.write tit_fir%>，
页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
  </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);">
  </td>
  </tr>
  </form>
<%
end sub

sub joekoe_chk_emoney()
  dim sum_pay,e_ispay,e_ptim,sel_id,hdim,hnum,hid,hi,htype
  select case action
  case "handle"
    sel_id=trim(request.form("sel_id"))
    sel_id=replace(sel_id," ","")
    hdim=split(sel_id,",")
    hnum=ubound(hdim)
    for hi=0 to hnum
      hid=hdim(hi)
      if isnumeric(hid) then call joekoe_cms.exec("delete from notes_emoney where e_id="&hid,0)
    next
    call admin_msg("已成功删除了"&(hnum+1)&"条"&tit_fir,pageurl,1)
  case "clear"
    call joekoe_cms.exec("delete from notes_emoney where e_ispay=0 and datediff("&s_d&"d"&s_d&",e_tim,"&s_tim&")>7",0)
    call admin_msg("已成功清理未支付"&tit_fir,pageurl,1)
    exit sub
  end select
  call admin_td("购买"&joekoe_cms.web_unit&tit_fir)
  sql="select sum(e_amount) from notes_emoney where e_ispay=1"
  set rs=joekoe_cms.exec(sql,1)
  sum_pay=rs(0)
  rs.close
  if not isnumeric(sum_pay) then sum_pay=0
%>
<tr align=center valign=top>
<td>
  <table border=0 cellspacing=2 cellpadding=2>
  <tr><td height=5></td></tr>
  <tr><td><%response.write img_admin("","")%>&nbsp;<a href='<%response.write pageurl%>'<%if action="" then response.write " class=red2"%>>购买<%response.write joekoe_cms.web_unit&tit_fir%></a></td></tr>
  <tr><td height=5></td></tr>
  <tr><td><%response.write img_admin("","")%>&nbsp;<a href='<%response.write pageurl%>action=ispay'<%if action="ispay" then response.write " class=red2"%>>已支付购买</a></td></tr>
  <tr><td><%response.write img_admin("","")%>&nbsp;<a href='<%response.write pageurl%>action=nopay'<%if action="nopay" then response.write " class=red2"%>>未支付购买</a></td></tr>
  <tr><td height=5></td></tr>
  <tr><td><%response.write img_admin("s_emoney","")%>&nbsp;支付额：<font class=red><%response.write sum_pay%></font> 元</td></tr>
  <tr><td height=5></td></tr>
  <tr><td><%response.write img_admin("s_imp","")%>&nbsp;<a href='<%response.write pageurl%>action=clear' alt='注意：清理<font class=red>一天前</font>的未支付<%response.write tit_fir%>' onclick="javascript:return click_return('清理一天前的未支付<%response.write tit_fir%>',0);">清理未支付<%response.write tit_fir%></a></td></tr>
  </table>
</td>
<td>
  <table cellspacing=1 cellpadding=2 class=table0>
  <form name=sel_form action='<%response.write pageurl%>action=handle' method=post>
  <tr align=center>
  <td class=td width='7%'>序号</td>
  <td class=td width='25%'>购买订单号</td>
  <td class=td width='16%'>购买用户</td>
  <td class=td width='10%'>金额</td>
  <td class=td width='10%'>购买数</td>
  <td class=td width='16%'>购买时间</td>
  <td class=td width='11%'>支付否</td>
  <td class=td width='5%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
  </tr>
<%
  select case action
  case "ispay"
    sql_add=" where e_ispay=1"
    pageurl=pageurl&"action="&action&"&"
  case "nopay"
    sql_add=" where e_ispay=0"
    pageurl=pageurl&"action="&action&"&"
  end select
  sql="select count(e_id) from notes_emoney "&sql_add
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from notes_emoney "&sql_add&" order by e_id desc"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    nid=rs("e_id")
    tim=rs("e_tim")
    e_ispay=rs("e_ispay")
    e_ptim=rs("e_ptim")
%>
  <tr align=center>
  <td class=tims><%response.write (viewpage-1)*nummer+i%></td>
  <td<%if e_ispay then response.write " class=blue"%>><%response.write rs("e_ordernum")%></td>
  <td><%response.write format_user_view(rs("e_username"),1,0)%></td>
  <td align=right><%response.write rs("e_amount")%>&nbsp;<font class=gray>元</font></td>
  <td align=right><%response.write rs("e_emoney")%>&nbsp;<font class=gray><%response.write joekoe_cms.web_unit%></font></td>
  <td class=tims><%
  if e_ispay then
    response.write "<font class=red alt='支付时间："&joekoe_cms.time_type(e_ptim,2)&"<br><font class=gray>购买时间："&joekoe_cms.time_type(tim,2)&"</font>'>"&joekoe_cms.time_type(e_ptim,3)&"</font>"
  else
    response.write "<font alt='购买时间："&joekoe_cms.time_type(tim,2)&"'>"&joekoe_cms.time_type(tim,3)&"</font>"
  end if
%></td>
  <td><%
  if e_ispay then
    response.write "<font class=red>已支付</font>"
  else
    response.write "<font class=gray>未支付</font>"
  end if
%></td>
  <td><input type=checkbox name=sel_id value='<%response.write nid%>'></td>
  </tr>
<%
    rs.movenext
  next
  rs.close
%>
  <tr>
  <td colspan=6>
现有<font class=red><%response.write rssum%></font>条<%response.write tit_fir%>，
页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
  </td>
  <td colspan=2 align=center>
<select name=sel_type size=1>
<option value='删除'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);">
  </td>
  </tr>
  </form>
  </table>
</td>
</tr>
<%
end sub

sub joekoe_chk_main()
  dim sum_pay,data_type,clear_msg
  call admin_td(tit)
  sql="select sum(e_amount) from notes_emoney where e_ispay=1"
  set rs=joekoe_cms.exec(sql,1)
  sum_pay=rs(0)
  rs.close
  if not isnumeric(sum_pay) then sum_pay=0
%>
<tr>
<td>购买<%response.write joekoe_cms.web_unit%>相关属性：</td>
<td>
  <table border=0>
  <tr>
  <td><%response.write img_admin("s_emoney","")%>&nbsp;总支付金额：<font class=red><%response.write sum_pay%></font>&nbsp;元</td>
  <td width=5></td>
  <td><%response.write img_admin("","")%>&nbsp;<a href='?jk_mod=emoney&action=ispay'>已支付购买</a></td>
  <td width=5></td>
  <td><%response.write img_admin("","")%>&nbsp;<a href='?jk_mod=emoney&action=nopay'>未支付购买</a></td>
  </tr>
  </table>
</td>
</tr>
<%
  if joekoe_cms.chk() then
    data_type=trim(request.form("data_type"))
    select case data_type
    case "all"
      sql="delete from notes"
    clear_msg="所有"
    case "week"
      sql="delete from notes where datediff("&s_d&"d"&s_d&",tim,"&s_tim&")>7"
      clear_msg="一周前"
    case else	'"month"
      sql="delete from notes where datediff("&s_d&"d"&s_d&",tim,"&s_tim&")>30"
    clear_msg="一个月前"
    end select
    call joekoe_cms.exec(sql,0)
    call admin_msg("已成功清理了"&clear_msg&"的消费数据！",pageurl,1)
    exit sub
  end if
  call form_first()
%>
<tr>
<td>消费数据清理：</td>
<td>
  <table border=0>
  <tr>
  <td>对网站内部模块的虚拟货币（<%response.write joekoe_cms.web_unit%>）消费数据，如文章、下载、影视、图片等栏目所消耗的消费数据。</td>
  </tr>
  </table>
</td>
</tr>
<tr>
<form name=data_frm action='<%response.write pageurl%>' method=post>
<input type=hidden name=chk value='yes'>
<td class=htd>注意：<br>清除后将不能再恢复</td>
<td>
  <table border=0>
  <tr><td><input type=radio name=data_type value='month' checked>&nbsp;清除一个月前的数据</td></tr>
  <tr><td><input type=radio name=data_type value='week'>&nbsp;清除一周前的数据</td></tr>
  <tr><td><input type=radio name=data_type value='all'>&nbsp;清除所有的消费数据</td></tr>
  </table>
</td>
</tr>
<tr>
<td></td>
<td><input type=submit value='执行清除操作' onclick="javascript:return click_return('执行清除操作',0);"></td>
</form>
</tr>
<%
end sub
%>