普乐智能

查看: 6657|回复: 0

PHP数据图形化报表SQL数据查询

[复制链接]

338

主题

424

帖子

1670

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1670
发表于 2022-1-13 10:22:18 | 显示全部楼层 |阅读模式
  1. <?php
  2. header("Content-type: text/html; charset=utf-8");
  3. if(!defined('CORE'))exit("error!");

  4. //数组转化为type循环th名称
  5. function type_tj_th($arr,$report){
  6.         foreach($arr as $key=>$val){
  7.                 $slt .= "<th>".$val." <a href="index.php?action=report&prod=".$key."&do=".$report."&time_start=".$_POST[time_start]."&time_over=".$_POST[time_over]."" target="_blank"">[柱状图]</a></th>\n";
  8.         }
  9.         return $slt;
  10. }


  11. //[1]销售统计表查询
  12. function count_user_tt($productid,$cuserid,$search,$td){
  13.                 global $db;
  14.                 //按不同产查询数量
  15.                 $sql="SELECT sellproduct,sellvol FROM `rv_sell` where salesid={$cuserid} {$search}";
  16.                 $db->query($sql);
  17.                 $list=$db->fetchAll();       
  18.                 foreach($list as $k=>$v){       
  19.                          $list[sellvol] = explode(",",$list[$k][sellvol]);
  20.                          $list[sellproduct] = explode(",",$list[$k][sellproduct]);
  21.                          foreach($list[sellvol] as $key=>$val){                 
  22.                                 $selllist[newsellvol][$list[sellproduct][$key]] += $val;
  23.                          }
  24.                 }
  25.                 if($td!=""){
  26.                         $tdl="<td>";
  27.                         $tdr="</td>";
  28.                 }
  29.                 foreach($productid as $kk=>$vv){
  30.                         if($selllist[newsellvol][$kk]==""){
  31.                         $cc .= $tdl."0".$tdr;
  32.                         }else{                       
  33.                         $cc .=  $tdl.$selllist[newsellvol][$kk].$tdr;
  34.                         }
  35.                 }
  36.                 return $cc;
  37. }

  38. //[1]销售统计表统计查询
  39. function count_user_th($productid,$cuserid,$search){
  40.                 global $db;
  41.                 //按不同产查询数量
  42.                 $sql="SELECT sellproduct,sellvol FROM `rv_sell` where salesid={$cuserid} {$search}";
  43.                 $db->query($sql);
  44.                 $list=$db->fetchAll();       
  45.                 foreach($list as $k=>$v){       
  46.                          $list[sellvol] = explode(",",$list[$k][sellvol]);
  47.                          $list[sellproduct] = explode(",",$list[$k][sellproduct]);
  48.                          foreach($list[sellvol] as $key=>$val){                 
  49.                                 $selllist[newsellvol][$list[sellproduct][$key]] += $val;
  50.                          }
  51.                 }
  52.                 foreach($productid as $kk=>$vv){
  53.                         if($kk == $_GET[prod]){                               
  54.                                 if($selllist[newsellvol][$kk]==""){
  55.                                         $cc[] .= "0";
  56.                                 }else{
  57.                                         $cc[] .=  $selllist[newsellvol][$kk];
  58.                                 }                       
  59.                         }
  60.                 }
  61.                 return $cc;
  62. }

  63. //[2]区域统计表查询
  64. function count_areaid_tt($productid,$areaid,$search,$td){
  65.                 global $db;
  66.                
  67.                 $sql="SELECT distinct id FROM `rv_info` WHERE `areaid` = {$areaid}";
  68.                 $db->query($sql);
  69.                 $area_list =$db->fetchAll();
  70.                 foreach($area_list as $k=>$v){
  71.                         $area_list[$k] = $area_list[$k][id];
  72.                 }
  73.                 $userarr = implode(",",$area_list);
  74.                 //按不同产查询数量
  75.                 if($userarr!=""){
  76.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in ({$userarr}) {$search}";
  77.                 }else{
  78.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in (0) {$search}";
  79.                 }
  80.                
  81.                 $db->query($sql);
  82.                 $list=$db->fetchAll();       
  83.                 foreach($list as $k=>$v){       
  84.                          $list[sellvol] = explode(",",$list[$k][sellvol]);
  85.                          $list[sellproduct] = explode(",",$list[$k][sellproduct]);
  86.                          foreach($list[sellvol] as $key=>$val){                 
  87.                                 $selllist[newsellvol][$list[sellproduct][$key]] += $val;
  88.                          }
  89.                 }
  90.                 if($td!=""){
  91.                         $tdl="<td>";
  92.                         $tdr="</td>";
  93.                 }
  94.                 foreach($productid as $kk=>$vv){
  95.                         if($selllist[newsellvol][$kk]==""){
  96.                         $cc .= $tdl."0".$tdr;
  97.                         }else{                       
  98.                         $cc .=  $tdl.$selllist[newsellvol][$kk].$tdr;
  99.                         }
  100.                 }
  101.                 return $cc;
  102. }

  103. //[2]销售统计表统计查询
  104. function count_areaid_th($productid,$areaid,$search){
  105.                 global $db;
  106.                
  107.                 $sql="SELECT distinct id FROM `rv_info` WHERE `areaid` = {$areaid}";
  108.                 $db->query($sql);
  109.                 $area_list =$db->fetchAll();
  110.                 foreach($area_list as $k=>$v){
  111.                         $area_list[$k] = $area_list[$k][id];
  112.                 }
  113.                 $areaarr = implode(",",$area_list);
  114.                
  115.                 //按不同产查询数量
  116.                
  117.                 //按不同产查询数量
  118.                 if($areaarr!=""){
  119.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in ({$areaarr}) {$search}";
  120.                 }else{
  121.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in (0) {$search}";       
  122.                 }
  123.                
  124.                 $db->query($sql);
  125.                 $list=$db->fetchAll();       
  126.                 foreach($list as $k=>$v){       
  127.                          $list[sellvol] = explode(",",$list[$k][sellvol]);
  128.                          $list[sellproduct] = explode(",",$list[$k][sellproduct]);
  129.                          foreach($list[sellvol] as $key=>$val){                 
  130.                                 $selllist[newsellvol][$list[sellproduct][$key]] += $val;
  131.                          }
  132.                 }
  133.                 foreach($productid as $kk=>$vv){               
  134.                         if($kk == $_GET[prod]){                       
  135.                                 if($selllist[newsellvol][$kk]==""){
  136.                                 $cc[] .= "0";
  137.                                 }else{                       
  138.                                 $cc[] .=  $selllist[newsellvol][$kk];
  139.                                 }
  140.                         }
  141.                 }
  142.                 return $cc;
  143. }


  144. //[3]类型统计表查询
  145. function count_typeid_tt($productid,$typeid,$search,$td){
  146.                 global $db;
  147.                
  148.                 $sql="SELECT distinct id FROM `rv_info` WHERE `typeid` = {$typeid}";
  149.                 $db->query($sql);
  150.                 $type_list =$db->fetchAll();
  151.                 foreach($type_list as $k=>$v){
  152.                         $type_list[$k] = $type_list[$k][id];
  153.                 }
  154.                 $typearr = implode(",",$type_list);
  155.                
  156.                 //按不同产查询数量
  157.                 if($typearr!=""){
  158.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in ({$typearr}) {$search}";       
  159.                 }else{
  160.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in (0) {$search}";               
  161.                 }
  162.                 $db->query($sql);
  163.                 $list=$db->fetchAll();       
  164.                
  165.                 foreach($list as $k=>$v){       
  166.                          $list[sellvol] = explode(",",$list[$k][sellvol]);
  167.                          $list[sellproduct] = explode(",",$list[$k][sellproduct]);
  168.                          foreach($list[sellvol] as $key=>$val){                 
  169.                                 $selllist[newsellvol][$list[sellproduct][$key]] += $val;
  170.                          }
  171.                 }
  172.                 if($td!=""){
  173.                         $tdl="<td>";
  174.                         $tdr="</td>";
  175.                 }
  176.                 foreach($productid as $kk=>$vv){
  177.                         if($selllist[newsellvol][$kk]==""){
  178.                         $cc .= $tdl."0".$tdr;
  179.                         }else{                       
  180.                         $cc .=  $tdl.$selllist[newsellvol][$kk].$tdr;
  181.                         }
  182.                 }
  183.                 return $cc;
  184. }

  185. //[3]类型统计表统计查询
  186. function count_typeid_th($productid,$typeid,$search){
  187.                 global $db;
  188.                
  189.                 $sql="SELECT distinct id FROM `rv_info` WHERE `typeid` = {$typeid}";
  190.                 $db->query($sql);
  191.                 $type_list =$db->fetchAll();
  192.                 foreach($type_list as $k=>$v){
  193.                         $type_list[$k] = $type_list[$k][id];
  194.                 }
  195.                 $typearr = implode(",",$type_list);
  196.                 //按不同产查询数量
  197.                 if($typearr!=""){
  198.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in ({$typearr}) {$search}";       
  199.                 }else{
  200.                         $sql="SELECT sellproduct,sellvol FROM `rv_sell` where `infoid` in (0) {$search}";               
  201.                 }
  202.                 $db->query($sql);
  203.                 $list=$db->fetchAll();       
  204.                 foreach($list as $k=>$v){       
  205.                          $list[sellvol] = explode(",",$list[$k][sellvol]);
  206.                          $list[sellproduct] = explode(",",$list[$k][sellproduct]);
  207.                          foreach($list[sellvol] as $key=>$val){                 
  208.                                 $selllist[newsellvol][$list[sellproduct][$key]] += $val;
  209.                          }
  210.                 }
  211.                 foreach($productid as $kk=>$vv){               
  212.                         if($kk == $_GET[prod]){                       
  213.                                 if($selllist[newsellvol][$kk]==""){
  214.                                 $cc[] .= "0";
  215.                                 }else{                       
  216.                                 $cc[] .=  $selllist[newsellvol][$kk];
  217.                                 }
  218.                         }
  219.                 }
  220.                 return $cc;
  221. }


  222. //【1】销售统计表
  223. if($do=="t1"){
  224.         If_rabc($action,$do); //检测权限        //查询
  225.        
  226.         //判断检索值
  227.         if($_POST['time_start'] && $_POST['time_over']){
  228.                 $search = " and `created_at` > '$_POST[time_start] 00:00:00' and `created_at`<  '$_POST[time_over] 23:59:59' ";
  229.         }       
  230.        
  231.         //sql按用户
  232.         $sql ="SELECT id,username FROM `rv_user` as u group by id asc";
  233.         $db->query($sql);
  234.         $list=$db->fetchAll();
  235.         //格式化输出数据
  236.         foreach($list as $key=>$val){
  237.                 $list[$key][productid_tj] = count_user_tt($productid,$list[$key][id],$search,"td");
  238.         }
  239.        
  240.         //sql合计
  241.         $sqltotal ="SELECT sellproduct,sellvol FROM `rv_sell` where 1=1 {$search}";
  242.         $db->query($sqltotal);
  243.         $listtotal=$db->fetchAll();
  244.         //格式化输出数据
  245.         foreach($listtotal as $k=>$v){       
  246.                  $listtotal[sellvol] = explode(",",$listtotal[$k][sellvol]);
  247.                  $listtotal[sellproduct] = explode(",",$listtotal[$k][sellproduct]);
  248.                  foreach($listtotal[sellvol] as $key=>$val){                 
  249.                         $selllist[newsellvol][$listtotal[sellproduct][$key]] += $val;
  250.                  }
  251.         }
  252.         foreach($selllist[newsellvol] as $keyt=>$valt){
  253.                 $productid_tj_total .= "<td>".$valt."</td>";
  254.         }
  255.        
  256.         //模版
  257.         $smt = new smarty();smarty_cfg($smt);
  258.         $smt->assign('list',$list);       
  259.         $smt->assign('productid_tj_total',$productid_tj_total);       
  260.         $smt->assign('productid_cn',type_tj_th($productid,"t1t"));
  261.         $smt->assign('postdate_start',$_POST[time_start]);
  262.         $smt->assign('postdate_over',$_POST[time_over]);
  263.         $smt->assign('title',"销售统计表");
  264.         $smt->display('report_t1.htm');
  265.         exit;
  266. }


  267. //【1】 销售统计表 [图]
  268. if($do=="t1t"){
  269.         If_rabc($action,$do); //检测权限
  270.         $post_prod = $_POST[prod];
  271.        
  272.         //判断检索值
  273.         if($_GET['time_start'] && $_GET['time_over']){
  274.                 $search = " and `created_at` > '$_GET[time_start] 00:00:00' and `created_at`<  '$_GET[time_over] 23:59:59' ";
  275.                 $postdate = "<span class='t_title'>当前时间范围: [$_GET[time_start] 00:00:00] 到 [$_GET[time_over] 23:59:59]</span>";
  276.         }else{
  277.                 $postdate = "<span class='t_title'>当前时间范围:全部时间</span>";
  278.         }
  279.        
  280.         //sql按用户查询
  281.         $sql ="SELECT id,username FROM `rv_user` as u group by id asc";
  282.         $db->query($sql);
  283.         $list=$db->fetchAll();
  284.         //格式化输出数据
  285.         foreach($list as $key=>$val){
  286.                 $x_title[]="'".$list[$key][username]."'";
  287.                 $productid_tj[] = count_user_th($productid,$list[$key][id],$search);
  288.         }
  289.        
  290.         //格式化报表数据按产品按人合计
  291.         foreach($productid as $key=>$val){       
  292.                 if($key==$_GET[prod]){               
  293.                         $i=0;
  294.                         foreach($productid_tj as $k=>$v){
  295.                                 $num_arr0[$i+1][] = $productid_tj[$k][$i];
  296.                         }
  297.                         $i++;
  298.                 }
  299.         }
  300.        
  301.         //格式化
  302.         foreach($productid as $key=>$val){               
  303.                 if($key==$_GET[prod]){
  304.                         $i=1;
  305.                         $num_arr[] = "var s".$i." = [".implode(",", $num_arr0[$i])."];\n";
  306.                         $numname_arr[] = "s".$i ;
  307.                         $titlecolor[] = $i.". ".$val."<br\>";
  308.                         $i++;
  309.                 }
  310.         }
  311.         //模版
  312.         $smt = new smarty();smarty_cfg($smt);
  313.         $smt->assign('list',$list);
  314.         $smt->assign('prod_name',$productid[$_GET[prod]]);
  315.         $smt->assign('x_title',implode(",", $x_title));
  316.         $smt->assign('titlecolor',implode("<br/>", $titlecolor));
  317.         $smt->assign('num',implode("", $num_arr));
  318.         $smt->assign('numname',implode(",", $numname_arr));
  319.         $smt->assign('postdate',$postdate);
  320.         $smt->assign('title',"销售统计表 [图]");
  321.         $smt->display('report_t1_t.htm');
  322.         exit;
  323. }



  324. //【2】区域统计表       
  325. if($do=="t2"){
  326.         If_rabc($action,$do); //检测权限        //查询
  327.         //判断检索值
  328.         if($_POST['time_start'] && $_POST['time_over']){
  329.                 $search = " and `created_at` > '$_POST[time_start] 00:00:00' and `created_at`<  '$_POST[time_over] 23:59:59' ";
  330.         }
  331.        
  332.         //格式化输出数据
  333.         $i=0;
  334.         foreach($areaid as $k1=>$v1){
  335.                 $list[$i][username] = $v1;
  336.                 $list[$i][productid_tj] = count_areaid_tt($productid,$k1,$search,"td");               
  337.                 $i++;
  338.         }
  339.        
  340.         //sql合计
  341.         $sqltotal ="SELECT sellproduct,sellvol FROM `rv_sell` where 1=1 {$search}";
  342.         $db->query($sqltotal);
  343.         $listtotal=$db->fetchAll();
  344.         //格式化输出数据
  345.         foreach($listtotal as $k=>$v){       
  346.                  $listtotal[sellvol] = explode(",",$listtotal[$k][sellvol]);
  347.                  $listtotal[sellproduct] = explode(",",$listtotal[$k][sellproduct]);
  348.                  foreach($listtotal[sellvol] as $key=>$val){                 
  349.                         $selllist[newsellvol][$listtotal[sellproduct][$key]] += $val;
  350.                  }
  351.         }
  352.         foreach($selllist[newsellvol] as $keyt=>$valt){
  353.                 $productid_tj_total .= "<td>".$valt."</td>";
  354.         }
  355.        
  356.         //模版
  357.         $smt = new smarty();smarty_cfg($smt);
  358.         $smt->assign('list',$list);       
  359.         $smt->assign('productid_tj_total',$productid_tj_total);       
  360.         $smt->assign('productid_cn',type_tj_th($productid,"t2t"));
  361.         $smt->assign('postdate_start',$_POST[time_start]);
  362.         $smt->assign('postdate_over',$_POST[time_over]);
  363.         $smt->assign('title',"销售统计表");
  364.         $smt->display('report_t2.htm');
  365.         exit;
  366. }

  367. //【2】区域统计表 [图]
  368. if($do=="t2t"){
  369.         If_rabc($action,$do); //检测权限
  370.         //判断检索值
  371.         if($_GET['time_start'] && $_GET['time_over']){
  372.                 $search = " and `created_at` > '$_GET[time_start] 00:00:00' and `created_at`<  '$_GET[time_over] 23:59:59' ";
  373.                 $postdate = "<span class='t_title'>当前时间范围: [$_GET[time_start] 00:00:00] 到 [$_GET[time_over] 23:59:59]</span>";
  374.         }else{
  375.                 $postdate = "<span class='t_title'>当前时间范围:全部时间</span>";
  376.         }
  377.        
  378.        
  379.         //格式化输出数据
  380.         $i=0;
  381.         foreach($areaid as $k1=>$v1){
  382.                 $x_title[]="'".$v1."'";
  383.                 $productid_tj[] = count_areaid_th($productid,$k1,$search);
  384.                 $i++;
  385.         }
  386.        
  387.         //格式化报表数据按产品按人合计
  388.         foreach($productid as $key=>$val){
  389.                 if($key==$_GET[prod]){               
  390.                         $i=0;
  391.                         foreach($productid_tj as $k=>$v){
  392.                                 $num_arr0[$i+1][] = $productid_tj[$k][$i];
  393.                         }
  394.                         $i++;
  395.                 }
  396.         }
  397.         //格式化
  398.         foreach($productid as $key=>$val){               
  399.                 if($key==$_GET[prod]){
  400.                         $i=1;               
  401.                         $num_arr[] = "var s".$i." = [".implode(",", $num_arr0[$i])."];\n";
  402.                         $numname_arr[] = "s".$i ;
  403.                         $titlecolor[] = $i.". ".$val."<br\>";
  404.                         $i++;
  405.                 }
  406.         }
  407.         //模版
  408.         $smt = new smarty();smarty_cfg($smt);
  409.         $smt->assign('list',$list);
  410.         $smt->assign('prod_name',$productid[$_GET[prod]]);
  411.         $smt->assign('x_title',implode(",", $x_title));
  412.         $smt->assign('titlecolor',implode("<br/>", $titlecolor));
  413.         $smt->assign('num',implode("", $num_arr));
  414.         $smt->assign('numname',implode(",", $numname_arr));
  415.         $smt->assign('postdate',$postdate);
  416.         $smt->assign('title',"销售统计表 [图]");
  417.         $smt->display('report_t2_t.htm');
  418.         exit;
  419. }

  420. //【3】类型统计表       
  421. if($do=="t3"){
  422.         If_rabc($action,$do); //检测权限        //查询
  423.         //判断检索值
  424.         if($_POST['time_start'] && $_POST['time_over']){
  425.                 $search = " and `created_at` > '$_POST[time_start] 00:00:00' and `created_at`<  '$_POST[time_over] 23:59:59' ";
  426.         }       
  427.        
  428.         //格式化输出数据
  429.         $i=0;
  430.         foreach($typeid as $k1=>$v1){
  431.                 $list[$i][username] = $v1;
  432.                 $list[$i][productid_tj] = count_typeid_tt($productid,$k1,$search,"td");
  433.                 $i++;
  434.         }
  435.         //sql合计
  436.         $sqltotal ="SELECT sellproduct,sellvol FROM `rv_sell` where 1=1 {$search}";
  437.         $db->query($sqltotal);
  438.         $listtotal=$db->fetchAll();
  439.         //格式化输出数据
  440.         foreach($listtotal as $k=>$v){       
  441.                  $listtotal[sellvol] = explode(",",$listtotal[$k][sellvol]);
  442.                  $listtotal[sellproduct] = explode(",",$listtotal[$k][sellproduct]);
  443.                  foreach($listtotal[sellvol] as $key=>$val){                 
  444.                         $selllist[newsellvol][$listtotal[sellproduct][$key]] += $val;
  445.                  }
  446.         }
  447.         foreach($selllist[newsellvol] as $keyt=>$valt){
  448.                 $productid_tj_total .= "<td>".$valt."</td>";
  449.         }
  450.        
  451.         //模版
  452.         $smt = new smarty();smarty_cfg($smt);
  453.         $smt->assign('list',$list);       
  454.         $smt->assign('productid_tj_total',$productid_tj_total);       
  455.         $smt->assign('productid_cn',type_tj_th($productid,"t3t"));
  456.         $smt->assign('postdate_start',$_POST[time_start]);
  457.         $smt->assign('postdate_over',$_POST[time_over]);
  458.         $smt->assign('title',"类型统计表");
  459.         $smt->display('report_t3.htm');
  460.         exit;
  461. }

  462. //【3】类型统计表 [图]
  463. if($do=="t3t"){
  464.         If_rabc($action,$do); //检测权限
  465.         //判断检索值
  466.         if($_GET['time_start'] && $_GET['time_over']){
  467.                 $search = " and `created_at` > '$_GET[time_start] 00:00:00' and `created_at`<  '$_GET[time_over] 23:59:59' ";
  468.                 $postdate = "<span class='t_title'>当前时间范围: [$_GET[time_start] 00:00:00] 到 [$_GET[time_over] 23:59:59]</span>";
  469.         }else{
  470.                 $postdate = "<span class='t_title'>当前时间范围:全部时间</span>";
  471.         }
  472.        
  473.         //格式化输出数据
  474.         $i=0;
  475.         foreach($typeid as $k1=>$v1){
  476.                 $x_title[]="'".$v1."'";
  477.                 $productid_tj[] = count_typeid_th($productid,$k1,$search);
  478.                 $i++;
  479.         }
  480.        
  481.         //格式化报表数据按产品按人合计
  482.         foreach($productid as $key=>$val){                       
  483.                 if($key==$_GET[prod]){
  484.                         $i=0;
  485.                         foreach($productid_tj as $k=>$v){
  486.                                 $num_arr0[$i+1][] = $productid_tj[$k][$i];
  487.                         }
  488.                         $i++;
  489.                 }
  490.         }
  491.         //格式化
  492.         foreach($productid as $key=>$val){                               
  493.                 if($key==$_GET[prod]){
  494.                         $i=1;
  495.                         $num_arr[] = "var s".$i." = [".implode(",", $num_arr0[$i])."];\n";
  496.                         $numname_arr[] = "s".$i ;
  497.                         $titlecolor[] = $i.". ".$val."<br\>";
  498.                         $i++;
  499.                 }
  500.         }
  501.         //模版
  502.         $smt = new smarty();smarty_cfg($smt);
  503.         $smt->assign('list',$list);
  504.         $smt->assign('prod_name',$productid[$_GET[prod]]);
  505.         $smt->assign('x_title',implode(",", $x_title));
  506.         $smt->assign('titlecolor',implode("<br/>", $titlecolor));
  507.         $smt->assign('num',implode("", $num_arr));
  508.         $smt->assign('numname',implode(",", $numname_arr));
  509.         $smt->assign('postdate',$postdate);
  510.         $smt->assign('title',"类型统计表 [图]");
  511.         $smt->display('report_t3_t.htm');
  512.         exit;
  513. }



  514. //考勤统计表       
  515. if($do=="t7"){
  516.         If_rabc($action,$do); //检测权限        //查询
  517.         //判断检索值
  518.         if($_POST['time_start'] && $_POST['time_over']){
  519.                 $search = " and `created_at` > '$_POST[time_start] 00:00:00' and `created_at`<  '$_POST[time_over] 23:59:59' ";
  520.         }       

  521.         //sql按用户
  522.         $sql ="SELECT id,username,
  523.         (SELECT count(*) FROM `rv_track` as r where u.id= r.salesid {$search}) as num ,
  524.         (SELECT count(*) FROM `rv_track` as r where u.id= r.salesid and status = '1' {$search} ) as numz
  525.         FROM `rv_user` as u ";
  526.         $db->query($sql);
  527.         $list=$db->fetchAll();
  528.        
  529.         //sql按合计
  530.         $sql ="SELECT count(*)  as num ,
  531.         (SELECT count(*) FROM `rv_track` where status = '1' {$search}) as numz
  532.         FROM `rv_track` where 1=1 {$search}";
  533.         $db->query($sql);
  534.         $rowtotal=$db->fetchRow();
  535.        
  536.         //模版
  537.         $smt = new smarty();smarty_cfg($smt);
  538.         $smt->assign('list',$list);       
  539.         $smt->assign('attendance_txt',$attendance_txt);       
  540.         $smt->assign('postdate_start',$_POST[time_start]);
  541.         $smt->assign('postdate_over',$_POST[time_over]);
  542.         $smt->assign('rowtotal',$rowtotal);       
  543.         $smt->assign('title',"考勤统计表");
  544.         $smt->display('report_t7.htm');
  545.         exit;
  546. }

  547. //考勤统计表        [图]
  548. if($do=="t7t"){
  549.         If_rabc($action,$do); //检测权限        //查询
  550.         //判断检索值
  551.         if($_GET['time_start'] && $_GET['time_over']){
  552.                 $search = " and `created_at` > '$_GET[time_start] 00:00:00' and `created_at`<  '$_GET[time_over] 23:59:59' ";
  553.                 $postdate = "<span class='t_title'>当前时间范围: [$_GET[time_start] 00:00:00] 到 [$_GET[time_over] 23:59:59]</span>";
  554.         }else{
  555.                 $postdate = "<span class='t_title'>当前时间范围:全部时间</span>";
  556.         }

  557.         //sql按用户
  558.         $sql ="SELECT id,username,
  559.         (SELECT count(*) FROM `rv_track` as r where u.id= r.salesid and status = 1 {$search}) as num
  560.         FROM `rv_user` as u ";
  561.         $db->query($sql);
  562.         $list=$db->fetchAll();       
  563.         foreach($list as $key=>$val){
  564.                 $x_title[]="'".$list[$key][username]."'";
  565.                 $num[]=$list[$key][num];
  566.         }
  567.         //模版
  568.         $smt = new smarty();smarty_cfg($smt);
  569.         $smt->assign('list',$list);       
  570.         $smt->assign('num',implode(",", $num));
  571.         $smt->assign('x_title',implode(",", $x_title));
  572.         $smt->assign('postdate',$postdate);
  573.         $smt->assign('rowtotal',$rowtotal);       
  574.         $smt->assign('title',"考勤统计表");
  575.         $smt->display('report_t7_t.htm');
  576.         exit;
  577. }

  578. //考勤轨迹查看       
  579. if($do=="t7tmap"){
  580.         If_rabc($action,$do); //检测权限
  581.        
  582.         //设置允许查询范围
  583.         $tt =  abs(strtotime($_GET['time_over']) - strtotime($_GET['time_start']))/86400;
  584.         if($tt>3 || $tt<0 || $_GET['time_over']=="" || $_GET['time_start']==""){exit("<span style="font-size:12px;color:red">时间范围只允许3日内,请关闭重选...</span>");}
  585.        
  586.         //判断检索范围
  587.         if($_GET['time_start'] && $_GET['time_over']){
  588.                 $search = " and `created_at` > '$_GET[time_start] 00:00:00' and `created_at`<  '$_GET[time_over] 23:59:59' ";
  589.                 $postdate = "<span class='t_title'>当前时间范围: [$_GET[time_start] 00:00:00] 到 [$_GET[time_over] 23:59:59]</span>";
  590.         }else{
  591.                 $postdate = "<span class='t_title'>当前时间范围:全部时间</span>";
  592.         }
  593.        
  594.         //sql按用户
  595.         $sql ="SELECT id,username FROM `rv_user` where id = {$id} limit 1";
  596.         $db->query($sql);
  597.         $rowuser=$db->fetchRow();
  598.        
  599.         //sql按用户
  600.         $sql ="SELECT * FROM `rv_track` where salesid = {$id} {$search} order by id asc";
  601.         $db->query($sql);
  602.         $list=$db->fetchAll();
  603.         $i=1;
  604.         foreach($list as $key=>$val){
  605.                 $list[$key][number] = $i;
  606.                 $list[$key][number2] = $i+1;
  607.                 $list[$key][salesid_txt] = $user_list[$list[$key][salesid]];
  608.                 $i++;
  609.         }
  610.        
  611.         //模版
  612.         $smt = new smarty();smarty_cfg($smt);
  613.         $smt->assign('list',$list);       
  614.         $smt->assign('postdate',$postdate);
  615.         $smt->assign('numberindex',count($list));
  616.         $smt->assign('username',$rowuser[username]);
  617.         $smt->assign('title',"考勤轨迹查看");
  618.         $smt->display('report_t7_t_map.htm');
  619.         exit;
  620. }

  621. ?>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|11wo.com

Copyright © 2001-2013 Comsenz Inc.Template by Comsenz Inc.All Rights Reserved.

Powered by Discuz!X3.4( 备案号:桂ICP备18000909号-1 )QQ

快速回复 返回顶部 返回列表