<?php
namespace app\home\controller;

use think\Lang;
use think\Validate;

class Visitkf extends AdminControl
{
   public function index(){
   	    $erwh = array();
        $erwh['service_pid'] = session('service_pid');
        $allkf = Model('service')->allkef($erwh, $field = 'service_id,service_nickname');//所有客服
        
        if(request()->isPost()){
            $lyaddtime = $_POST['lyaddtime'];
        }else{
            $lyaddtime = 0;
        }

        if($lyaddtime==1){
            $kstime = strtotime(date("Y-m-d 23:59:59",strtotime("-3 day")));
        }elseif($lyaddtime==2){
            $kstime = strtotime(date("Y-m-d 23:59:59",strtotime("-1 week")));
        }elseif($lyaddtime==3){
            $kstime = strtotime(date("Y-m-d",strtotime("-1 month")));
        }else{
            $kstime = "1546272000";
        }
        $endtime = TIMESTAMP;

        if (input('post.kstime')) {
            $kstime = strtotime(input('post.kstime'));
        }
        if (input('post.endtime')) {
            $endtime = strtotime(input('post.endtime'));
        }

        $readok = input('post.record_readok');
   	    $model_chatlog = Model('Chatlog');
   		$condition = array();   
        if($readok){
            $condition['sid'] = $readok;
        }
        $condition['create_time'] = array('between', array($kstime, $endtime));
        
        $condition['uid'] = session('service_pid');
        $condition['type'] = 2;
        $visitorlist = $model_chatlog->getChatlogList($condition,$field = '',10);
        
        if($visitorlist){
            //所属客服
            for ($i=0; $i < count($visitorlist); $i++) { 
                $sere['service_id'] = $visitorlist[$i]["sid"];
                $kflist[] = db('service')->field('service_nickname')->where($sere)->find();
            }
            $this->assign('kflist',$kflist);
        }

        $this->assign('visitorlist',$visitorlist);
        $this->assign('lyaddtime',$lyaddtime);
        $this->assign('show_page', $model_chatlog->page_info->render());
        $this->assign('allkf',$allkf);
		$this->setAdminCurItem('index');
        return $this->fetch();
   }

}
