php 总结(14) 每个客服当月每天的资料查询,多重数组查询
思路
涉及到多重数组,当用户选择那一个月,某一个客服的时候 客服 当月每天 以及总的资料查询。
1.一个月内每天的时间戳生成数组:
for($i=0;$i<$j;$i++){
$date_array[] =array($start_time+$i*86400,$start_time+($i+1)*86400);
//每隔一天赋值给数组
}
$date_array[99]=array($thismonth_begin,$thismonth_end);
2.查询这个月内有数据的客服:
$kefu[] = $db->query("select distinct author,count(author) as ca from $table where status=1 and part_id=2 and $at>=$lastmonth_end and $at<=$thismonth_end group by author order by ca ", "", "author");;
$kefu[2][99]="ALL";
ALL是所有客服一起的资料
可以用这个数组 循环生成单选列表
foreach ($kefu[2] as $k => $v){
echo "<option value='{$v}'";
if ($v==$kefus) {
echo "selected=''";
}
echo">{$v}</option>";
}
?>
3.数据查询 ,循环遍历时间戳数组,获取开始和结束值
foreach ($date_array as $tname => $t) {
$b = $t[0];
$e = $t[1];
$tname=$tname+1;
// 每一天总潜在
// $data[$ptid][$tname+1]["dayall"] = $d1 = $db->query("select count(*) as c from $table where part_id=$ptid and $at>=$b and $at<=$e", 1, "c");
// 每天每个客服潜在:
$data[$tname]["all"] = $d2 = $db->query("select count(*) as c from $table where $at>=$b and $at<=$e $pp", 1, "c");
// 每天每个客服预约:
$data[$tname]["yuyue"] = $d3 = $db->query("select count(*) as c from $table where zhuanjia_num >1 $pp and $at>=$b and $at<=$e", 1, "c");
// 每天每个客服本地预约:
$data[$tname]["byuyue"] = $db->query("select count(*) as c from $table where area='本市' and zhuanjia_num >1 $pp and $at>=$b and $at<=$e", 1, "c");
$data[$tname]["yiq"]= round($d5 / $d2 ,2)*100 ."%" ;
$data[$tname]["yuq"]= round($d4 / $d2 ,2)*100 ."%";
// 已到:
// $data[$ptid][$kf][$tname+1]["come"] = $d6 = $db->query("select count(*) as c from $table where and author='$kf' and $tf>=$b and $tf<=$e and status=1", 1, "c");
// 未到:
// $data[$ptid][$kf][$tname+1]["leave"] = $d1 - $d2;
// }
// }
}
4.判断哪个客服 还是所有客服 根据GET获取的 月份=》更新月份数组和 客服=》更新$pp的值 ,生成数据
if ( $kefus=='ALL') {
$pp="";
}else{
$pp="and author='{$kefus}'";
}
5.用layui 前端展示数据
foreach($data as $k=>$v) {
echo "<tr>";
echo "<td> $k </td>";
echo "<td>"; echo $v['all']; echo "</td>";
echo "<td>"; echo $v['yuyue']; echo "</td>";
echo "<td>"; echo $v['wyudao']; echo "</td>";
// }
// 展示结束
echo "</tr>";
// }
}
?>
总结 尽量用一个数组 搞定所有要展示的数据,一个数组可以 分项包含数组 以便更好展示
if ( $kefus=='ALL') {
$pp="";
}else{
$pp="and author='{$kefus}'";
}
echo "<br>";
foreach ($date_array as $tname => $t) {
$b = $t[0];
$e = $t[1];
$tname=$tname+1;
// 每一天总潜在
// $data[$ptid][$tname+1]["dayall"] = $d1 = $db->query("select count(*) as c from $table where part_id=$ptid and $at>=$b and $at<=$e", 1, "c");
// 每天每个客服潜在:
$data[$tname]["all"] = $d2 = $db->query("select count(*) as c from $table where $at>=$b and $at<=$e $pp", 1, "c");
// 每天每个客服预约:
$data[$tname]["yuyue"] = $d3 = $db->query("select count(*) as c from $table where zhuanjia_num >1 $pp and $at>=$b and $at<=$e", 1, "c");
// 每天每个客服本地预约:
$data[$tname]["byuyue"] = $db->query("select count(*) as c from $table where area='本市' and zhuanjia_num >1 $pp and $at>=$b and $at<=$e", 1, "c");
$data[$tname]["wyuyue"] = $db->query("select count(*) as c from $table where area <> '本市' and zhuanjia_num >1 $pp and $at>=$b and $at<=$e", 1, "c");
// 每天每个客服预到:
$data[$tname]["yudao"] = $d4 = $db->query("select count(*) as c from $table where $tf between $b and $e $pp ", 1, "c");
// 每天每个客服本地遇到:
$data[$tname]["byudao"] = $db->query("select count(*) as c from $table where area='本市' and $tf between $b and $e $pp ", 1, "c");
$data[$tname]["wyudao"] = $db->query("select count(*) as c from $table where area <> '本市' and $tf between $b and $e $pp ", 1, "c");
// 每天每个客服已到:
$data[$tname]["yidao"] = $d5 = $db->query("select count(*) as c from $table where status =1 and $tf between $b and $e $pp ", 1, "c");
// 每天每个客服本地已:
$data[$tname]["byidao"] = $db->query("select count(*) as c from $table where status =1 and area='本市' and $tf between $b and $e $pp ", 1, "c");
$data[$tname]["wyidao"] = $db->query("select count(*) as c from $table where status =1 and area <> '本市' and $tf between $b and $e $pp ", 1, "c");
if ($d2 <=0) {
$d2=1;
}
$data[$tname]["yiq"]= round($d5 / $d2 ,2)*100 ."%" ;
$data[$tname]["yuq"]= round($d4 / $d2 ,2)*100 ."%";
// 已到:
// $data[$ptid][$kf][$tname+1]["come"] = $d6 = $db->query("select count(*) as c from $table where and author='$kf' and $tf>=$b and $tf<=$e and status=1", 1, "c");
// 未到:
// $data[$ptid][$kf][$tname+1]["leave"] = $d1 - $d2;
// }
// }
}
更多精彩

