<!-- #include file="include/con_user.asp" -->
<!-- #include file="include/jk_md5.asp" -->
<!-- #include file="include/joekoe_pay.asp" -->
<%

dim unit_num,emoney_1,chk,errs,is_converion,is_virement,min_amount
unit_num=dim_num(7)
min_amount=dim_num(25)
if not isnumeric(min_amount) then min_amount=1
if min_amount<1 then min_amount=1
chk=joekoe_cms.chk()
errs=""
is_converion=true
if cstr(format_mid_num(11))<>"1" then
  is_converion=false
  if action="converion" then action=""
end if
is_virement=true
if cstr(format_mid_num(12))<>"1" then
  is_virement=false
  if action="virement" then action=""
end if

tit="虚拟货币"

call web_head(2,0,0,0,0)
'----------------------------左边 开始----------------------------
call user_left("")
'----------------------------左边 结束----------------------------
call web_center(0)
'----------------------------中间 开始----------------------------
call emoney_main()
'----------------------------中间 结束----------------------------
call web_end(0,0)

sub emoney_pay_chk()
  dim pay_amount,pay_emoney,pay_ordernum,p_order_true,price_head
  price_head=""
  pay_amount=trim(request.form("pay_amount"))
  if not joekoe_cms.int_true(pay_amount) then
    response.write "<tr><td height=30><font class=red2>购买失败：</font>请输入一个大于0的正整数！&nbsp;&nbsp;<input type=button name=go_back value='返回上一页' onclick=""javascript:history.back(1);""></td></tr>"
    exit sub
  end if
  if csng(pay_amount)<csng(min_amount) then
    response.write "<tr><td height=30><font class=red2>购买失败：</font>您输入的人民币数额（<font class=red><b>"&pay_amount&"</b></font>元）低于当前的最低消费额（<font class=red><b>"&min_amount&"</b></font>元）！&nbsp;&nbsp;<input type=button name=go_back value='返回上一页' onclick=""javascript:history.back(1);""></td></tr>"
    exit sub
  end if
  pay_emoney=pay_amount*dim_num(8)
  pay_emoney=cint(pay_emoney)
  pay_ordernum=joekoe_cms.time_type(joekoe_cms.now_time,11)
  p_order_true=true
  sql="select top 1 e_id from notes_emoney where e_ordernum='"&pay_ordernum&"'"
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    rs.close
    response.write "<tr><td height=30><font class=red>真对不起！当前购买"&joekoe_cms.web_unit&"的用户太多，请稍候再进行购买。</font></td></tr>"
    exit sub
  end if
  rs.close
  sql="insert into notes_emoney(e_ordernum,e_username,e_amount,e_emoney,e_tim,e_ispay) " & _
      "values('"&pay_ordernum&"','"&login_username&"',"&price_head&pay_amount&","&pay_emoney&",'"&joekoe_cms.now_time&"',0)"
  call joekoe_cms.exec(sql,0)
  dim obj_pay
  set obj_pay=new joekoe_pay
  obj_pay.pay_sort="emoney"
  obj_pay.pay_username=login_username
  obj_pay.pay_carry=pay_emoney&joekoe_cms.web_unit&"，换算率：1:"&dim_num(8)
  obj_pay.back_url=joekoe_cms.own_http()&"pay_return_emoney.asp"
  obj_pay.pay_ordernum=pay_ordernum
  obj_pay.pay_amount=pay_amount
  obj_pay.frm_target=false
  call obj_pay.pay_frm(1)
  set obj_pay=nothing
  response.write "<tr><td height=30>您支付的&nbsp;<font class=red2><b>"&fm_price(pay_amount,1)&"</b></font>&nbsp;元人民币可以购买&nbsp;<font class=red2><b>"&pay_emoney&"</b></font>&nbsp;"&joekoe_cms.web_unit&"&nbsp;&nbsp;<input type=button value='在线支付' onClick=""javascript:joekoe_online_pay();""></td></tr>"
end sub

