<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <?php $shoname_name = D('Home/Front')->get_config_by_name('shoname'); ?>
  <title><?php echo $shoname; ?></title>
  <link rel="shortcut icon" href="" />
        
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">

  <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
 
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->  

<link href="./resource/css/bootstrap.min.css?v=201903260001" rel="stylesheet">
<link href="./resource/css/common.css?v=201903260001" rel="stylesheet">
<script type="text/javascript">
            window.sysinfo = {
            <?php if (!empty($_W['uniacid']) ){ ?>'uniacid': '{$_W['uniacid']}',<?php } ?>
			
            <?php if( !empty($_W['acid'])  ){ ?>'acid': '{$_W['acid']}',<?php } ?>
			
            <?php if (!empty($_W['openid']) ) { ?>'openid': '{$_W['openid']}',<?php } ?>
			
            <?php if( !empty($_W['uid']) ) {  ?>'uid': '{$_W['uid']}',<?php } ?>
			
            'isfounder': <?php if (!empty($_W['isfounder']) ) { ?>1<?php  }else{  ?>0<?php } ?>,
			
            'siteroot': '{$_W['siteroot']}',
                    'siteurl': '{$_W['siteurl']}',
                    'attachurl': '{$_W['attachurl']}',
                    'attachurl_local': '{$_W['attachurl_local']}',
                    'attachurl_remote': '{$_W['attachurl_remote']}',
                    'module' : {'url' : '<?php if( defined('MODULE_URL') ) { ?>{MODULE_URL}<?php } ?>', 'name' : '<?php if (defined('IN_MODULE') ) { ?>{IN_MODULE}<?php } ?>'},
            'cookie' : {'pre': ''},
            'account' : {:json_encode($_W['account'])},
            };
        </script>
		
<script type="text/javascript" src="./resource/js/lib/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="./resource/js/lib/bootstrap.min.js"></script>
<script type="text/javascript" src="./resource/js/app/util.js?v=201903260001"></script>
<script type="text/javascript" src="./resource/js/app/common.min.js?v=201903260001"></script>
<script type="text/javascript" src="./resource/js/require.js?v=201903260001"></script>
<script type="text/javascript" src="./resource/js/lib/jquery.nice-select.js?v=201903260001"></script>
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
<link href="/static/css/snailfish.css" rel="stylesheet">
<style>
.img-40{width:40px;height:40px;}
</style>
</head>
<body layadmin-themealias="default">

