<?php
/**
 * CRM 基本模块  呼叫中心控制器
 * 默认接口方法，此方法内定议基础框架所需要的方法，用于验证模块合法性，模块版本，对接基础架构中需要的方法
 *
 * ============================================================================
 * 版权所有 2017北京素玄科技，并保留所有权利。
 *
 * 网站地址: http://www.suxuantech.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！未经允许的情况下，您不能对本系统代码做任何修改 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * 如有修改需求，请联系素玄科技有限公司：contact@suxuantech.cn
 * ============================================================================
 * $Author: wzy<songdemei@suxuantech.cn> 2017-09-21 $
 */
namespace app\crm\controller;
use think\Cache;
use app\index\controller\Base;
use think\Exception;
use think\Controller;
class Call extends Base{
    //坐席列表
    public function callList(){
        return $this->fetch();
    }
    public function callListData(){
        if(check_right('menu1512637269')) {//查看所有客资权限
            $info = db('s_call_man')->where('shop_code',session('shop_code'))->order('status,is_busy desc')->select();
        }elseif(check_right('menu1531471639')) {//查看部门客资权限
            $info = db('s_call_man')->where('group_id',session('group_id'))->order('status,is_busy desc')->select();
        }elseif(check_right('menu1529653231')) {//查看小组客资权限
            $info = db('s_call_man')->where('department_id',session('department_id'))->order('status,is_busy desc')->select();
        }
        foreach($info as $k=>$v){
            if($v['is_busy'] == 1){
                $tel = cache('tel_'.session('staff_id'));
                $tel = '13515303738';
                $cusInfo = db('c_customerinfo')->where('customer_tel|mate_tel','13515303738')->where('is_status',1)->order('id desc')->field('id,customer_name,customer_tel,mate_tel')->find();
                $info[$k]['customer_id'] = $cusInfo['id'];
                $info[$k]['customer_name'] = $cusInfo['customer_name'];
                $info[$k]['customer_tel'] = $cusInfo['customer_tel'] ? $cusInfo['customer_tel'] : $cusInfo['mate_tel'];
                $info[$k]['guid'] = cache('guid_'.$tel);
            }
        }
        $result['code'] = 0;
        $result['msg'] = '';
        $result['count'] = count($info);
        $result['data'] = $info;
        return json($result);
    }
}