<?php if( !defined( 'ONGPHP')) exit( 'Error ONGSOFT');
$D = db('');



?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>设置</title>
	<script type="text/javascript" src="/jquery-2.1.1.js"></script>
	<link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
	<script type="text/javascript" src="/layui/layui.js" ></script>
	<link rel="stylesheet" type="text/css" href="/webuploader/webuploader.css">

<!--引入JS-->
<script type="text/javascript" src="/webuploader/webuploader.js"></script>

</head>
<body>
  

<div style="padding: 2%;">
    

<table class="layui-table">
    <colgroup>
      <col width="50">
      <col width="150">
      <col width="150">
      <col width="200">
      <col>
    </colgroup>
    <thead>
      <tr>
        <th>ID</th>
        <th>代理名称</th>
        <th>所属角色</th>
        <th>会员数量</th>
        <th>总充值</th>
        <th>比例</th>
        <th>得钱</th>
        <th>已经提现</th>
        <th>剩余</th>
      </tr> 
    </thead>
    <tbody>

    <?php 
      
    $order = '  ';
    $tiaojian = array(
      'type >' =>0
      );
    $admins = $D -> setbiao('admin') -> order(  )->where( $tiaojian )-> select();
    



if ($admins) {
  foreach($admins as  $k => $v){

    ?>

      <tr>
        
        <td><?php echo $v['id'] ?></td>
        <td><?php echo $v['name'] ?></td>
        <td>
          
        <?php 
          
        $fenzu = $D ->setbiao('adminfenzu')-> where( array( "id" => $v['type'] ) ) -> find();
       echo $fenzu['name'];

        ?>

        </td>
        <td>
          
        <?php 
          
        $order = 'uid desc';
        $huiyuans = $D ->setbiao('user')->order( $order )->where( array(
          'adminid' => $v['id']

          ) )-> select();


        if ($huiyuans) {
          $num = count($huiyuans);


          $huis = array();

          foreach($huiyuans as  $k1 => $v1){

            $huis[] =  $v1['uid'];

          }



          /*查询总充值*/

          $order = 'id desc';
          $jins = $D ->setbiao('jinelog')->order( $order )->where( array(
            'uid IN' => $huis,
            'type'=>1

            ) )-> select();

          if ($jins) {

              $rr = array();
              foreach($jins as  $k1 => $v1){

                $rr[] = $v1['jine'];

              }

              $zong = array_sum($rr);

          }else{
            $zong = 0;
          }


        }else{
          $num = 0;

          $zong = 0;

        }






echo $num;

        ?>


        </td>
        <td><?php echo $zong ?></td>




        <td>
          
        <?php 

$daili = explode(',', $shezhi['daili']);
  

  if ($v['type']==1) {

    $biali = $daili[0];
  

  }elseif ($v['type']==2) {
    $biali =  $daili[1];
  }elseif ($v['type']==3) {
   $biali =  $daili[2];
  }

  echo $biali;


        ?>
%

        </td>

<td>
  
<?php 
  
 $deqian =  $zong *( $biali/100 );
echo $deqian;

?>



</td>
        <td>
            <?php 
              $order = 'id desc';
              $tixian = $D ->setbiao('dailitixian')->order( $order )->where( array(
                'adminid' => $v['id']
                ) )-> select();
              if ($tixian) {
                  $titt= array();
                foreach($tixian as  $k1 => $v1){

                  $titt[] = $v['jine'];

                }

                $tixian1 = array_sum( $titt );

              }else{
                $tixian1 =0;
              }
            
              echo $tixian1;

            ?>


        </td>
        <td>
          
        <?php 
            $shengyu = $deqian-$tixian1;
echo $shengyu;

        ?>

        </td>


      </tr>
      
      <?php 
        }
      }
      ?>
      
      
    </tbody>
  </table>







</div>



</body>
<script>
layui.use(['form', 'layedit', 'laydate'], function(){
  var form = layui.form()
  ,layer = layui.layer
  ,layedit = layui.layedit
  ,laydate = layui.laydate;
  
  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo_editor');
 
  //自定义验证规则
  form.verify({
    title: function(value){
      if(value.length < 5){
        return '标题至少得5个字符啊';
      }
    }
    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  //监听指定开关
  form.on('switch(switchTest)', function(data){
    // layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
    //   offset: '6px'
    // });
    // layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
  });
  
  //监听提交
  form.on('submit(demo1)', function(data){
    layer.alert(JSON.stringify(data.field), {
      title: '最终的提交信息'
    })
    return false;
  });
  
  
});
</script>









<script type="text/javascript">
jQuery(function(){

  /*删除*/
  jQuery(".shanchu").click(function(){
    var p = jQuery(this).parent('.ss');
    p.remove();

  })

  /*增加提现规则*/

  jQuery(".adtixcian").click(function(){
      
      jQuery("#tixian").append('<input type="text" name="data[tixian][]" autocomplete="off" placeholder="" class="layui-input"  >');

  })

  /*增加邀请规则*/
  jQuery(".adyaoqing").click(function(){

    jQuery("#yaoqing").append('<input type="text" name="data[yaoqing][]" autocomplete="off" placeholder="" class="layui-input"  >');

  })




  /*增加作弊*/
  jQuery(".adzuobi").click(function(){
    
    jQuery("#zuobi").append('<input type="text" name="data[zuobi][]" autocomplete="off" placeholder="" class="layui-input"  >');

  })

  /*增加规则*/

  jQuery(".adguize").click(function(){
    jQuery("#guieze").append('<input type="text" name="data[guize][]" autocomplete="off" placeholder="" class="layui-input"  >');

  })


  	jQuery(".tijiaoshezhi").click(function(){

        var biaobiao = jQuery("#biaobiao").serialize();
        var data = biaobiao+'&action=shezhi';

        $.ajax({
          async: true,
          type:"POST",
          url:"?action=ajax",
          data:data,
          dataType:'json',
          success:function(data){
            if (data.o=='yes') {
              alert('更新成功');
              location.reload(true);
            }


            
          }



        })



	})
});
</script>


<script type="text/javascript">
  

   // 初始化Web Uploader
    var uploader = WebUploader.create({
        // 选完文件后，是否自动上传。
        auto: true,
            fileVal: 'all',
        // swf文件路径
        swf:   'http://cdn.staticfile.org/webuploader/0.1.0/Uploader.swf',
        // 文件接收服务端。
        server: '<?php  echo '?action=ajax&upload=yes&uplx=all'?>',

        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#filePicker',

        // 只允许选择图片文件。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        }
    });



    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
    uploader.on( 'uploadSuccess', function( file,respond ) {
        var tupian = respond.url;
        jQuery(".tpul").html('');

        jQuery(".tpul").append('<li><img style="width:100px;" src="'+tupian+'" alt=""><input type="hidden" name="data[beijing]" value="'+tupian+'" /> </li>');
    });

</script>

</html>