<?php
/**
 * 大屏专用lib
 *
 * ============================================================================
 * 版权所有 2019北京素玄科技，并保留所有权利。
 *
 * 网站地址: http://www.suxuantech.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！未经允许的情况下，您不能对本系统代码做任何修改 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * 如有修改需求，请联系素玄科技有限公司：contact@suxuantech.cn
 * ============================================================================
 */
namespace app\crm\lib;
use think\Controller;

class Sunbeibei extends Controller{

    // 渠道入客
    public function ChannelGuest($where='1=1'){
        $time_start = date('Y-m-01 00:00:00', time());
        $time_end = $this->today();//date('Y-m-t 23:59:59', time());
        $year = date('Y');
        $month = date('m');
        $day_sum = cal_days_in_month(CAL_GREGORIAN, $month, $year);
        $res = db('c_customerinfo')->field('LEFT(dj_day,10) as day_t,count(id) as id_count')->where($where)->where("dj_day",">","$time_start")->where("dj_day","<","$time_end")->where('is_status',1)->group('LEFT(dj_day,10)')->select();
        $data = array();
        for($i=1; $i<=$day_sum; $i++){
            foreach ($res as $k => $val) {
                $ii = strlen($i) == 1 ? "0".$i : $i;
                $tim = $year."-".$month."-".$ii;
                if ($tim == $val['day_t']) {
                    $data[$i] = $val['id_count'];
                }
            }
            if (!$data[$i]) {
                $data[$i] = '';
            }
        }
        return $data;
    } 
    // 入客  的 月总
    public function ChannelGuests($where='1=1'){
        $time_start = date('Y-m-01 00:00:00', time());
        $time_end = $this->today();//date('Y-m-t 23:59:59', time());
        $res = db('c_customerinfo')->field('count(id) as id_count')->where($where)->where("dj_day",">","$time_start")->where("dj_day","<","$time_end")->where('is_status',1)->select();

        return $res;
    } 
    // 大屏专用  判断  该员工是否有权限查看大屏数据
    public function checkBigScreenAuth(){
        // 获取配置文件中的信息，根据,分割成数组，如果staff_id不存在，则跳转到登录或首页
        $staff_id = session('staff_id');
        $str_id = config('bigScreen_id');
        $bigScreen_id = explode(',', $str_id);
        $is_in = in_array($staff_id, $bigScreen_id);
        if ($is_in === false) {
            // controller('crm/Index','controller')->index();
            // exit;
            return false;
        }else{
            return true;
        }
    }
    //时间
    public function today(){
        $t = date('t');
        $tim = strtotime('17:30:00');
        $time = time();
        if ($time >= $tim || $t == 01|| $t == 1) {
            $today = date('Y-m-t 23:59:59');
        }else{
            $today = date("Y-m-d 23:59:59",strtotime("-1 day"));
        }
        return $today;
    }

}