sub emoney_main()
  dim emoneys,emoney_2,emoney_3,emoney_pe,e_num,e_all,c_name,c_pass,c_emoney,c_id
  emoney_2=0
  c_id=0
  emoney_1=login_integral\unit_num
  if action<>"virement" and action<>"card" and action<>"converion" then action="pay"
  
  if (action="converion" or action="virement") and chk=true then
    e_num=trim(request.form("e_num"))
    e_all=trim(request.form("e_all"))
    emoneys=emoney_1
    if action="virement" then emoneys=login_emoney
    if e_all="yes" then
      emoney_2=emoneys
    else
      if not(isnumeric(e_num)) then
        errs="no"
      else
        if instr(1,e_num,".")>0 then
          errs="no"
        else
         if int(e_num)<1 or int(e_num)>int(emoneys) then
           errs="no"
         else
           emoney_2=e_num
         end if
        end if
      end if
    end if
    if action="virement" then
      emoney_pe=emoney_2*dim_num(22)/100
      emoney_pe=joekoe_cms.fix_num(emoney_pe,1)
      emoney_3=emoney_pe+emoney_2
      if int(login_emoney)<int(emoney_3) then
        emoney_2=emoney_2-(emoney_3-login_emoney)
        emoney_3=login_emoney
      end if
    end if
    if action="converion" and int(emoney_2)>0 then
      call joekoe_cms.exec("update user_data set integral=integral-"&emoney_2*unit_num&",emoney=emoney+"&emoney_2&" where username='"&login_username&"'",0)
      login_integral=login_integral-emoney_2*unit_num
      login_emoney=login_emoney+emoney_2
      emoney_1=emoney_1-emoney_2
      response.write joekoe_cms.js_put("alert(""您已成功换算了 "&emoney_2&" "&joekoe_cms.web_unit&"！\n\n您的积分消耗了："&emoney_2*unit_num&" 分\n\n目前的积分换算率为：每 "&unit_num&" 分可换算 1 "&joekoe_cms.web_unit&""");",1)
    end if
    
    if action="virement" and int(emoney_2)>0 then
      dim username2
      username2=trim(request.form("username2"))
      if symbol_name(username2)<>true then
        errs="no"
      else
        set rs=joekoe_cms.exec("select username from user_data where username='"&username2&"'",1)
        if rs.eof then errs="no"
        rs.close
      end if
      if errs="" then 
        call joekoe_cms.exec("update user_data set emoney=emoney-"&emoney_3&" where username='"&login_username&"'",0)
        call joekoe_cms.exec("update user_data set emoney=emoney+"&emoney_2&" where username='"&username2&"'",0)
        login_emoney=login_emoney-emoney_3
        response.write joekoe_cms.js_put("alert(""您已成功的给 "&username2&" 转帐了 "&emoney_2&" "&joekoe_cms.web_unit&"！\n\n您拥有的"&tit&"也减少了："&emoney_3&" "&joekoe_cms.web_unit&"\n\n转帐手续费为："&emoney_pe&" "&joekoe_cms.web_unit&""");",1)
        sql="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
	    "values('"&login_username&"','"&username2&"','[系统]货币转帐信息提示','"&login_username&" 已成功的给 您 转帐了 "&emoney_2&" "&joekoe_cms.web_unit&"！','"&joekoe_cms.now_time&"',1,0)"
	call joekoe_cms.exec(sql,0)
      end if
    end if
  end if
  
  if action="card" and chk=true then
    c_name=joekoe_cms.code_form(trim(request.form("c_name")))
    c_pass=joekoe_cms.code_form(trim(request.form("c_pass")))
    if len(c_name)<1 or len(c_pass)<1 then errs="no"
    if errs="" then
      sql="select c_id,c_emoney from cards where c_name='"&c_name&"' and c_pass='"&c_pass&"' and c_hidden=0"
      set rs=joekoe_cms.exec(sql,1)
      if rs.eof then
        errs="no"
      else
        c_id=rs("c_id")
        c_emoney=rs("c_emoney")
      end if
      rs.close
    end if
    if errs="" then
      dim ok_msg
      ok_msg=""
      call joekoe_cms.exec("update cards set c_hidden=1 where c_id="&c_id,0)
      sql="update user_data set emoney=emoney+"&c_emoney
      if int(login_modep)>3 and int(format_mid_num(13)) then
        sql=sql&",power='"&format_power2(format_mid_num(14),1)&"'"
        ok_msg="\n\n您也同时升级为 "&format_power2(format_mid_num(14),2)&"！"
      end if
      sql=sql&" where username='"&login_username&"'"
      call joekoe_cms.exec(sql,0)
      login_emoney=login_emoney+c_emoney
      response.write joekoe_cms.js_put("alert(""您已成功的用会员卡（卡号："&c_name&"）给您充值了 "&c_emoney&" "&joekoe_cms.web_unit&"！"&ok_msg&""");",1)
    end if
  end if
  
  call emoney_top()

  select case action
  case "converion"
    call emoney_converion()
    call emoney_virement()
    call emoney_card()
    call emoney_pay()
  case "virement"
    call emoney_virement()
    call emoney_card()
    call emoney_pay()
    call emoney_converion()
  case "card"
    call emoney_card()
    call emoney_pay()
    call emoney_converion()
    call emoney_virement()
  case else
    call emoney_pay()
    if not chk then
      call emoney_converion()
      call emoney_virement()
      call emoney_card()
    end if
  end select
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td>&nbsp;<%response.write img_skin("m_user")%>相关说明</td></tr>
<tr class=bg_td><td align=center>
  <table border=0 class=tablew>
  <tr><td><font class=red>注意：</font></td><td>您输入的换算的<%response.write joekoe_cms.web_unit%>数值不能超过您目前可以换算的最大值（<font class=red><%response.write emoney_1&"</font>&nbsp;"&joekoe_cms.web_unit%>）</td></tr>
  <tr><td></td><td>您输入的要转帐的<%response.write joekoe_cms.web_unit%>数值不能超过您目前拥有的最大值（<font class=red><%response.write login_emoney&"</font>&nbsp;"&joekoe_cms.web_unit%>）</td></tr>
  <tr><td></td><td>您在这里进行的<font class=blue>积分换算</font>和<font class=blue>货币转帐</font>为<font class=red>不可逆操作</font>！请在操作前注意一下。</td></tr>
  </table>
</td></tr>
</table>
<%
  response.write ukong
end sub

sub emoney_pay()
%>
<script language=javascript>
<!--
var min_amount=<%response.write min_amount%>;
var base_unit_num=<%response.write dim_num(8)%>;
var strTemp="0123456789";
function emoney_pay_checkreturn()
{
  var num=document.emoney_frm_pay.pay_amount.value;
  if (num<5) 
  {
    alert('对不起，当前最低消费额为 5 元！');
    return false;
  }
  else
  {
    return click_return('您确定要购买 '+(num*base_unit_num)+' '+m_unit+'吗？\n\n您将支付 '+num+' 元人民币！\n\n点击确定进行在线支付购买……',1)
  }
}

function emoney_pay_checknum()
{
  //var num=emoney_pay_nums(document.emoney_frm_pay.pay_amount.value,min_amount);
  var num=document.emoney_frm_pay.pay_amount.value;
  document.emoney_frm_pay.pay_unit_num.value=num*base_unit_num;
}

function emoney_pay_nums(nums,bnum)
{
  var i,j;
  var tmpnum=nums;
  if (tmpnum=="" || tmpnum==null) { return bnum; }
  for (i=0;i<tmpnum.length;i++)
  {
    j=strTemp.indexOf(tmpnum.charAt(i));  
    if (j==-1) { return bnum; }
  }
  if (tmpnum<bnum) { tmpnum=bnum; }
  return tmpnum;
}
-->
</script>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td>&nbsp;<%response.write img_skin("m_user")%>购买<%response.write joekoe_cms.web_unit%></td></tr>
<tr class=bg_td><td align=center>
  <table border=0 class=tablew>
  <tr><td height=20>目前的人民币购买<%response.write joekoe_cms.web_unit%>的比率为：每&nbsp;<font class=red2><b>1</b></font>&nbsp;元人民币可购买&nbsp;<font class=red><b><%response.write dim_num(8)%></b></font>&nbsp;<%response.write joekoe_cms.web_unit%>，当前最低消费额为&nbsp;<font class=red><b><%response.write min_amount%></b></font>&nbsp;元</td></tr>
  </table>
</td></tr>
<tr class=bg_tds><td align=center>
  <table border=0 class=tablew>
<%
  if action="pay" and chk=true then
    call emoney_pay_chk()
  else
%>
  <form name=emoney_frm_pay action='?action=pay' method=post onsubmit="javascript:frm_submitonce(this);">
  <input type=hidden name=chk value='yes'>
  <tr><td height=30>
    <table border=0>
    <tr>
    <td>请输入您要购买<%response.write joekoe_cms.web_unit%>的人民币数额：</td>
    <td><input type=text name=pay_amount value='<%response.write min_amount%>' size=6 maxlength=10 onKeyUp="javascript:emoney_pay_checknum();" style="text-align: center">&nbsp;元</td>
    <td>可购买&nbsp;<input type=text name=pay_unit_num value='<%response.write min_amount*dim_num(8)%>' size=6 maxlength=10 readonly style="text-align: center">&nbsp;<%response.write joekoe_cms.web_unit%></td>
    <td><input type=submit value='在线支付购买' onclick="javascript:return emoney_pay_checkreturn();"></td>
    </tr>
    </table>
  </td></tr>
  </form>
<% end if %>
  </table>
</td></tr>
</table>
<%
end sub

sub emoney_converion()
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td>&nbsp;<%response.write img_skin("m_user")%>积分换算</td></tr>
<tr class=bg_td><td align=center>
  <table border=0 class=tablew>
  <tr><td>目前的积分换算率为：每&nbsp;<font class=red2><b><%response.write unit_num%></b></font>&nbsp;分可换算&nbsp;<font class=red><b>1</b></font>&nbsp;<%response.write joekoe_cms.web_unit%>，您目前可以换算：<font class=red><%response.write emoney_1&"</font>&nbsp;"&joekoe_cms.web_unit%></td></tr>
  </table>
</td></tr>
<tr class=bg_tds><td align=center>
<%if is_converion then%>
  <table border=0 class=tablew>
<% if action="converion" and chk=true and errs<>"" then %>
  <tr><td height=30><font class=red2>换算失败：</font>请输入一个不大于 <font class=red><%response.write emoney_1%></font> 的正整数！&nbsp;&nbsp;<input type=button name=go_back value='返回上一页' onclick="javascript:history.back(1);"></td></tr>
<% else %>
  <form name=emoney_frm_converion action='?action=converion' method=post onsubmit="javascript:frm_submitonce(this);">
  <input type=hidden name=chk value='yes'>
  <tr><td height=30>请输入您要换算的<%response.write joekoe_cms.web_unit%>数值：&nbsp;
<input type=text name=e_num size=12 maxlength=10 value=''>&nbsp;&nbsp;&nbsp;
<input type=checkbox name=e_all value='yes' class=bg_tds>&nbsp;全部换算&nbsp;&nbsp;&nbsp;
<input type=submit value='进行换算'></td></tr>
  </form>
<% end if %>
  </table>
<%else%>
  <table border=0 class=tablew>
  <tr><td height=30><font class=red><b>积分换算</b>功能暂时关闭！</font></td></tr>
  </table>
<%end if%>
</td></tr>
</table>
<%
end sub

sub emoney_virement()
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td>&nbsp;<%response.write img_skin("m_user")%>货币转帐</td></tr>
<tr class=bg_td><td align=center>
  <table border=0 class=tablew>
  <tr><td height=20>目前的转帐的手续费为：<font class=red2><b><%response.write dim_num(22)%>%</b></font>，不足&nbsp;<font class=red><b>1</b></font>&nbsp;<%response.write joekoe_cms.web_unit%>的按&nbsp;<font class=red><b>1</b></font>&nbsp;<%response.write joekoe_cms.web_unit%>计算</td></tr>
  </table>
</td></tr>
<tr class=bg_tds><td align=center>
<%if is_virement then%>
  <table border=0 class=tablew>
<% if action="virement" and chk=true and errs<>"" then %>
  <tr><td height=30><font class=red2>转帐失败：</font></td><td>请输入一个不大于 <font class=red><%response.write emoney_1%></font> 的正整数&nbsp;或&nbsp;您要转入的注册用户不存在！&nbsp;&nbsp;<input type=button name=go_back value='返回上一页' onclick="javascript:history.back(1);"></td></tr>
<% else %>
  <form name=emoney_frm_virement action='?action=virement' method=post onsubmit="javascript:frm_submitonce(this);">
  <input type=hidden name=chk value='yes'>
  <tr><td height=30>请输入您要转帐的注册用户：&nbsp;
<input type=text name=username2 size=15 maxlength=20 value=''>&nbsp;&nbsp;&nbsp;
<%response.write friend_select()%>
</td></tr>
  <tr><td height=30>请输入您要转帐的<%response.write joekoe_cms.web_unit%>数值：&nbsp;
<input type=text name=e_num size=12 maxlength=10 value=''>&nbsp;&nbsp;&nbsp;
<input type=checkbox name=e_all value='yes' class=bg_tds>&nbsp;全部转帐&nbsp;&nbsp;&nbsp;
<input type=submit value='进行转帐'></td></tr>
  </form>
<% end if %>
  </table>
<%else%>
  <table border=0 class=tablew>
  <tr><td height=30><font class=red><b>货币转帐</b>功能暂时关闭！</font></td></tr>
  </table>
<%end if%>
</td></tr>
</table>
<%
end sub

sub emoney_card()
%>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td>&nbsp;<%response.write img_skin("m_user")%>会员卡充值</td></tr>
<tr class=bg_td><td align=center>
  <table border=0 class=tablew>
<% if action="card" and chk=true and errs<>"" then %>
  <tr><td height=30><font class=red2>会员卡充值失败：</font></td><td>您输入的会员 <font class=red>卡号</font> 或 <font class=red>密码</font> 有错误！&nbsp;&nbsp;<input type=button name=go_back value='返回上一页' onclick="javascript:history.back(1);"></td></tr>
<% else %>
  <form name=emoney_frm_card action='?action=card' method=post onsubmit="javascript:frm_submitonce(this);">
  <input type=hidden name=chk value='yes'>
  <tr><td height=30>
    <table border=0>
    <tr>
    <td>卡号：&nbsp;<input type=text name=c_name size=20 maxlength=20></td>
    <td>&nbsp;&nbsp;密码：&nbsp;<input type=password name=c_pass size=20 maxlength=20></td>
    <td>&nbsp;&nbsp;<input type=submit value='会员卡充值'></td>
    </tr>
    </table>
  </td><tr>
  </form>
<% end if %>
  </table>
</td></tr>
</table>
<%
end sub

sub emoney_top()
%>
<table border=0>
<tr height=50 align=center>
<td><a href='?action=pay'><img src='<%response.write joekoe_cms.web_dir_skin%>main/emoney_pay.gif' border=0></a></td>
<td width=30></td>
<td><a href='?action=converion'><img src='<%response.write joekoe_cms.web_dir_skin%>main/emoney_converion.gif' border=0></a></td>
<td width=30></td>
<td><a href='?action=virement'><img src='<%response.write joekoe_cms.web_dir_skin%>main/emoney_virement.gif' border=0></a></td>
<td width=30></td>
<td><a href='?action=card'><img src='<%response.write joekoe_cms.web_dir_skin%>main/emoney_card.gif' border=0></a></td>
</tr>
</table>
<table cellspacing=1 cellpadding=4 class=table>
<tr><td class=td><%response.write img_skin("m_user")%>当前信息</td></tr>
<tr class=bg_td><td align=center>
  <table border=0 class=tablew>
  <tr><td height=25>您目前拥有的<%response.write tit%>为：<font class=red><%response.write login_emoney&"</font>&nbsp;"&joekoe_cms.web_unit%>，社区积分为：<font class=red><%response.write login_integral%></font>&nbsp;分</td></tr>
  </table>
</td></tr>
</table>
<%
end sub

function friend_select()
  dim rsf,ttt,temp1
  temp1=vbcrlf&"<select name=friend_select size=1 onchange=""javascript:if (this.options[this.selectedIndex].value!='') { document.emoney_frm_virement.username2.value=this.options[this.selectedIndex].value; };"">" & _
	vbcrlf&"<option value='' class=bg_td>选择我的好友</option>"
  set rsf=conn.execute("select username2 from user_friend where username1='"&login_username&"' order by id")
  do while not rsf.eof
    ttt=rsf(0)
    temp1=temp1&vbcrlf&"<option value='"&ttt&"'>"&ttt&"</option>"
    rsf.movenext
  loop
  rsf.close
  set rsf=nothing
  temp1=temp1&vbcrlf&"</select>"
  friend_select=temp1
end function

%>