Jobcv.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Lang;
  4. use think\Validate;
  5. class Jobcv extends AdminControl
  6. {
  7. public function _initialize()
  8. {
  9. parent::_initialize();
  10. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/jobcv.lang.php');
  11. }
  12. /**
  13. * 聊天历史管理
  14. */
  15. public function index()
  16. {
  17. $model_chatlog = Model('Chatlog');
  18. $erwh = array();
  19. $allkf = Model('service')->allkef($erwh = array(), $field = 'service_id,service_name');//所有客服
  20. if(request()->isPost()){
  21. $lyaddtime = $_POST['lyaddtime'];
  22. }else{
  23. $lyaddtime = 0;
  24. }
  25. if($lyaddtime==1){
  26. $kstime = strtotime(date("Y-m-d 23:59:59",strtotime("-3 day")));
  27. }elseif($lyaddtime==2){
  28. $kstime = strtotime(date("Y-m-d 23:59:59",strtotime("-1 week")));
  29. }elseif($lyaddtime==3){
  30. $kstime = strtotime(date("Y-m-d",strtotime("-1 month")));
  31. }else{
  32. $kstime = "1546272000";
  33. }
  34. $endtime = TIMESTAMP;
  35. if (input('post.kstime')) {
  36. $kstime = strtotime(input('post.kstime'));
  37. }
  38. if (input('post.endtime')) {
  39. $endtime = strtotime(input('post.endtime'));
  40. }
  41. $readok = input('post.record_readok');
  42. $uid = input('post.record_uid');
  43. $condition = array();
  44. $condition['create_time'] = array('between', array($kstime, $endtime));
  45. if($readok){
  46. $condition['sid'] = $readok;
  47. }
  48. if($uid){
  49. $condition['uid'] = $uid;
  50. }
  51. $record_list = $model_chatlog->getChatlogList($condition, '*', 10);
  52. if($record_list){
  53. for ($i=0; $i < count($record_list); $i++) {
  54. $where[' log_id'] = $record_list[$i]["id"];
  55. $list[] = db('chat_message')->field('id,create_time,from')->where($where)->select();
  56. }
  57. if(!empty($list)){
  58. for ($ii=0; $ii < count($list); $ii++) {
  59. for ($ie=0; $ie < count($list[$ii]); $ie++) {
  60. $who['id'] = $list[$ii][$ie]["id"];
  61. $cjtime[] = date("Y-m-d H:i:s",$list[$ii][$ie]["create_time"]);
  62. $conlist[] = db('chat_message_content')->where($who)->find();
  63. }
  64. }
  65. }
  66. $this->assign('conlist',$conlist);
  67. //所属公司
  68. for ($i=0; $i < count($record_list); $i++) {
  69. $ere['member_id'] = $record_list[$i]["uid"];
  70. $gslist[] = db('member')->field('member_name')->where($ere)->find();
  71. }
  72. $this->assign('gslist',$gslist);
  73. //所属客服
  74. for ($i=0; $i < count($record_list); $i++) {
  75. $sere['service_id'] = $record_list[$i]["sid"];
  76. $kflist[] = db('service')->field('service_name')->where($sere)->find();
  77. }
  78. $this->assign('kflist',$kflist);
  79. }
  80. $allgs = Model('member')->allcompany('');
  81. $allpower = $this->qxhans();
  82. $this->assign('allgs',$allgs);
  83. $this->assign('allpower',$allpower);
  84. $this->assign('record_list', $record_list);
  85. $this->assign('lyaddtime',$lyaddtime);
  86. $this->assign('endtime',$endtime);
  87. $this->assign('kstime',$kstime);
  88. $this->assign('show_page', $model_chatlog->page_info->render());
  89. $this->assign('allkf',$allkf);
  90. $this->setAdminCurItem('index');
  91. return $this->fetch();
  92. }
  93. //客服下的访问客户
  94. public function kfvisitor(){
  95. $pid = $_GET['uid'];//客服id
  96. $kflist = model('Chatlog');
  97. $visitorlist = $kflist->allvisitor($pid);
  98. echo json_encode($visitorlist);
  99. }
  100. //客服客户聊天内容
  101. public function chatcontent(){
  102. $sid = $_GET['forWhat'];//客服id
  103. $kname = $_GET['kname'];//客户名
  104. $type = $_GET['type'];
  105. $choicetime = $_GET['choicetime'];
  106. if($type=="nearWeek"){
  107. $begin = strtotime(date('Y-m-d', strtotime('-7 days')));
  108. }else{
  109. $begin = strtotime("-0 year -1 month -0 day");
  110. }
  111. $end = TIMESTAMP;
  112. if(!empty($choicetime)){
  113. $gap = explode(' - ', $choicetime);
  114. $begin = strtotime($gap[0]);
  115. $end = strtotime($gap[1]);
  116. }
  117. $ltlist = model('Chatlog');
  118. $ltjt = $ltlist->chatdata($begin,$end,$kname,$sid);
  119. if($ltjt){
  120. for ($i=0; $i < count($ltjt); $i++) {
  121. $where[' log_id'] = $ltjt[$i]["id"];
  122. $list[] = db('chat_message')->field('id,create_time,from')->where($where)->select();
  123. }
  124. if(!empty($list)){
  125. for ($i=0; $i < count($list); $i++) {
  126. for ($ie=0; $ie < count($list[$i]); $ie++) {
  127. $who['id'] = $list[$i][$ie]["id"];
  128. $cjtime[] = date("Y-m-d H:i:s",$list[$i][$ie]["create_time"]);
  129. $conlist[] = db('chat_message_content')->where($who)->find();
  130. }
  131. }
  132. }
  133. }
  134. if(!empty($cjtime) && !empty($conlist) && !empty($kname)){
  135. $array = array(
  136. 'list'=>$list,
  137. 'cjtime'=>$cjtime,
  138. 'conlist'=>$conlist,
  139. 'kname'=>$kname,
  140. );
  141. }else{
  142. $array = array(
  143. 'list'=>'',
  144. 'cjtime'=>'',
  145. 'conlist'=>'',
  146. 'kname'=>'',
  147. );
  148. }
  149. echo json_encode($array);
  150. }
  151. protected function getAdminItemList()
  152. {
  153. $menu_array = array(
  154. array(
  155. 'name' => 'index', 'text' => lang('ds_manage'), 'url' => url('jobcv/index')
  156. )
  157. );
  158. return $menu_array;
  159. }
  160. }
  161. ?>