<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header layui-elem-quote">当前位置：<span class="line-text">分销管理</span></div>
		<div class="layui-tab layui-tab-brief" >
		  <ul class="layui-tab-title">
				<li <?php if(empty($type) || $type=='0'){ ?> class="layui-this"<?php } ?>>
					<a href="{:U('distribution/distribution', array('type' => 0))}">全部</a>
				</li>
				<li <?php if($type==1){ ?> class="layui-this"<?php } ?> >
					<a href="{:U('distribution/distribution', array('type' => 1))}">已审核</a>
				</li>
				<li  <?php if($type==2){ ?>class="layui-this"<?php } ?> >
					<a href="{:U('distribution/distribution', array('type' => 2))}">未审核</a>
				</li>
		  </ul>
		</div>
		<div class="layui-card-body" style="padding:15px;">
    
      <form action="" method="get" class="form-horizontal form-search layui-form" role="form">
        <input type="hidden" name="c" value="distribution" />
        <input type="hidden" name="a" value="distribution" />
        
        <div class="layui-form-item">
          <div class="layui-inline">
		  
		  <div class="layui-input-inline">
				<select name='searchtime' class='form-control' style="width:100px;padding:0 5px;"  id="searchtime">
					<option value=''>不按时间</option>
					<option value='create_time' <?php if( $_GPC['searchtime']=='create_time' ){ ?>selected<?php } ?>>审核时间</option>
				</select>
		 </div>
		 <div class="layui-input-inline" style="width: 285px;">
				{:tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d H:i', $endtime)),true);}
		 </div>
		  
		  
          	
          <div class="layui-input-inline" >
            <select name="comsiss_state" class='layui-input layui-unselect' data-placeholder="状态">
              	<option value=''>状态</option>
						<option value='0' <?php if($_GPC['comsiss_state']=='0'){ ?>selected<?php } ?>>未审核</option>
						<option value='1' <?php if($_GPC['comsiss_state']=='1'){ ?>selected<?php } ?>>已审核</option>
                        <option value='2' <?php if($_GPC['comsiss_state']=='2'){ ?>selected<?php } ?>>已拒绝</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <input type="text" class="layui-input" name='keyword' value="{$_GPC['keyword']}" placeholder="昵称/姓名/手机号">  
          </div>
          <div class="layui-input-inline">
            <button class="layui-btn layui-btn-sm"  type="submit"> 搜索</button>
            
			<button type="submit" name="export" data-export="1" value="1" class="layui-btn layui-btn-sm">导出</button>
          </div>
          </div>
        </div>
        
      </form>
      <form action="" class="layui-form" lay-filter="example" method="post" >
       
        <div class="row">
          <div class="col-md-12">
            <div class="page-table-header">
              <div class="btn-group">
                <button class="btn btn-default btn-sm  btn-operation"  type="button" data-confirm='确认要审核通过?' data-toggle='batch' data-href="{:U('distribution/agent_check',array('comsiss_state'=>1))}">审核通过</button>
                <button class="btn btn-default btn-sm  btn-operation"  type="button" data-toggle='batch' data-href="{:U('distribution/agent_check',array('comsiss_state'=>0))}">取消审核</button>
                
              </div>
            </div>
            
            <table class="layui-table" lay-skin="line" lay-size="lg">
              <thead>
                <tr>
               			<th style="width:25px;"></th>
						<th style="width:60px;">ID</th>
                        <th style="width: 220px;">用户名</th>
						<th style='width:80px;'>累计佣金<br/>打款佣金</th>
						<th style='width:180px;'>推荐人</th>
						<th style='width:20px;'>上级用户</th>
						<th style='width:20px;'>下级用户</th>
                        <th style="width:200px;">注册时间</br>审核时间</th>
                        <th style='width:200px;'>申请类型</th>
						<th style='width:150px;'>状态</th>
                        <th style="width: 220px;text-align: center;">操作</th>
                </tr>
              </thead>
              <tbody>
			  <?php foreach($list as $row){ ?>
           
				<tr>
					<td style="position: relative; ">
						<input type='checkbox' name="item_checkbox" lay-skin="primary" value="{$row['member_id']}"/>
					</td>
					<td>
						{$row['member_id']}
					</td>
					<td style="overflow: visible">
						<div rel="pop" style="display: flex"  >
						   <img class="img-40" src="{$row['avatar']}" style='border-radius:50%;border:1px solid #efefef;' />
						   <span style="display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-left: 5px">
							   <span class="nickname">
								   <?php if(empty($row['username'])){ ?>未更新<?php }else{ ?>{$row['username']}<?php } ?>
							   </span>
								<?php if($row['isblack']==1){ ?>
									<span class="text-danger">未启用<i class="icow icow-heimingdan1"style="color: #db2228;margin-left: 2px;font-size: 13px;"></i></span>
							    <?php } ?>
						   </span>
						</div>
					</td>
					<td>
						 <span class="text-danger">{$row['commission_info']['commission_total']}</span><br/>
						 <span class="text-warning">{$row['commission_info']['getmoney']}</span>
					</td>
					<td>
						
						<?php if( empty($row['share_parent_info']) ){ ?>
						 
						  <?php if( $row['isagent']==0 ){ ?>
							  总店
						  <?php }else{ ?>
							 暂无
						  <?php } ?>
						<?php }else{ ?>

						
						<?php if( !empty($row['share_parent_info']['avatar']) ){ ?>
						 <img src='{$row['share_parent_info']['avatar']}' style='width:20px;height:20px;padding1px;border:1px solid #ccc' />
						<?php } ?>
						[{$row['share_parent_info']['member_id']}]<?php if(empty($row['share_parent_info']['username'])){ ?>未更新<?php }else{ ?>{$row['share_parent_info']['username']}<?php } ?>
					    <?php } ?>
					</td>
					<td>
					
						<?php if(empty($row['parent_info'])){ ?>
						 
						  <?php if($row['isagent']==0){ ?>
							  总店
						  <?php }else{ ?>
							 暂无
						  <?php } ?>
						<?php }else{ ?>

						<?php if(!empty($row['parent_info']['avatar'])){ ?>
						 <img src='{$row['parent_info']['avatar']}' style='width:20px;height:20px;padding1px;border:1px solid #ccc' />
						<?php } ?>
						[{$row['parent_info']['member_id']}]<?php if(empty($row['parent_info']['username'])){ ?>未更新<?php }else{ ?>{$row['parent_info']['username']}<?php } ?>
					   <?php } ?>
					</td>
					<td>
						<a  href="{:U('distribution/nextchild_list',array('id' => $row['member_id']));}"   style="color: rgb(0,0,255);"  title="">
						{$row['next_member_count']}
						</a>
						
						
					</td>
					<td>
						{:date("Y-m-d",$row['create_time'])}<br/>{:date("H:i:s",$row['create_time'])}
						<br/>
						<?php if( !empty($row['comsiss_time']) ){ ?>
							{:date("Y-m-d",$row['comsiss_time'])}<br/>{:date("H:i:s",$row['comsiss_time'])}
						<?php } ?>
					</td>
					<td>
						<?php if($row['is_writecommiss_form'] == 1){ ?>
						<a class="layui-btn layui-btn-sm " href="{:U('user/detail',array('id' => $row['member_id'],'is_showform' => 1));}" title="">
							<span data-toggle="tooltip" data-placement="top" title="" data-original-title="表单">
								<i class='icow icow-bianji2'></i>表单
							</span>
						</a>
						<?php } ?>
						<?php if($row['is_share_tj'] == 1){ ?>
						<a class="layui-btn layui-btn-sm  " href="{:U('distribution/sharedetail',array('id' => $row['member_id']));}" title="">
							<span data-toggle="tooltip" data-placement="top" title="" data-original-title="分享">
								<i class='icow icow-bianji2'></i>分享
							</span>
						</a>
						<?php } ?>
                        <?php if($row['is_share_tj'] == 0 && $row['is_writecommiss_form'] == 0){ ?>
                            <?php if($row['is_comsiss_admin'] == 1){ ?>
                                后台设置
                            <?php }else{?>
                                无
                            <?php } ?>
                        <?php } ?>

					</td>
					<td>
                        <?php if($row['is_comsiss_audit'] == 0 && $row['comsiss_state'] != 1){ ?>
                        <?php if($row['comsiss_state'] == 0){ ?>
                        <a class="layui-btn layui-btn-xs check_agent" href="javascript:void(0)" data-href="{:U('distribution/check_agent',array('id'=>$row['member_id'],'state'=>1))}" data-confirm="确认通过该会员的分销申请？" title="" style="padding: 0 15px;">
                              <span data-toggle="tooltip" data-placement="top" title="" data-original-title="通过">
                                  <i class='icow icow-bianji2'></i>通过
                              </span>
                        </a>
                        <br/>
                        <input type="checkbox" lay-filter="statewsitch_jujue" data-href="{:U('distribution/check_agent',array('id'=>$row['member_id'],'state'=>2))}" lay-skin="switch" lay-text="拒绝|拒绝">
                        <?php } ?>
                        <?php if($row['comsiss_state'] == 2){ ?>
                            <span style="color:red;">已拒绝</span><br/>
                            <a class="check_agent" data-href="{:U('distribution/check_agent',array('id'=>$row['member_id'],'state'=>1))}" data-confirm="确认通过该会员的分销申请？" style="padding: 0px;color:#1182e4;cursor: pointer;">
                                    <span data-toggle="tooltip" data-placement="top" title="" data-original-title="重新审核">
                                        <i class='icow icow-bianji2'></i>重新审核
                                    </span>
                            </a>
                        <?php } ?>
                        <?php } ?>
                        <?php if($row['comsiss_state'] == 1 || $row['is_comsiss_audit'] == 1){ ?>
                        <input type="checkbox" name="" lay-filter="statewsitch" data-href="{:U('distribution/agent_check',array('id'=>$row['member_id']))}" <?php if($row['comsiss_state']==1){ ?>checked<?php } ?> lay-skin="switch" lay-text="启用|禁用">
                        <?php } ?>
					</td>
					<td style="overflow:visible;">
						<div class="btn-group">

							
							<?php if($s_id == 1){ ?>
								<a class="layui-btn layui-btn-xs " href="{:U('user/detail',array('id' => $row['member_id']));}" title="">
									<span data-toggle="tooltip" data-placement="top" title="" data-original-title="会员详情">
										<i class='icow icow-bianji2'></i>查看详情
									</span>
								</a>
							<?php }else{ ?>
								<a class="layui-btn layui-btn-xs user"  title="">
									<span data-toggle="tooltip" data-placement="top" title="" data-original-title="会员详情">
										<i class='icow icow-bianji2'></i>查看详情
									</span>
								</a>
							<?php } ?>
							
						</div>
						
						<div class="btn-group">		
							<a class="layui-btn layui-btn-xs" href="{:U('distribution/distributionorder',array('commiss_member_id' => $row['member_id']));}"  target='_blank'>
								分销推广订单
							</a>
						</div>	
						<div class="btn-group">			
							<a class="layui-btn layui-btn-xs" href="{:U('distribution/communityorder',array('member_id' => $row['member_id']));}"  target='_blank'>
								分销收益明细
							</a>
						</div>	
						
						<div class="btn-group">
							<?php if( $row['comsiss_flag'] == 1 && $row['comsiss_state'] == 1 ){  ?>
							<a class="layui-btn layui-btn-sm  " href="{:U('distribution/nextchild_list',array('id' => $row['member_id']));}" title="">
								<span data-toggle="tooltip" data-placement="top" title="" data-original-title="查看下级">
									<i class='icow icow-bianji2'></i>查看下级
								</span>
							</a>
							<?php } ?>
						</div>
					</td>
				</tr>
			<?php } ?>
					
              </tbody>
              <tfoot>
              <tr>
                <td colspan="4">
                  <div class="page-table-header">
                    <input type="checkbox" name="checkall" lay-skin="primary" lay-filter="checkboxall">
                    <div class="btn-group">
		                <button class="btn btn-default btn-sm  btn-operation"  type="button" data-confirm='确认要审核通过?' data-toggle='batch' data-href="{:U('distribution/agent_check',array('comsiss_state'=>1))}">审核通过</button>
		                <button class="btn btn-default btn-sm  btn-operation"  type="button" data-toggle='batch' data-href="{:U('distribution/agent_check',array('comsiss_state'=>0))}">取消审核</button>
		                
		              </div>
                  </div>
                </td>
                <td colspan="7" style="text-align: right">
                  {$pager}
                </td>
              </tr>
              </tfoot>
            </table>
          </div>
        </div>
        
      </form>
    </div>
		
	</div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>

<script>
	layui.config({
		base: '/layuiadmin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	}).use('index');
</script>

<script>
//由于模块都一次性加载，因此不用执行 layui.use() 来加载对应模块，直接使用即可：
var layer = layui.layer;
var $;

layui.use(['jquery', 'layer','form'], function(){ 
  $ = layui.$;
  var form = layui.form;

  $('.check_agent').click(function(){
     var s_url = $(this).attr('data-href');
     var confirm_txt = $(this).attr('data-confirm');
    if(confirm_txt){
      layer.confirm($(this).attr('data-confirm'), function(index){
        $.ajax({
          url:s_url,
          type:'post',
          dataType:'json',
          success:function(info){

            if(info.status == 0)
            {
              layer.msg(info.result.message,{icon: 1,time: 2000});
            }else if(info.status == 1){
              var go_url = location.href;
              if( info.result.hasOwnProperty("url") )
              {
                go_url = info.result.url;
              }

              layer.msg('操作成功',{time: 1000,
                end:function(){
                  location.href = info.result.url;
                }
              });
            }
          }
        })
      });
    }
  })
  
  $('.deldom').click(function(){
    var s_url = $(this).attr('data-href');
    layer.confirm($(this).attr('data-confirm'), function(index){
           $.ajax({
            url:s_url,
            type:'post',
            dataType:'json',
            success:function(info){
            
              if(info.status == 0)
              {
                layer.msg(info.result.message,{icon: 1,time: 2000});
              }else if(info.status == 1){
                var go_url = location.href;
                if( info.result.hasOwnProperty("url") )
                {
                  go_url = info.result.url;
                }
                
                layer.msg('操作成功',{time: 1000,
                  end:function(){
                    location.href = info.result.url;
                  }
                }); 
              }
            }
          })
        }); 
  })
  
  $('.btn-operation').click(function(){
    var ids_arr = [];
    var obj = $(this);
    var s_toggle = $(this).attr('data-toggle');
    var s_url = $(this).attr('data-href');
    
    
    $("input[name=item_checkbox]").each(function() {
      
      if( $(this).prop('checked') )
      {
        ids_arr.push( $(this).val() );
      }
    })
    if(ids_arr.length < 1)
    {
      layer.msg('请选择要操作的内容');
    }else{
      var can_sub = true;
      if( s_toggle == 'batch-remove' )
      {
        can_sub = false;
        
        layer.confirm($(obj).attr('data-confirm'), function(index){
           $.ajax({
            url:s_url,
            type:'post',
            dataType:'json',
            data:{ids:ids_arr},
            success:function(info){
            
              if(info.status == 0)
              {
                layer.msg(info.result.message,{icon: 1,time: 2000});
              }else if(info.status == 1){
                var go_url = location.href;
                if( info.result.hasOwnProperty("url") )
                {
                  go_url = info.result.url;
                }
                
                layer.msg('操作成功',{time: 1000,
                  end:function(){
                    location.href = info.result.url;
                  }
                }); 
              }
            }
          })
        }); 
      }else{
        $.ajax({
          url:s_url,
          type:'post',
          dataType:'json',
          data:{ids:ids_arr},
          success:function(info){
          
            if(info.status == 0)
            {
              layer.msg(info.result.message,{icon: 1,time: 2000});
            }else if(info.status == 1){
              var go_url = location.href;
              if( info.result.hasOwnProperty("url") )
              {
                go_url = info.result.url;
              }
              
              layer.msg('操作成功',{time: 1000,
                end:function(){
                  location.href = info.result.url;
                }
              }); 
            }
          }
        })
      }
    }
  })


  form.on('switch(statewsitch_jujue)', function(data){

    var s_url = $(this).attr('data-href');

    $.ajax({
      url:s_url,
      type:'post',
      dataType:'json',
      success:function(info){

        if(info.status == 0)
        {
          layer.msg(info.result.message,{icon: 1,time: 2000});
        }else if(info.status == 1){
          var go_url = location.href;
          if( info.result.hasOwnProperty("url") )
          {
            go_url = info.result.url;
          }

          layer.msg('操作成功',{time: 1000,
            end:function(){
              location.href = info.result.url;
            }
          });
        }
      }
    })
  });

  form.on('switch(statewsitch)', function(data){
    
    var s_url = $(this).attr('data-href')
    
    var s_value = 1;
    if(data.elem.checked)
    {
    s_value = 1;
    }else{
    s_value = 0;
    }
    
    $.ajax({
      url:s_url,
      type:'post',
      dataType:'json',
      data:{comsiss_state:s_value},
      success:function(info){
      
        if(info.status == 0)
        {
          layer.msg(info.result.message,{icon: 1,time: 2000});
        }else if(info.status == 1){
          var go_url = location.href;
          if( info.result.hasOwnProperty("url") )
          {
            go_url = info.result.url;
          }
          
          layer.msg('操作成功',{time: 1000,
            end:function(){
              location.href = info.result.url;
            }
          }); 
        }
      }
    })
  });  
  form.on('checkbox(checkboxall)', function(data){
    
    if(data.elem.checked)
    {
    $("input[name=item_checkbox]").each(function() {
      $(this).prop("checked", true);
    });
    $("input[name=checkall]").each(function() {
      $(this).prop("checked", true);
    });
    
    }else{
    $("input[name=item_checkbox]").each(function() {
      $(this).prop("checked", false);
    });
    $("input[name=checkall]").each(function() {
      $(this).prop("checked", false);
    });
    }
    
    form.render('checkbox');
  });

  $('.user').click(function(){
		layer.msg('权限不足!',{icon: 2,time: 1200});
  }); 
 
  //监听提交
  form.on('submit(formDemo)', function(data){
  
   $.ajax({
    url: data.form.action,
    type: data.form.method,
    data: data.field,
    dataType:'json',
    success: function (info) {
      
      if(info.status == 0)
      {
        layer.msg(info.result.message,{icon: 1,time: 2000});
      }else if(info.status == 1){
        var go_url = location.href;
        if( info.result.hasOwnProperty("url") )
        {
          go_url = info.result.url;
        }
        
        layer.msg('操作成功',{time: 1000,
          end:function(){
            location.href = info.result.url;
          }
        }); 
      }
    }
  });
  
    return false;
  });
})

</script>  
</body>
</html>
