<?php
 
  function arraySort($array,$keys,$sort='asc') {
      $newArr = $valArr = array();
      foreach ($array as $key=>$value) {
          $valArr[$key] = $value[$keys];
      }
      ($sort == 'asc') ?  asort($valArr) : arsort($valArr);
      reset($valArr);
      foreach($valArr as $key=>$value) {
          $newArr[$key] = $array[$key];
      }
      return $newArr;
  }
  function filter_money($money,$accuracy=2)
  {
      $str_ret = 0;
      if (empty($money) === false) {
          $str_ret = sprintf("%.".$accuracy."f", substr(sprintf("%.".($accuracy+1)."f", floatval($money)), 0, -1));
      }
      return floatval($str_ret);
  }
  $data=file_get_contents('http://auth.whfjkj.com/index.php/index/index/sharedTeahouse');
  $data=json_decode($data,true);
  $data=$data['data'];
  $sale_price=0;
  $store_num=0;
  $user_num=0;
  $today_price=0;
  $week_price=0;
  $month_price=0;
  $city_list=[];
  foreach($data as $key=>$value){
      $sale_price+=$value['sale_price'];
      $store_num+=$value['store_num'];
      $user_num+=$value['user_num'];
      $today_price+=$value['today_price'];
      $week_price+=$value['week_price'];
      $month_price+=$value['month_price'];
      $city_list[]=$value['city'];
      $value['sale_price']=$value['sale_price']>10000?filter_money($value['sale_price']/10000).'w':$value['sale_price'];
      $value['user_num']=$value['user_num']>10000?filter_money($value['user_num']/10000).'w':$value['user_num'];
  }
  $sale_price=$sale_price>10000?filter_money($sale_price/10000).'w':$sale_price;
  $today_price=$today_price>10000?filter_money($today_price/10000).'w':$today_price;
  $week_price=$week_price>10000?filter_money($week_price/10000).'w':$week_price;
  $month_price=$month_price>10000?filter_money($month_price/10000).'w':$month_price;
  $user_num=$user_num>10000?filter_money($user_num/10000).'w':$user_num;
  //销量排行
  $sale_price_top=arraySort($data,'sale_price','DESC');
  $user_num_top=arraySort($data,'user_num','DESC');
  $city_list=array_unique($city_list);
  $city_json=[];
  foreach($city_list as $city){
     $city_json[]=[
        ['name'=>'福州'],
        ['name'=>$city],
     ];
  }
  $sale_price_arr=[];
  $i=0;
  foreach($sale_price_top as $s=>$sale){
     $i++;
     if($i>6){
        break;
     }else{
      $sale['sale_price']=$sale['sale_price']>10000?filter_money($sale['sale_price']/10000).'w':$sale['sale_price'];
      $sale_price_arr[]=$sale;
     }
  }
  $user_num_arr=[];
  $i=0;
  foreach($user_num_top as $u=>$user){
    $i++;
     if($i>6){
        break;
     }else{
     $user_num_arr[]=$user;
    }
  }
  $city_json=json_encode($city_json,JSON_UNESCAPED_UNICODE);
  $platform_num=count($data);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>芊雅软件</title>
<script type="text/javascript" src="static/js/jquery.js"></script>
<script type="text/javascript" src="static/js/echarts.min.js"></script>
<script type="text/javascript" src="static/js/china.js"></script>
<script type="text/javascript">
  var city_json=<?php print_r($city_json);?>;
  var platform_num="<?php print_r($platform_num);?>";
</script>
<script type="text/javascript" src="static/js/js.js?time=111"></script>
<script type="text/javascript" src="static/js/jquery.cxselect.min.js"></script>

<link rel="stylesheet" href="static/css/comon0.css">
</head>
<body>
	<div class="canvas">
	<iframe src="https://chashi.youdiy.cn/bigdata/html5" frameborder="0" style="width: 100%; height: 100%"></iframe>
	</div>
