<?php
use xh\library\url;
use xh\library\model;
$fix = DB_PREFIX;
?>
	<?php include_once (PATH_VIEW . 'common/header.php');?>
	
    <!-- START CONTENT -->
      <section id="content">
        
        <!--breadcrumbs start-->
        <div id="breadcrumbs-wrapper">
            <!-- Search for small screen -->
            <div class="header-search-wrapper grey hide-on-large-only">
                <i class="mdi-action-search active"></i>
                <input type="text" name="Search" class="header-search-input z-depth-2" placeholder="Explore Materialize">
            </div>
          <div class="container">
            <div class="row">
              <div class="col s12 m12 l12">
                <h5 class="breadcrumbs-title">配置收款账号</h5>
                <ol class="breadcrumbs">
                    <li><a href="<?php echo url::s('index/panel/home');?>">仪表盘</a></li>
                    <li><a href="<?php echo url::s('index/alipay/automatic');?>">微博红包</a></li>
                </ol>
              </div>
            </div>
          </div>
        </div>
        <!--breadcrumbs end-->
        <!--start container-->
        <div class="container">
          <div class="section">
			<p class="caption">
		          <a onclick="addwwm();" style="font-size: 14px;background-color: red;!important;" class="btn waves-effect waves-light grey darken-3" ><i class="mdi-content-add left" style="width: 10px;"></i>添加收包人</a> 	
				<br>
				<br>
			<font color=blue>收款账号总数：<font color=red><?php
                                        $account = $mysql->select("select count(id) as count from {$fix}client_alipay_automatic_appid where user_id={$_SESSION['MEMBER']['uid']}")[0];
                                        echo $account['count'];
                                        ?></font></font>&nbsp;	&nbsp;	
                                        <font color=blue>今日领取笔数:<font color=red><?php  $order = $mysql->select("select sum(today_number) as money,count(id) as count from {$fix}client_alipay_automatic_appid where  user_id={$_SESSION['MEMBER']['uid']}")[0];
                                        echo number_format($order['money']);
                                        ?></font>  </font>&nbsp;	&nbsp;	
                                        <font color=blue>今日领取总额:<font color=red><?php  $order = $mysql->select("select sum(amount) as money,count(id) as count from {$fix}client_alipay_automatic_appid where  user_id={$_SESSION['MEMBER']['uid']}")[0];
                                        echo number_format($order['money'],3);
                                        ?></font>  </font>&nbsp;	&nbsp;	
                                         <font color=blue>总计领取笔数:<font color=red><?php  $order = $mysql->select("select sum(all_number) as money,count(id) as count from {$fix}client_alipay_automatic_appid where  user_id={$_SESSION['MEMBER']['uid']}")[0];
                                        echo number_format($order['money']);
                                        ?>  </font></font>&nbsp;	&nbsp;	
                                        <font color=blue>总计领取总额:<font color=red><?php  $order = $mysql->select("select sum(all_amount) as money,count(id) as count from {$fix}client_alipay_automatic_appid where  user_id={$_SESSION['MEMBER']['uid']}")[0];
                                        echo number_format($order['money'],3);
                                        ?>  </font></font>
                                        
				</p>

 
            <!--Striped Table-->
            <div id="striped-table">

              <div class="row">
   
                <div class="col s12 m12 l12">
                  <table class="striped"  style="font-size: 14px;">
                    <thead>
                      <tr>
                          <th>ID</th>
                          <th>备注</th>
                         <!-- <th>所属设备</th>-->
                          <th>状态</th>
                          <th>收款UID</th>
                          <th>今日领取笔数</th>
                          <th>今日领取金额</th>
                          <th>总计领取笔数</th>
                          <th>总计领取金额</th>
                          <th>每日领取限额</th>
						  <th>状态操作</th>	
                      </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($result['result'] as $ru){?>
                      <tr>
                        <td><?php echo $ru['id'];?></td>
                       <td><?php echo $ru['beizhu'];?></td>
                        <!--<td><?php echo $ru['key_id'];?></td>-->
                       <td><p><?php
                                       if ($ru['status']==4){
                                       $zt='正常使用';
                                       $ys='red';
                                       }else if ($ru['status']==1||$ru['status']==5){
                                         $zt='禁用中';
                                         $ys='rainbow';
                                       };
                                        ?>
                                       <font color=<?php echo $ys;?> ><?php echo $zt;?></font></p></td>
                        <td><?php echo $ru['appid'];?></td>
                        
                        <td><?php echo $ru['today_number'];?></td>
                        <td><?php echo $ru['amount'];?></td>
                        <td><?php echo $ru['all_number'];?></td>
                        <td><?php echo $ru['all_amount'];?></td>
                        <td><?php echo $ru['max_amount'];?></td>
                            <td>
                                  
                               <?php echo $ru['status'] ==4 ? '<span style="color:#4caf50;">启用中 ( <a href="#" style="color:#006064;" onclick="startAutomaticEwm(' . $ru['id'] . ');">禁用 </a> )</span>' : '<span style="color:red;">禁用中 ( <a href="#" style="color:#e57373;" onclick="startAutomaticEwm(' . $ru['id'] . ');">启用 </a>)</span>'; ?>
                            		<br>
                            		<!--<a href="javascript:void(0);"  onclick="editMaxAmount('<?php echo $ru['id'];?>');" class="qdbtn edit-click">设置收款额度</a>
									<br>-->
									<a href="#" onclick="del('<?php echo $ru['id'];?>');" style="color:#757575;">删除账号</a>
                                  </td>
                        
                      </tr>
                    <?php }?>
                    </tbody>
                  </table>
                </div>
              </div>
              
              <div class="row"><ul class="pagination"><?php (new model())->load('page', 'turn')->auto($result['info']['pageAll'], $result['info']['page'], 10); ?></ul></div>
  
            </div>
            
            

          </div>


        </div>
        <!--end container-->

      </section>

      <!-- END CONTENT -->
      <script type="text/javascript">
       function addSk(){
       	
     
       	
       	
          swal({   title: "请输入微博红包配置信息",
                  type: "input",
                  showCancelButton: true,
                  closeOnConfirm: false,
                  html: true,
                  text: "备注<input type='text' id='nick_name' value=''>"
                  +"微博红包UID<input type='text' id='gathering_name'>",
                  confirmButtonText: "提交" },
              function(inputValue){
                  if (inputValue === false) return false;
                  if (inputValue === "") {
                      swal.showInputError("微博红包帐号不能为空");
                      return false
                  }
                  $.get("<?php echo url::s('index/alipay/uidAdd',"gathering_name=");?>" +$('#gathering_name').val()+"&nick_name="+$('#nick_name').val(), function(result){
                      if(result.code == '200'){
                          swal("成功提醒", result.msg, "success");
                          setTimeout(function(){location.href = '';},1000);
                      }else{
                          swal.showInputError(result.msg);
                      }
                  });
              });
          $('.showSweetAlert fieldset input').attr('type','hidden');
      }
 
 
 
 function addwwm(){
       	
          swal({   title: "请输入微博收款账号信息",
                  type: "input",
                  showCancelButton: true,
                  closeOnConfirm: false,
                  html: true,
                  text: "微博昵称:<input type='text' id='name'>"+"微博UID:<input type='text' id='uid' value=''>"
                  +"微博COOKIE:<input type='text' id='kku'>",
                  confirmButtonText: "提交" },
              function(inputValue){
                  if (inputValue === false) return false;
                  if (inputValue === "") {
                      swal.showInputError("微博UID不能为空");
                      return false
                  }
                  $.get("<?php echo url::s('index/alipay/wxAdd',"uid=");?>"+$('#uid').val()+"&kku="+$('#kku').val()+"&name="+$('#name').val(), function(result){
                      if(result.code == '200'){
                          swal("成功提醒", result.msg, "success");
                          setTimeout(function(){location.href = '';},1000);
                      }else{
                          swal.showInputError(result.msg);
                      }
                  });
              });
          $('.showSweetAlert fieldset input').attr('type','hidden');
      }
      
      
      
  //收款状态启用关闭
  function startAutomaticEwm(id) {
        swal({
                title: "微博红包提醒",
                text: "当前操作是更改账号状态,您是否继续?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的,继续!",
                closeOnConfirm: false
            },
            function () {
                $.get("<?php echo url::s('index/alipay/startAutomaticUid', "id=");?>" + id, function (result) {
                    if (result.code == '200') {
                        swal("微博红包提示", result.msg, "success");
                        setTimeout(function () {
                            location.href = '';
                        }, 1000);
                    } else {
                        swal("微博红包提示", result.msg, "error");
                    }
                });
            });
    }
    
	  function del(id){
		  swal({   title: "微博红包提醒",   
              text: "请验证您的登录密码:",   
              type: "input",   showCancelButton: true,   
              closeOnConfirm: false,   
              animation: "slide-from-top",   
              inputPlaceholder: "会员登录密码",
              confirmButtonText: "确认删除" }, 
              function(inputValue){   
                  if (inputValue === false) return false;      
                  if (inputValue === "") {     
                  swal.showInputError("请输入您的登录密码!");     
                  return false   
                  }
             $.get("<?php echo url::s('index/alipay/uidDelete',"id=");?>" + id + "&pwd=" + inputValue, function(result){
              	 if(result.code == '200'){
               		    swal("微博红包提醒", result.msg, "success");
    	              	setTimeout(function(){location.href = '';},1000);
    	              }else{
    	            	swal.showInputError(result.msg);     
    	             }
          		});
         });
		  $('.showSweetAlert input').attr('type','password');
	  }
       
       
       function editMaxAmount(id){
          swal({   title: "修改提醒",
                  type: "input",   showCancelButton: true,
                  closeOnConfirm: false,
                  animation: "slide-from-top",
                  inputPlaceholder: "最大收款",
                  confirmButtonText: "确认提交" },
              function(inputValue){
                  if (inputValue === false) return false;
                  if (inputValue === "") {
                      swal.showInputError("请输入您的最大收款金额!");
                      return false
                  }
                  $.get("<?php echo url::s('index/alipay/edituidMaxAmount',"id=");?>" + id + "&amount=" + inputValue, function(result){
                      if(result.code == '200'){
                          swal("提醒", result.msg, "success");
                          setTimeout(function(){location.href = '';},1000);
                      }else{
                          swal.showInputError(result.msg);
                      }
                  });
              });
          $('.showSweetAlert input').attr('type','text');
      }
    
      function goewm(){
    //	var ewm = "https://render.alipay.com/p/f/fd-ixpo7iia/index.html";
    	qrcode_img = "https://api.phpma.cn/qrcode/qrcode.png?t=1574313864";
    
          swal({   title: "打开微博红包扫描此二维码获取UID",
                  type: "success",
                  showCancelButton: true,
                  closeOnConfirm: false,
                  html: true,
                  imageUrl: qrcode_img,
                 imageSize:"200x200",
                   },
 							 );
          $('.showSweetAlert fieldset input').attr('type','hidden');
      }
	  </script>
      <?php include_once (PATH_VIEW . 'common/footer.php');?>    
   