Glservice.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. class Glservice extends AdminControl
  5. {
  6. const EXPORT_SIZE = 5000;
  7. /**
  8. * 客服统计
  9. * @return mixed
  10. */
  11. public function index(){
  12. $srwh = array();
  13. $srwh['suosgs'] = session('service_pid');
  14. $gskefz =Model('Admingroup')->getAdminGroupList($srwh,'group_id,group_name');//公司所有客服组
  15. $readok = input('post.kefu_keywords');
  16. $kefuz = input('post.record_readok');
  17. $model_service = Model('Service');
  18. $condition = array();
  19. if($readok){
  20. $condition['service_name'] = $readok;
  21. }
  22. if($kefuz){
  23. $condition['service_group_id'] = $kefuz;
  24. }
  25. $condition['service_pid'] = session('service_pid');
  26. $kefulist = $model_service->getServiceList($condition,$field = '',10);
  27. if($kefulist){
  28. //所属权限组
  29. for ($i=0; $i < count($kefulist); $i++) {
  30. $ner['group_id'] = $kefulist[$i]['service_group_id'];
  31. $sqxz[] = Model('Admingroup')->getOneAdmingroup($ner,'group_name');
  32. }
  33. $this->assign('sqxz',$sqxz);
  34. //客服满意率
  35. for ($ie=0; $ie < count($kefulist); $ie++) {
  36. $ser['sid'] = $kefulist[$ie]['service_id'];
  37. $kfrate[] = Model('Chatlog')->chatlogcoRate($ser);
  38. }
  39. $this->assign('kfrate',$kfrate);//客服满意率
  40. //客服挽留率
  41. for ($i=0; $i < count($kefulist); $i++) {
  42. $wer['sid'] = $kefulist[$i]['service_id'];
  43. $wlrate[] = Model('Chatlog')->chatlogDetainment($wer);
  44. }
  45. $this->assign('wlrate',$wlrate);
  46. //客服转化率
  47. for ($i=0; $i < count($kefulist); $i++) {
  48. $ler['sid'] = $kefulist[$i]['service_id'];
  49. $zhrate[] = Model('Chatlog')->chatlogConversion($ler);
  50. }
  51. $this->assign('zhrate',$zhrate);
  52. }
  53. $this->assign('gskefz',$gskefz);
  54. $this->assign('kefulist',$kefulist);
  55. $this->assign('show_page', $model_service->page_info->render());
  56. $this->setAdminCurItem('index');
  57. return $this->fetch();
  58. }
  59. /**
  60. * 导出第一步
  61. */
  62. public function export_step1()
  63. {
  64. $model_service = Model('Service');
  65. $condition = array();
  66. $condition['service_pid'] = session('service_pid');
  67. $kefulist = $model_service->getServiceList($condition,$field = '',10);
  68. $count = db('Service')->where($condition)->count();
  69. if (!is_numeric(input('param.curpage'))) {
  70. $count = db('Service')->where($condition)->count();
  71. $array = array();
  72. if ($count > self::EXPORT_SIZE) { //显示下载链接
  73. $page = ceil($count / self::EXPORT_SIZE);
  74. for ($i = 1; $i <= $page; $i++) {
  75. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  76. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  77. $array[$i] = $limit1 . ' ~ ' . $limit2;
  78. }
  79. $this->assign('list', $array);
  80. $this->assign('murl', url('adminlog/list'));
  81. return $this->fetch('excel');
  82. }else{
  83. //如果数量小,直接下载
  84. $data = db('Service')->where($condition)->order('service_id desc')->limit(self::EXPORT_SIZE)->select();
  85. if($kefulist){
  86. for ($ie=0; $ie < count($kefulist); $ie++) {
  87. $ser['sid'] = $kefulist[$ie]['service_id'];
  88. $kfrate[] = Model('Chatlog')->chatlogcoRate($ser);
  89. }//客服满意率
  90. for ($i=0; $i < count($kefulist); $i++) {
  91. $wer['sid'] = $kefulist[$i]['service_id'];
  92. $wlrate[] = Model('Chatlog')->chatlogDetainment($wer);
  93. }//客服挽留率
  94. for ($i=0; $i < count($kefulist); $i++) {
  95. $ler['sid'] = $kefulist[$i]['service_id'];
  96. $zhrate[] = Model('Chatlog')->chatlogConversion($ler);
  97. }//客服转化率
  98. }
  99. $this->createExcel($data,$kfrate,$wlrate,$zhrate);
  100. }
  101. }else{
  102. //下载
  103. $limit1 = (input('param.curpage') - 1) * self::EXPORT_SIZE;
  104. $limit2 = self::EXPORT_SIZE;
  105. $data = db('Service')->where($condition)->order('service_id desc')->limit("{$limit1},{$limit2}")->select();
  106. $this->createExcel($data);
  107. }
  108. }
  109. /**
  110. * 生成excel
  111. *
  112. * @param array $data
  113. */
  114. private function createExcel($data = array(),$kfrate,$wlrate,$zhrate)
  115. {
  116. $excel_obj = new \excel\Excel();
  117. $excel_data = array();
  118. //设置样式
  119. $excel_obj->setStyle(array(
  120. 'id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')
  121. ));
  122. //header
  123. $excel_data[0][] = array('styleid' => 's_title', 'data' => "客服名");
  124. $excel_data[0][] = array('styleid' => 's_title', 'data' => "满意率(百分比)");
  125. $excel_data[0][] = array('styleid' => 's_title', 'data' => "转化率(百分比)");
  126. $excel_data[0][] = array('styleid' => 's_title', 'data' => "挽留率(百分比)");
  127. foreach ((array)$data as $k => $v) {
  128. $tmp = array();
  129. $tmp[] = array('data' => $v['service_name']);
  130. $tmp[] = array('data' => $kfrate[$k] .'%');
  131. $tmp[] = array('data' => $wlrate[$k] .'%');
  132. $tmp[] = array('data' => $zhrate[$k] .'%');
  133. $excel_data[] = $tmp;
  134. }
  135. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  136. $excel_obj->addArray($excel_data);
  137. $excel_obj->addWorksheet($excel_obj->charset(lang('admin_log'), CHARSET));
  138. $excel_obj->generateXML($excel_obj->charset(lang('admin_log'), CHARSET) . input('param.curpage') . '-' . date('Y-m-d-H', time()));
  139. }
  140. }