<div class="loading">
  <div class="loadbox"> <img src="static/picture/loading.gif"> 页面加载中... </div>
</div>
<div style="overflow: hidden;background:rgba(0,0,40,0) ; position: relative; z-index: 2;"> 
  <div class="mainbox">
    <ul class="clearfix">
      <li>
        <div class="boxall" style="height:350px;">
          <div class="alltitle">软件产品</div>
          <div class="navboxall" id="echart1" >
            
          </div>
        </div>
        <div class="boxall" style="height:360px;">
          <div class="alltitle">数据总计</div>
          <div class="navboxall" >
         
            <div class="sycm">
          <ul class="clearfix">
            <li>
              <h2><?php print_r($sale_price);?></h2>
              <span>销售总额</span></li>
            <li>
              <h2><?php print_r($month_price);?></h2>
              <span>当月销售额</span></li>
            <li>
              <h2><?php print_r($week_price);?></h2>
              <span>本周销售额</span></li>
    
            <li>
              <h2><?php print_r($today_price);?></h2>
              <span>今日销售额</span></li>
            <li>
              <h2><?php print_r($user_num);?></h2>
              <span>用户量</span></li>
            <li>
              <h2><?php print_r($store_num);?></h2>
              <span>商户量</span></li>
        </ul>
        </div>
          </div>
        </div>
       
      </li>
      <li>
        <div class="boxall" style="height:100px">
          <div class="navboxall"><h1>芊雅共享茶室系统</h1></div>
        </div>
        <div class="boxall" style="height:610px">
          
          <div class="navboxall" style="overflow: hidden;height: 100%">
			<div style="width: 120%; height: 120%; position: relative; left: -10%; top: -11%;"  id="echart3">
			  
			  </div>
			</div>
        </div>
        
      </li>
      <li>
        <div class="boxall" style="height:350px">
          <div class="alltitle">销量排行</div>
          <div class="navboxall">
            <table class="table1" width="100%" border="0" cellspacing="0" cellpadding="0">
              <tbody>
                <tr>
                  <th scope="col">排名</th>
                  <th scope="col">名称</th>
                  <th scope="col">金额</th>
                </tr>
                <?php foreach($sale_price_arr as $key=> $item){ ?>
                <tr>
                  <td><span><?php echo $key+1;?></span></td>
                  <td><?php print_r($item['system_name']);?></td>
                  <td><?php print_r($item['sale_price']);?><br></td>
                </tr>
                <?php } ?>
                
              </tbody>
            </table>
          </div>
        </div>
        <div class="boxall" style="height: 360px">
          <div class="alltitle">用户排行</div>
          <div class="navboxall">
            <table class="table1" width="100%" border="0" cellspacing="0" cellpadding="0">
              <tbody>
                <tr>
                  <th scope="col">排名</th>
                  <th scope="col">名称</th>
                  <th scope="col">用户量</th>
                </tr>
                <?php foreach($user_num_arr as $key=> $item){ ?>
                <tr>
                  <td><span><?php echo $key+1;?></span></td>
                  <td><?php print_r($item['system_name']);?></td>
                  <td><?php print_r($item['user_num']);?><br></td>
                </tr>
                <?php } ?>
              </tbody>
            </table>
          </div>
        </div>
      </li>
    </ul>
	  <ul class="clearfix">
      <li style="width:60%">
        <div class="boxall" style="height:300px;">
          <div class="alltitle">数据</div>
          <div class="navboxall " id="echart2" >
            
          </div>
        </div>
      </li>
      <li style="width: 40%">
        
        <div class="boxall" style="height:300px">
          <div class="alltitle">其他</div>
          <div class="navboxall" id="echart4"></div>
        </div>
      </li>
    </ul>
  </div>
</div>
<script>
$(function(){
	$('.wrap,.adduser').liMarquee({
		direction: 'up',//身上滚动 
		runshort: false,//内容不足时不滚动
		scrollamount: 20//速度
	});
});

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