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

class Juzi extends Controller{
    protected  $tgshop = 'WX001';//市场营销中心
    protected  $shop_code = 'WX002';//网销中心
    protected  $zjsshop = 'WX003';// 转介绍中心
    protected  $jkcource = "电商,网销";//
    protected  $store = "'JZ001','JZ002','JZ005'";//门店
    protected  $base = "'JZ003','JZ004'";//基地
    protected  $zjsChannel = "'闵行门市部','徐汇门市部','静安门市部','静安门市2部','静安门市1部','静安前台'";
    // 静安渠道
    protected $jachannel = '静安门市部,静安门市1部,静安门市2部,静安前台';
    // 闵行渠道
    protected $mhchannel = '闵行门市部';
    // 徐汇渠道
    protected $xhchannel = '徐汇门市部';
    // 今天
    protected  $today = [
        'start'=>'', 'end'  =>'',
    ];
    // 昨天
    // protected  $yestoday = [
    //     'start'=>'', 'end'  =>'',
    // ];
    // 本月一号和当天
    protected  $thisMonth = [
        'start'=>'', 'end'  =>'',
    ];
    // 本月每一天
    protected  $thisMonthAllDay = [];
    public function _initialize(){
        // 今天
        // $this->today['start']= date('2019-11-01 00:00:00');
        // $this->today['end']  = date('2019-11-30 23:59:59');
        $this->today['start']=  date('Y-m-d 00:00:00');
        $this->today['end']  =  date('Y-m-d 23:59:59');
        // 昨天
        $this->yestoday['start']= date('Y-m-d 00:00:00',strtotime('-1 day'));
        $this->yestoday['end']  = date('Y-m-d 23:59:59',strtotime('-1 day'));
        // 本月
        $this->thisMonth['start']= date('Y-m-01 00:00:00');
        $this->thisMonth['end']  = date('Y-m-d 23:59:59');
        // $this->thisMonth['start']= date('2019-11-01 00:00:00');
        // $this->thisMonth['end']  = date('2019-11-30 23:59:59');
        // 本月每一天
        $date = getdateArea('this_month');
        $timezone = getDateFromRange($date[0], $date[1]);
        $this->thisMonthAllDay = $timezone;
    }
    // public function _initialize(){}
    //-------------------------------------- 大屏pc端 开始 --------------------------------------//
        // 大屏页面  2018-03-11
        public function index(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                controller('crm/Index','controller')->index();
                exit;
            }
            // $no_bids = config('no_bigScreen_bid');
            // $no_bids = explode(',', $no_bids);
            
            // $brandList = controller('crm/Juzi', 'lib')->getBrandInfo();
            // foreach ($brandList as $key => $value) {
            //     if (in_array($value['id'], $no_bids)) {
            //         continue;
            //     }else{
            //         $baseBrand[$key]['brandclass_id'] = $value['id'];
            //         $baseBrand[$key]['brandclass']    = $value['brandclass'];
            //         if ($value['nickname']) {
            //             $baseBrand[$key]['nickname']  = $value['nickname'];
            //         }else{
            //             $baseBrand[$key]['nickname']  = $value['brandclass'];
            //         }
            //     }
            // }
            
            // $this->assign('baseBrand', $baseBrand);

            // 集团名称
            $gInfo = controller('crm/Juzi', 'lib')->getGName();
            $this->assign('title',$gInfo['group_company_name']);
            return $this->fetch();
        }

        // 移动端大屏
        public function mobile(){
            $get = input('get.sid');
            $sid = think_decrypt($get);
            session('staff_id', $sid);
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                controller('crm/Index','controller')->index();
                exit;
            }

            // $no_bids = config('no_bigScreen_bid');
            // $no_bids = explode(',', $no_bids);
            
            // $brandList = controller('crm/Juzi', 'lib')->getBrandInfo();
            // foreach ($brandList as $key => $value) {
            //     if (in_array($value['id'], $no_bids)) {
            //         continue;
            //     }else{
            //         $baseBrand[$key]['brandclass_id'] = $value['id'];
            //         $baseBrand[$key]['brandclass']    = $value['brandclass'];
            //         if ($value['nickname']) {
            //             $baseBrand[$key]['nickname']  = $value['nickname'];
            //         }else{
            //             $baseBrand[$key]['nickname']  = $value['brandclass'];
            //         }
            //     }
            // }
            // $this->assign('baseBrand', $baseBrand);

            // 集团名称
            $gInfo = controller('crm/Juzi', 'lib')->getGName();
            $this->assign('title',$gInfo['group_company_name']);
            return $this->fetch();
        }

        // 页面基础数据
        public function baseData(){
            // echo 'START==>'.microtime(true).'<br />';     
            // 权限
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                controller('crm/Index','controller')->index();
                exit;
            }

            //本月
            $mdate = getdateArea('this_month');
            $mData['start'] = date('Y-m-d 00:00:00',strtotime($mdate[0]));
            $mData['end']   = date('Y-m-d 23:59:59');
            //今天
            $tData['start'] = date('Y-m-d 00:00:00');
            $tData['end']   = date('Y-m-d 23:59:59');
            //昨日
            $yData['start'] = date('Y-m-d 00:00:00',strtotime('-1 day'));
            $yData['end'] = date('Y-m-d 23:59:59',strtotime('-1 day'));
            $where['is_status']= 1;
            $where['c_from']   = 1;

            $sql  = 'sum(dj_day between "'.$tData['start'].'" and "'.$tData['end'].'") as mkz,';
            $sql .= 'sum(dj_day between "'.$tData['start'].'" and "'.$tData['end'].'" and is_valid<>3) as valid,';
            $sql .= 'sum(dj_day between "'.$tData['start'].'" and "'.$tData['end'].'" and is_valid=3) as unvalid,';
            $sql .= 'sum(yjd_day between "'.$tData['start'].'" and "'.$tData['end'].'") as yjd,';
            $sql .= 'sum(syjd_day between "'.$tData['start'].'" and "'.$tData['end'].'" and is_intostore in (2,3)) as jd,';
            $sql .= 'sum(order_day between "'.$tData['start'].'" and "'.$tData['end'].'" and is_success=1) as xd,';
            $sql .= 'sum(order_day between "'.$tData['start'].'" and "'.$tData['end'].'" and is_success=1 and order_type=1) as oxd';
            
            $cacheKey = 'bgscreen_data_mobile_infoDay';
            if(cache('?'.$cacheKey)){
                $infoDay = cache($cacheKey);
            }else{
                $infoDay = db('c_customerinfo')
                ->where($where)
                ->field($sql)
                ->find();
                cache($cacheKey,$infoDay,60);
            }
            $infoDay['validRate'] = number_format(($infoDay['valid'] / $infoDay['mkz'])*100,2).'%';
            $infoDay['unvalidRate'] = number_format(($infoDay['unvalid'] / $infoDay['mkz'])*100,2).'%';
            $infoDay['jdRate'] = number_format(($infoDay['jd'] / $infoDay['mkz'])*100,2).'%';
            $infoDay['xdRate'] = number_format(($infoDay['xd'] / $infoDay['mkz'])*100,2).'%';
            foreach ($infoDay as $key => $value) {
                $infoDay[$key] = $value ? $value : '0';
            }

            $sql  = 'sum(dj_day between "'.$mData['start'].'" and "'.$mData['end'].'") as mkz,';
            $sql .= 'sum(dj_day between "'.$mData['start'].'" and "'.$mData['end'].'" and is_valid<>3) as valid,';
            $sql .= 'sum(dj_day between "'.$mData['start'].'" and "'.$mData['end'].'" and is_valid=3) as unvalid,';
            $sql .= 'sum(yjd_day between "'.$mData['start'].'" and "'.$mData['end'].'") as yjd,';
            $sql .= 'sum(syjd_day between "'.$mData['start'].'" and "'.$mData['end'].'" and is_intostore in (2,3)) as jd,';
            // 
            $sql .= 'sum(order_day between "'.$mData['start'].'" and "'.$mData['end'].'" and is_success=1) as xd,';
            $sql .= 'sum(order_day between "'.$mData['start'].'" and "'.$mData['end'].'" and is_success=1 and order_type=1) as oxd';
            $cacheKey = 'bgscreen_data_mobile_infoMonth';
            if(cache('?'.$cacheKey)){
                $infoMonth = cache($cacheKey);
            }else{
                $infoMonth = db('c_customerinfo')
                ->where($where)
                ->field($sql)
                ->find();
                cache($cacheKey,$infoMonth,60);
            }
            $infoMonth['validRate'] = number_format(($infoMonth['valid'] / $infoMonth['mkz'])*100,2).'%';
            $infoMonth['unvalidRate'] = number_format(($infoMonth['unvalid'] / $infoMonth['mkz'])*100,2).'%';
            $infoMonth['jdRate'] = number_format(($infoMonth['jd'] / $infoMonth['mkz'])*100,2).'%';
            $infoMonth['xdRate'] = number_format(($infoMonth['xd'] / $infoMonth['mkz'])*100,2).'%';
            foreach ($infoMonth as $key => $value) {
                $infoMonth[$key] = $value ? $value : '0';
            }

            //推广客资月数据，计算月度成本
            //$infoDsMonth = controller('crm/Juzi', 'lib')->getKZNumber(['start'=>$mData['start'],'end'=>$mData['end'],'add_shop_code'=>'WX001']);

            $cacheKey = 'bgscreen_data_mobile_infoDsMonth';
            if(cache('?'.$cacheKey)){
                $infoDsMonth = cache($cacheKey);
            }else{
                $infoDsMonth = controller('crm/Juzi', 'lib')->getKZNumber(['start'=>$mData['start'],'end'=>$mData['end'],'add_shop_code'=>'WX001']);
                cache($cacheKey,$infoDsMonth,60);
            }

            ////推广客资昨日数据，计算昨日成本
            $cacheKey = 'bgscreen_data_mobile_infoDsYDay';
            if(cache('?'.$cacheKey)){
                $infoDsYDay = cache($cacheKey);
            }else{
                $infoDsYDay = controller('crm/Juzi', 'lib')->getKZNumber(['start'=>$yData['start'],'end'=>$yData['end'],'add_shop_code'=>'WX001']);
                cache($cacheKey,$infoDsYDay,3600);
            }

            //推广费用--昨日
            $cacheKey = 'bgscreen_data_mobile_costMoneyY';
            if(cache('?'.$cacheKey)){
                $costMoneyY = cache($cacheKey);
            }else{
                $costMoneyY = controller('crm/Juzi', 'lib')->costMoney($yData);
                cache($cacheKey,$costMoneyY,3600);
            }
            //昨日订单数据--参与相关成本计算以及ROI
            $condy = [
                'start'=>$yData['start'],
                'end'=>$yData['end'],
                'type'=>'shop',
                'add_shop_code'=>['WX001']
            ];
            $cacheKey = 'bgscreen_data_mobile_orderAmountYDS';
            if(cache('?'.$cacheKey)){
                $orderAmountYDS = cache($cacheKey);
            }else{
                $orderAmountYDS = controller('crm/Juzi', 'lib')->dealMoneyCustomer($condy);
                cache($cacheKey,$orderAmountYDS,3600);
            }

            // 推广费用-月度（渠道花费）
            //$costMoneyT = controller('crm/Juzi', 'lib')->costMoney($tData);
            
            $cacheKey = 'bgscreen_data_mobile_costMoneyM';
            if(cache('?'.$cacheKey)){
                $costMoneyM = cache($cacheKey);
            }else{
                $costMoneyM = controller('crm/Juzi', 'lib')->costMoney($mData);
                cache($cacheKey,$costMoneyM,300);
            }
            //当月的订单总数据，用于显示月订单数据，不参与ROI或相关成本计算
            $cacheKey = 'bgscreen_data_mobile_orderAmountM';
            if(cache('?'.$cacheKey)){
                $orderAmountM = cache($cacheKey);
            }else{
                $orderAmountM = controller('crm/Juzi', 'lib')->dealMoneyCustomer($mData);
                cache($cacheKey,$orderAmountM,300);
            }

            $infoMoney['cost'] = round($costMoneyY['cost']).' / '.round($costMoneyM['cost']);
            // 套系总额 （营收）
            // $orderAmountT = controller('crm/Juzi', 'lib')->dealMoney($tData);
            // $orderAmountM = controller('crm/Juzi', 'lib')->dealMoney($mData);
            
            $orderAmountT = controller('crm/Juzi', 'lib')->dealMoneyCustomer($tData);
            
            //电商的相关收入和订单
            $condm = [
                'start'=>$mData['start'],
                'end'=>$mData['end'],
                'type'=>'shop',
                'add_shop_code'=>['WX001']
            ];

            $cacheKey = 'bgscreen_data_mobile_orderAmountMDS';
            if(cache('?'.$cacheKey)){
                $orderAmountMDS = cache($cacheKey);
            }else{
                $orderAmountMDS = controller('crm/Juzi', 'lib')->dealMoneyCustomer($condm);
                cache($cacheKey,$orderAmountMDS,300);
            }
            
            $infoMoney['orderAmount'] = round($orderAmountT['totalpay_money']).' / '.round($orderAmountM['totalpay_money']);
            // 实际收款 （实收）--orderAmount*
            // $orderFactT = controller('crm/Juzi', 'lib')->incomeMoney($tData);
            // $orderFactM = controller('crm/Juzi', 'lib')->incomeMoney($mData);

            $infoMoney['orderFact'] = round($orderAmountT['fact_money']).' / '.round($orderAmountM['fact_money']);
            /*
                获取成本        mkzCost
                有效成本        validCost
                进店成本        jdCost
                成交成本        xdCost      
                成交均价        amountAvg   套系总额/单量
                营收            orderAmount 套系总额
                实收            orderFact   实际收款
                ROI             ROI         花费/实收
            */
            $infoMoney['mkzCost']  = round($costMoneyY['cost']/$infoDsYDay['mkz']).' / '.round($costMoneyM['cost']/$infoDsMonth['mkz']);
            $infoMoney['validCost']= round($costMoneyY['cost']/$infoDsYDay['valid']).' / '.round($costMoneyM['cost']/$infoDsMonth['valid']);
            $infoMoney['jdCost']   = round($costMoneyY['cost']/$infoDsYDay['jd']).' / '.round($costMoneyM['cost']/$infoDsMonth['jd']);
            $infoMoney['xdCost']   = round($costMoneyY['cost']/$infoDsYDay['xd']).' / '.round($costMoneyM['cost']/$infoDsMonth['xd']);
            $infoMoney['amountAvg']= number_format($orderAmountT['totalpay_money']/$infoDay['xd'], 2).' / '.number_format($orderAmountM['totalpay_money']/$infoMonth['xd'], 2);
            $infoMoney['ROI']      = number_format($orderAmountYDS['totalpay_money']/$costMoneyY['cost'], 2).' / '.number_format($orderAmountMDS['totalpay_money']/$costMoneyM['cost'], 2);
            $infoMoney['mkzCost']  = round($costMoneyT['cost']/$infoDay['mkz']).' / '.round($costMoneyM['cost']/$infoMonth['mkz']);
            $infoMoney['validCost']= round($costMoneyT['cost']/$infoDay['valid']).' / '.round($costMoneyM['cost']/$infoMonth['valid']);
            $infoMoney['jdCost']   = round($costMoneyT['cost']/$infoDay['jd']).' / '.round($costMoneyM['cost']/$infoMonth['jd']);
            $infoMoney['xdCost']   = round($costMoneyT['cost']/$infoDay['xd']).' / '.round($costMoneyM['cost']/$infoMonth['xd']);
            $infoMoney['amountAvg']= number_format($orderAmountT['totalpay_money']/$infoDay['xd'], 2).' / '.number_format($orderAmountM['totalpay_money']/$infoMonth['xd'], 2);
            $infoMoney['ROI']      = number_format($costMoneyT['cost']/$orderFactT, 2).' / '.number_format($costMoneyM['cost']/$orderFactM, 2);

            $returnData['infoDay']   = $infoDay;
            $returnData['infoMonth'] = $infoMonth;
            $returnData['infoMoney'] = $infoMoney;
            $returnData['orderAmountYDS'] = $orderAmountYDS;
            $returnData['orderAmountMDS'] = $orderAmountMDS;
            $returnData['monthChangeRate']= number_format(($infoMonth['xd'] / $infoMonth['mkz'])*100,2).'%';
            unset($infoDay,$infoMonth,$infoMoney,$costMoneyT,$costMoneyM,$orderAmountT,$orderAmountM,$orderFactT,$orderFactM);

            return json($returnData);
        }

        // 四个排行榜 (按人排)
        public function rankData(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }
            // 日 开始结束时间
            $today_start = date('Y-m-d 00:00:00', time());
            $today_end   = date('Y-m-d 23:59:59', time());
            // 月 开始结束时间
            $date = getdateArea('this_month');
            $month_start= date('Y-m-d 00:00:00',strtotime($date[0]));
            $month_end  = date('Y-m-d 23:59:59',strtotime($date[1]));
            // 取所有人 （缓存）
            $allStaffs = controller('crm/Juzi','lib')->getAllStaffs();
            $sids = '';
            foreach ($allStaffs as $key => $value) {
                $sids .= $value['id'].',';
            }
            $sids = trim($sids, ',');

            $where['is_status'] = 1;
            $where['c_from'] = 1;
            /* -----------------------------------------------------  毛客资排名开始  ----------------------------------------------------- */
            $dayNewCus = db('c_customerinfo force index(all_time)')
                ->where($where)
                ->where('dj_day', 'between time', [$today_start, $today_end])
                ->where('dj_staff_id', 'in', $sids)
                ->group('dj_staff_id')
                ->field('dj_staff_id as id, dj_staff as staffname, COUNT(id) AS dayNum, 0 AS monthNum')
                ->order('dayNum', 'desc')
                ->select();
            $monthNewCus = db('c_customerinfo force index(all_time)')
                ->where($where)
                ->where('dj_day', 'between time', [$month_start, $month_end])
                ->where('dj_staff_id', 'in', $sids)
                ->group('dj_staff_id')
                ->field('dj_staff_id as id, dj_staff as staffname, COUNT(id) AS monthNum, 0 AS dayNum')
                ->order('dayNum', 'desc')
                ->select();
            $merge = array_merge($dayNewCus, $monthNewCus, $allStaffs);
            $temp = [];
            foreach ($merge as $key => $value) {
                if (!$value['id']) {
                    continue;
                }
                $temp[$value['id']]['id']        = $value['id'];
                $temp[$value['id']]['staffname'] = $value['staffname'];
                $temp[$value['id']]['dayNum']   += $value['dayNum'];
                $temp[$value['id']]['monthNum'] += $value['monthNum'];
            }

            unset($merge);
            unset($dayNewCus);
            unset($monthNewCus);
            $sort_order = 'SORT_DESC';
            $temp = my_sort($temp, 'dayNum', $sort_order);
            $t = [];
            foreach ($temp as $key => $value) {
                $t[(int)$value['dayNum']][(int)$value['monthNum']][] = $key;
            }
            $temp1 = [];
            foreach ($t as $key => $value) {
                krsort($value);
                foreach ($value as $k => $v) {
                    foreach ($v as $kk => $vv) {
                        $temp1[$vv] = $temp[$vv];
                    }
                }
            }
            $brandDayNew = array_slice($temp1, 0, 10);
            /* -----------------------------------------------------  毛客资排名结束  ----------------------------------------------------- */

            /* -----------------------------------------------------  有效客资排名开始  ----------------------------------------------------- */
            $dayValidCus = db('c_customerinfo force index(all_time)')
                ->where($where)
                ->where('is_valid', '<>', 3)
                ->where('dj_staff_id', 'in', $sids)
                ->where('dj_day', 'between time', [$today_start, $today_end])
                ->group('dj_staff_id')
                ->field('dj_staff_id as id, dj_staff as staffname, COUNT(id) AS dayNum, 0 AS monthNum')
                ->order('dayNum', 'desc')
                ->select();
            $monthValidCus = db('c_customerinfo force index(all_time)')
                ->where($where)
                ->where('is_valid', '<>', 3)
                ->where('dj_staff_id', 'in', $sids)
                ->where('dj_day', 'between time', [$month_start, $month_end])
                ->group('dj_staff_id')
                ->field('dj_staff_id as id, dj_staff as staffname, COUNT(id) AS monthNum, 0 AS dayNum')
                ->order('dayNum', 'desc')
                ->select();
            $merge = array_merge($dayValidCus, $monthValidCus, $allStaffs);

            $temp = [];
            foreach ($merge as $key => $value) {
                if (!$value['id']) {
                    continue;
                }
                $temp[$value['id']]['id']        = $value['id'];
                $temp[$value['id']]['staffname'] = $value['staffname'];
                $temp[$value['id']]['dayNum']   += $value['dayNum'];
                $temp[$value['id']]['monthNum'] += $value['monthNum'];
            }
            unset($merge);
            unset($dayValidCus);
            unset($monthValidCus);
            $sort_order = 'SORT_DESC';
            $temp = my_sort($temp, 'dayNum', $sort_order);
            $t = [];
            foreach ($temp as $key => $value) {
                $t[(int)$value['dayNum']][(int)$value['monthNum']][] = $key;
            }
            $temp1 = [];
            foreach ($t as $key => $value) {
                krsort($value);
                foreach ($value as $k => $v) {
                    foreach ($v as $kk => $vv) {
                        $temp1[$vv] = $temp[$vv];
                    }
                }
            }
            $brandValidNew = array_slice($temp1, 0, 10);
            // var_dump($brandValidNew);
            // exit;
            /* -----------------------------------------------------  有效客资排名结束  ----------------------------------------------------- */

            /* -----------------------------------------------------  邀约(进店)排名开始  ----------------------------------------------------- */
            $dayIntoCus = db('c_customerinfo force index(all_time)')
                ->where($where)
                ->where('is_intostore', 2)
                ->where('sales_staff_id', 'in', $sids)
                ->where('syjd_day', 'between time', [$today_start, $today_end])
                ->group('sales_staff_id')
                ->field('sales_staff_id as id, dj_staff as staffname, COUNT(id) AS dayNum, 0 AS monthNum')
                ->order('dayNum', 'desc')
                ->select();
            // echo db()->getLastSql().'<br />';
            $monthIntoCus = db('c_customerinfo force index(all_time)')
                ->where($where)
                ->where('is_intostore', 2)
                ->where('sales_staff_id', 'in', $sids)
                ->where('syjd_day', 'between time', [$month_start, $month_end])
                ->group('sales_staff_id')
                ->field('sales_staff_id as id, dj_staff as staffname, COUNT(id) AS monthNum, 0 AS dayNum')
                ->order('dayNum', 'desc')
                ->select();
            $merge = array_merge($dayIntoCus, $monthIntoCus, $allStaffs);
            $temp = [];
            foreach ($merge as $key => $value) {
                if (!$value['id']) {
                    continue;
                }
                $temp[$value['id']]['id']        = $value['id'];
                $temp[$value['id']]['staffname'] = $value['staffname'];
                $temp[$value['id']]['dayNum']   += $value['dayNum'];
                $temp[$value['id']]['monthNum'] += $value['monthNum'];
            }
            unset($merge, $dayIntoCus, $monthOrdeCus);
            $sort_order = 'SORT_DESC';
            $temp = my_sort($temp, 'dayNum', $sort_order);
            $t = [];
            foreach ($temp as $key => $value) {
                $t[(int)$value['dayNum']][(int)$value['monthNum']][] = $key;
            }
            $temp1 = [];
            foreach ($t as $key => $value) {
                krsort($value);
                foreach ($value as $k => $v) {
                    foreach ($v as $kk => $vv) {
                        $temp1[$vv] = $temp[$vv];
                    }
                }
            }
            $brandDayInto = array_slice($temp1, 0, 10);
            // var_dump($brandDayInto);
            // exit;
            /* -----------------------------------------------------  邀约排名结束  ----------------------------------------------------- */

            /* -----------------------------------------------------  新单排名开始  ----------------------------------------------------- */
            $dayOrdeCus = db('c_customer_order')->alias('o')
                ->join('c_customerinfo c', 'c.id=o.customer_id', 'LEFT')
                ->where('o.order_valid', 2)
                ->where('o.is_delete', 2)
                ->where('o.valid_time', 'between time', [$today_start, $today_end])
                ->where('c.sales_staff_id', 'in', $sids)
                ->where('c.is_status', 1)
                ->where('c.c_from', 1)
                ->field('sales_staff_id as id, dj_staff as staffname, COUNT(o.id) AS dayNum, 0 AS monthNum')
                ->order('sales_staff_id', 'desc')
                ->select();
            $monthOrdeCus = db('c_customer_order')->alias('o')
                ->join('c_customerinfo c', 'c.id=o.customer_id', 'LEFT')
                ->where('o.order_valid', 2)
                ->where('o.is_delete', 2)
                ->where('o.valid_time', 'between time', [$month_start, $month_end])
                ->where('c.sales_staff_id', 'in', $sids)
                ->where('c.is_status', 1)
                ->where('c.c_from', 1)
                ->field('sales_staff_id as id, dj_staff as staffname, COUNT(o.id) AS monthNum, 0 AS dayNum')
                ->order('dayNum', 'desc')
                ->select();
            $merge = array_merge($dayOrdeCus, $monthOrdeCus, $allStaffs);
            $temp = [];
            foreach ($merge as $key => $value) {
                if (!$value['id']) {
                    continue;
                }
                $temp[$value['id']]['id']        = $value['id'];
                $temp[$value['id']]['staffname'] = $value['staffname'];
                $temp[$value['id']]['dayNum']   += $value['dayNum'];
                $temp[$value['id']]['monthNum'] += $value['monthNum'];
            }
            unset($merge);
            unset($dayOrdeCus);
            unset($monthOrdeCus);
            $sort_order = 'SORT_DESC';
            $temp = my_sort($temp, 'dayNum', $sort_order);
            $t = [];
            foreach ($temp as $key => $value) {
                $t[(int)$value['dayNum']][(int)$value['monthNum']][] = $key;
            }
            $temp1 = [];
            foreach ($t as $key => $value) {
                krsort($value);
                foreach ($value as $k => $v) {
                    foreach ($v as $kk => $vv) {
                        $temp1[$vv] = $temp[$vv];
                    }
                }
            }
            $brandDayOrder = array_slice($temp1, 0, 10);
            // var_dump($brandDayOrder);
            // exit;
            /* -------------------------------------------------------  新单排名结束 ------------------------------------------------------- */

            $returnData = [
                'brandDayNew'  => $brandDayNew,
                'brandValidNew'=> $brandValidNew,
                'brandDayInto' => $brandDayInto,
                'brandDayOrder'=> $brandDayOrder,

            ];
            unset($brandDayNew,$brandValidNew,$brandDayInto,$brandDayOrder,$temp);
            return json($returnData);
        }

        // 转化漏斗 （日） 图
        public function dayChangeRate(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }

            $post = input('post.');
            $data['start'] = date('Y-m-d 00:00:00', time());
            $data['end']   = date('Y-m-d 23:59:59', time());
            $data['brandclass_id'] = (int)$post['brandclass_id'] ? (int)$post['brandclass_id'] : 0;

            $returnData = $this->getChangeLdData($data);

            return json($returnData);
        }

        // 转化漏斗 （月） 图
        public function monthChangeRate(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }

            $post = input('post.');

            $date = getdateArea('this_month');
            $data['start'] = date('Y-m-d 00:00:00',strtotime($date[0]));
            $data['end'] = date('Y-m-d 23:59:59',strtotime($date[1]));
            $data['brandclass_id'] = (int)$post['brandclass_id'] ? (int)$post['brandclass_id'] : 0;

            $returnData = $this->getChangeLdData($data);

            return json($returnData);
        }

        // 转化漏斗数据 
        public function getChangeLdData($data){
            $brandclass_id = $data['brandclass_id'];
            if ($brandclass_id) {
                $data['brandclass_id'] = $brandclass_id;
                // $add_shop_code = $this->shop_codes;
                // $data['add_shop_code'] = $add_shop_code[$brandclass_id];
                $data['add_shop_code'] = getShopCode($brandclass_id);
            }else{
                // $data['add_shop_code'] = implode(',', $this->shop_codes);
                $data['add_shop_code'] = getShopCode(0);
            }
            
            // 毛客资
            $customerNum = controller('crm/Juzi', 'lib')->getCustomerNum($data);
            $returnData[0]['name'] = '毛客资量';
            $returnData[0]['data'] = $customerNum;
            // 有效客资
            $invCustomer = controller('crm/Juzi', 'lib')->getInvCustomerNum($data);
            // exit;
            $returnData[1]['name'] = '有效客资';
            $returnData[1]['data'] = $invCustomer;
            // // 获取手机
            // $telCustomer = controller('crm/Statistics', 'lib')->getTelCustomerNum($data);
            // $returnData[2]['name'] = '获取手机';
            // $returnData[2]['data'] = $telCustomer;

            if ($brandclass_id) {
                $data['brandclass_id'] = $brandclass_id;
                // $add_shop_code = $this->all_shop_codes;
                // $data['add_shop_code'] = $add_shop_code[$brandclass_id];
                $data['shop_code'] = getShopCode($brandclass_id);
            }else{
                // $data['add_shop_code'] = implode(',', $this->all_shop_codes);
                $data['shop_code'] = getShopCode(0);
            }
            // 进店/邀约 量
            $intoCustomer= controller('crm/Juzi', 'lib')->getIntoCustomerNum($data);

            $returnData[2]['name'] = '进店';
            $returnData[2]['data'] = $intoCustomer;
            // 新单 量
            $data['type'] = 'shop';
            $orderNumber = controller('crm/Juzi', 'lib')->getOrderNumberNum($data);
            $returnData[3]['name'] = '订单';
            $returnData[3]['data'] = $orderNumber;
            return $returnData;
        }

        // 本月毛客资量走势 图
        public function monthCustomerNumber(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }
            $post = input('post.');
            $brandclass_id = (int)$post['brandclass_id'] ? (int)$post['brandclass_id'] : 0;
            if ($brandclass_id) {
                $data['brandclass_id'] = $brandclass_id;
                // $add_shop_code = $this->all_shop_codes;
                // $data['add_shop_code'] = $add_shop_code[$brandclass_id];
                $data['add_shop_code'] = getShopCode($brandclass_id);
            }else{
                // $data['add_shop_code'] = implode(',', $this->all_shop_codes);
                $data['add_shop_code'] = getShopCode(0);
            }
            // 起始时间
            $date = getdateArea('this_month');
            $timezone = getDateFromRange($date[0], $date[1]);

            $number = [];
            $today = date('Y-m-d');
            foreach ($timezone as $key => $value) {
                $data['start'] = date('Y-m-d 00:00:00', strtotime($value));
                $data['end']   = date('Y-m-d 23:59:59', strtotime($value));
                $customerNum = controller('crm/Juzi', 'lib')->getCustomerNum($data);
                $number[$key] = $customerNum;
                if ($value == $today) {
                    break;
                }
            }
            $zone = [];
            foreach ($timezone as $key => $value) {
                $zone[$key] = date('d', strtotime($value));
            }
            $arr = [
                0=>[
                    'name'=>'毛客资量',
                    'data' =>$number,
                ],
            ];

            $returnData['timezone'] = $zone;
            $returnData['name'] = array('毛客资量');
            $returnData['data'] = $arr;
            return json($returnData);
        }

        // 本月网销邀约 （进店） 量走势 图
        public function monthIntoNumber(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }
            $post = input('post.');
            $brandclass_id = (int)$post['brandclass_id'] ? (int)$post['brandclass_id'] : 0;
            if ($brandclass_id) {
                $data['brandclass_id'] = $brandclass_id;
                $data['add_shop_code'] = getShopCode($brandclass_id);
            }else{
                $data['add_shop_code'] = getShopCode(0);
            }
            // 起始时间
            $date = getdateArea('this_month');

            $data['start'] = date('Y-m-d 00:00:00', strtotime($date[0]));
            $data['end']   = date('Y-m-d 23:59:59', strtotime($date[1]));

            $timezone = getDateFromRange($date[0], $date[1]);
            $today = date('Y-m-d');
            $number = [];
            foreach ($timezone as $key => $value) {
                $data['start'] = date('Y-m-d 00:00:00', strtotime($value));
                $data['end']   = date('Y-m-d 23:59:59', strtotime($value));
                $customerNum = controller('crm/Juzi', 'lib')->getIntoCustomerNum($data);
                $number[$key] = $customerNum;
                if ($value == $today) {
                    break;
                }
            }
            $zone = [];
            foreach ($timezone as $key => $value) {
                $zone[$key] = date('d', strtotime($value));
            }
            $arr = [
                0=>[
                    'name'=>'邀约量',
                    'data' =>$number,
                ],
            ];

            $returnData['timezone'] = $zone;
            $returnData['name'] = array('邀约量');
            $returnData['data'] = $arr;
            return json($returnData);
        }
        
        // 本月网络新单量走势 图
        public function monthNewOrderNumber(){
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }
            $post = input('post.');
            $brandclass_id = (int)$post['brandclass_id'] ? (int)$post['brandclass_id'] : 0;
            if ($brandclass_id) {
                $data['brandclass_id'] = $brandclass_id;
                $data['add_shop_code'] = getShopCode($brandclass_id);
            }else{
                $data['add_shop_code'] = getShopCode(0);
            }
            // 起始时间
            $date = getdateArea('this_month');
            $timezone = getDateFromRange($date[0], $date[1]);
            $today = date('Y-m-d');
            $number = [];
            foreach ($timezone as $key => $value) {
                $data['start'] = date('Y-m-d 00:00:00', strtotime($value));
                $data['end']   = date('Y-m-d 23:59:59', strtotime($value));
                $data['type']  = 'shop';
                $customerNum = controller('crm/Juzi', 'lib')->getOrderNumberNum($data);
                $number[$key] = $customerNum;
                if ($value == $today) {
                    break;
                }
            }
            $zone = [];
            foreach ($timezone as $key => $value) {
                $zone[$key] = date('d', strtotime($value));
            }
            $arr = [
                0=>[
                    'name'=>'新单量',
                    'data' =>$number,
                ],
            ];

            $returnData['timezone'] = $zone;
            $returnData['name'] = array('新单量');
            $returnData['data'] = $arr;
            return json($returnData);
        }

        // 本月转化率 （ 新单 / 有效获取 ） 走势 图
        public function monthOrderRateNumber(){
            // echo '开始 ==> '.microtime(true).'<br />';
            $auth = controller('crm/Juzi', 'lib')->checkBigScreenAuth();
            if ($auth === false) {
                // controller('crm/Index','controller')->index();
                exit;
            }
            $post = input('post.');
            $brandclass_id = (int)$post['brandclass_id'] ? (int)$post['brandclass_id'] : 0;
            if ($brandclass_id) {
                // 新单条件
                $dataInto['brandclass_id'] = $brandclass_id;
                $dataInto['add_shop_code'] = getShopCode($brandclass_id);
                // 有效条件
                $dataInv['brandclass_id'] = $brandclass_id;
                $dataInv['add_shop_code'] = getShopCode($brandclass_id);
            }else{
                // 新单条件
                $dataInto['shop_code'] = getShopCode(0);
                // 有效条件
                $dataInv['add_shop_code'] = getShopCode(0);
            }
            // 起始时间
            $date = getdateArea('this_month');
            $timezone = getDateFromRange($date[0], $date[1]);

            $zone   = [];
            $number = [];
            $allInto= 0;
            $allInv = 0;
            $today = date('Y-m-d');
            // echo '开始循环 ==> '.microtime(true).'<br />';

            foreach ($timezone as $key => $value) {
                $start = date('Y-m-d 00:00:00', strtotime($value));
                $end   = date('Y-m-d 23:59:59', strtotime($value));
                $dataInto['start']= $start;
                $dataInto['end']  = $end;
                $dataInv['start'] = $start;
                $dataInv['end']   = $end;
                // 邀约
                // echo '循环'.$key.'邀约 ==> '.microtime(true).'<br />';
                $intoNum = controller('crm/Juzi', 'lib')->getOrderNumberNum($dataInto);
                // echo $intoNum.'<br />';
                $allInto += $intoNum;
                // 有效
                // echo '循环'.$key.'有效 ==> '.microtime(true).'<br />';
                $invNum = controller('crm/Juzi', 'lib')->getInvCustomerNum($dataInv);
                // echo $invNum.'<br />';
                $allInv += $invNum;
                $rate = $intoNum / $invNum;
                $number[$key] = number_format($rate*100, 2);
                $number[$key] = $number[$key]>100 ? 100 : $number[$key];
                if ($value == $today) {
                    break;
                }
            }
            // exit;
            // echo '结束循环 ==> '.microtime(true).'<br />';

            $allRate = number_format(($allInto / $allInv)*100, 2);

            // echo '循环时间 ==> '.microtime(true).'<br />';
            foreach ($timezone as $key => $value) {
                $allNumber[$key] = $allRate;
                $zone[$key] = date('d', strtotime($value));
            }
            // echo '循环结束 ==> '.microtime(true).'<br />';
            $arr = [
                0=>[
                    'name'=>'日转化率',
                    'data' =>$number,
                ],
                1=>[
                    'name'=>'月转化率',
                    'data' =>$allNumber,
                ],
            ];
            $returnData['timezone'] = $zone;
            $returnData['name'] = array('转化率');
            $returnData['data'] = $arr;
            // echo '最后赋值 ==> '.microtime(true).'<br />';
            return json($returnData);
        }
    //-------------------------------------- 大屏pc端 结束 --------------------------------------//
    /*-------------------手机大屏--------start---------------------*/
    public function xp(){
        return $this->fetch();
    }
    public function md(){
        return $this->fetch();
    }
    public function zjs(){
        return $this->fetch();
    }
    public function totalOrder($data){
        $start = date('Ymd',strtotime($data['start']));
        $end = date('Ymd',strtotime($data['end']));
        $start_fomart = date('Y-m-d 00:00:00',strtotime($data['start']));
        $end_fomart = date('Y-m-d 23:59:59',strtotime($data['end']));
        // $return = cache('totalOrder_'.md5(json_encode($data)));
        if (empty($return)) {
            // 渠道
            if($data['customer_channel']){
                if ($data['seache_type']==='like') {
                    $where['c.customer_channel'] = ['like',$data['customer_channel'].'%'];
                }else{
                    $where['c.customer_channel'] = ['in',$data['customer_channel']];
                }
            }
            // 来源
            if($data['cssname']){
                $where['c.cssname'] = ['in',$data['cssname']];
            }
            $orderid = db('c_customerorder','sx_erp_hs')->alias('o')->join('c_customerinfo c','c.customerid=o.customerid','left')
                ->where('is_effective',1)
                ->where('is_effectiveday','between',[$start,$end])
                ->where('targetdate','<=',$end)
                ->where('bargain_money','>',0)
                ->where($where)
                ->field('orderId,targetdate,blankoutannaldate')
                ->select();
            // echo db('c_customerorder','sx_erp_hs')->getLastSql();die;
            foreach($orderid as $kk=>$vv){
                if(date('Ym',strtotime($vv['targetdate'])) == date('Ym',strtotime($vv['blankoutannaldate']))){
                    unset($orderid[$kk]);
                }
            }
            $order = db('c_customerorder','sx_erp_hs')->alias('o')
                ->join('c_customerinfo c','c.customerid=o.customerid','left')
                ->where('blankoutannal',1)
                ->where('blankoutannaldate','between',[$start_fomart,$end_fomart])
                ->where('targetdate','<',$end)
                ->where('bargain_money','>',0)
                ->where('payment_money','>=',0)
                // ->where('yixiaopaid_money > bargain_money*0.3')
                ->where($where)
                ->column("orderId,targetdate,blankoutannaldate,bargain_money", 'orderId');
                // ->select();
            // echo db('c_customerorder','sx_erp_hs')->getLastSql();die;
            $zfOrderid = '';
            foreach($order as $kk=>$vv){
                if(date('Ym',strtotime($vv['targetdate'])) == date('Ym',strtotime($vv['blankoutannaldate']))){
                    unset($order[$kk]);
                }else{
					$zfWhere['suoshu'] = ['in', '前期款,前期补款'];
                    $zfOrderid .= $vv['orderId'].',';
                    $pay = db('c_paymentcontent','sx_erp_hs')
						->where('orderId',$vv['orderId'])
						->where($zfWhere)
						->where('payment_money','>','0')
						->value('sum(payment_money) as sumpayment_money');
                    if ($vv['bargain_money']*0.3>$pay) {
                        unset($order[$kk]);
                    }
                }
            }
            // // var_dump($order);die;
            // $zfOrderid = trim($zfOrderid, ',');
            // // var_dump($zfOrderid);die;
            // // 过滤作废未达到有效标准的订单
            // $zfWhere['orderId'] = ['in', $zfOrderid];
            // $zfWhere['suoshu'] = ['in', '前期款,前期补款'];
            // $zfOrders = db('c_paymentcontent','sx_erp_hs')
            //     ->where($zfWhere)
            //     ->where('payment_money','>','0')
            //     ->group('orderId')
            //     ->column('sum(payment_money) as sumpayment_money,orderId','orderId');
            // // echo db('c_paymentcontent','sx_erp_hs')->getLastSql();die;
            // // var_dump($zfOrders);die;
            // foreach ($zfOrders as $key => $value) {
            //     if ($order[$key]['bargain_money']*0.3 > $value) {
            //         unset($order[$key]);
            //     }
            // }
            // var_dump($zfOrders);die;
            $orderIds = array_column($orderid,'orderId');
            $order1 = array_column($order,'orderId');
            $orderIds = array_merge($orderIds,$order1);
            $orderList = '';
            foreach($orderIds as $k=>$v){
                $orderList .= $v.',';
            }
            $orderList = trim($orderList,',');
            // var_dump($orderList);die;
            $info = [];
            if($orderList){
                $info = db('c_customerorder','sx_erp_hs')->alias('o')
                    ->join('c_customerinfo c','c.customerid = o.customerid','left')
                    ->where('o.orderId', 'in', $orderList)
                    ->field('c.cssname,c.customer_channel,o.orderId,o.shop_code,o.shop_name,case blankoutannal when 1 then -bargain_money else bargain_money end as yeji')
                    ->order('orderId')->select();
                // $sql = "select b.shop_code,b.shop_name,date_format(b.targetdate,'%Y-%m-%d') as targetdate1,date_format(b.is_effectiveday,'%Y-%m-%d') as is_effectiveday1,date_format(b.blankoutannaldate,'%Y-%m-%d')  as blankoutannaldate1,a.cssname,a.customer_channel,b.is_effective,b.blankoutannaldate,CASE blankoutannal WHEN 1 THEN - bargain_money ELSE bargain_money END AS yeji FROM c_customerinfo a JOIN c_customerorder b ON a.customerid = b.customerid where b.orderId in (" . $orderList . ")";
                // $info = db('c_customerorder','sx_erp_hs')->query($sql);
            }
            // echo db('c_customerorder','sx_erp_hs')->getLastSql();die;
            // var_dump($info);die;
            $i = 0;//作废单
            $j = 0;//有效单
            //渠道单量
            $wx = 0;//网销
            $zjs = 0;//转介绍
            $new_zjs = 0;// 新转介绍
            $jd = 0;//自然进店
            $hbh = 0;//婚博会
            $sign = [];
            foreach($info as $k=>$v){
                $sign[$v['shop_code']]['shop_code'] = $v['shop_code'];
                $sign[$v['shop_code']]['shop_name'] = $v['shop_name'];
            }
            // var_dump($sign);
            // die;
            $yeji = 0;// 总业绩
            $wx_yj = 0;// 网销业绩
            $zjs_yj = 0;// 转介绍业绩
            foreach($info as $k=>$v){
                $sign[$v['shop_code']]['yeji']+= $v['yeji'];
                if($v['yeji'] > 0){
                    $sign[$v['shop_code']]['yx']  += 1;
                    $j++;
                    if($v['cssname'] == '网销' || $v['cssname'] == '电商'){
                        $wx++;
                        $wx_yj += $v['yeji'];
                    }elseif($v['cssname'] == '转介绍'){
                        $zjs++;
                        $zjs_yj += $v['yeji'];
                        if (strpos($this->zjsChannel, $v['customer_channel'])!==false) {
                            $new_zjs++;
                        }
                    }elseif($v['cssname'] == '自然进客'){
                        $jd++;
                    }elseif($v['cssname'] == '中国婚博会'){
                        $hbh++;
                    }
                }else if($v['yeji'] < 0){
                    $sign[$v['shop_code']]['yx']  -= 1;
                    $j--;
                    if($v['cssname'] == '网销' || $v['cssname'] == '电商'){
                        $wx--;
                    }elseif($v['cssname'] == '转介绍'){
                        $zjs--;
                        $zjs_yj += $v['yeji'];
                        if (strpos($this->zjsChannel, $v['customer_channel'])!==false) {
                            $new_zjs--;
                        }
                    }elseif($v['cssname'] == '自然进客'){
                        $jd--;
                    }elseif($v['cssname'] == '中国婚博会'){
                        $hbh--;
                    }
                }
                $yeji += $v['yeji'];
            }
            $return = [
                'order' => $j-$i,
                'yixiao'=> $yeji,
                'wx'    => $wx,
                'wx_yj' => $wx_yj,
                'zjs'   => $zjs,
                'zjs_yj'=> $zjs_yj,
                'jd'    => $jd,
                'hbh'   => $hbh,
                'new_zjs'=>$new_zjs,
                'sign'  => $sign,
            ];
            cache('totalOrder_'.md5(json_encode($data)), $return,30);
        }
        return $return;
    }
    //大屏基础数据
    public function mobileBaseData(){
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_mobileBaseData');
        if(empty($return)){
            //总订单量  is_effective is_effectiveday 有效状态，有效时间 blankoutannal 本单作废 bargain_money 预约总额（一销）
            // $sql_today =  "select count(b.orderid)as num from c_customerinfo a join c_customerorder b on a.customerid=b.customerid where b.is_effective=1 and b.is_effectiveday between '".$today."' and '".$today."' and targetdate<= '".$today."' and (blankoutannal is null or blankoutannal<>'1') and (bargain_money<>0);";

            // $sql_month =  "select count(b.orderid)as num from c_customerinfo a join c_customerorder b on a.customerid=b.customerid where b.is_effective=1 and b.is_effectiveday between '".$start."' and '".$today."' and targetdate<= '".$today."' and (blankoutannal is null or blankoutannal<>'1') and (bargain_money<>0);";
            // $db = db()->connect('sx_erp_hs');
            // $order_today = $db->query($sql_today);
            // $order_month = $db->query($sql_month);
            // $sql_today1 = "select count(b.orderid)as num from c_customerinfo a join c_customerorder b on a.customerid=b.customerid join (select c_paymentcontent.orderid,sum(c_paymentcontent.payment_money) as pm,c_customerorder.bargain_money*0.3 as bm from c_paymentcontent join c_customerorder on c_customerorder.orderid=c_paymentcontent.orderid where suoshu in ('前期款','前期补款') and blankoutannaldate between '".$today."' and '".$today."' and targetdate<'".$today."' and c_paymentcontent.payment_money>0 group by c_customerorder.orderid ) pay on b.orderid=pay.orderid and pay.pm>bm where blankoutannal='1'";

            // $sql_month1 = "select count(b.orderid)as num from c_customerinfo a join c_customerorder b on a.customerid=b.customerid join (select c_paymentcontent.orderid,sum(c_paymentcontent.payment_money) as pm,c_customerorder.bargain_money*0.3 as bm from c_paymentcontent join c_customerorder on c_customerorder.orderid=c_paymentcontent.orderid where suoshu in ('前期款','前期补款') and blankoutannaldate between '".$start."' and '".$today."' and targetdate<'".$start."' and c_paymentcontent.payment_money>0 group by c_customerorder.orderid ) pay on b.orderid=pay.orderid and pay.pm>bm where blankoutannal='1'";
            $db = db()->connect('sx_erp_hs');
            // $order_today1 = $db->query($sql_today1);
            // $order_month1 = $db->query($sql_month1);
            $todays['start'] = $today;
            $todays['end'] = $today;
            $order_today = $this->totalOrder($todays);
            $month['start'] = $start;
            $month['end'] = $today;
			// var_dump($month);die;
            $order_month = $this->totalOrder($month);

            // $return['order_today'] = $order_today[0]['num'] ? number_format($order_today[0]['num']-$order_today1[0]['num']) : 0;
            // $return['order_month'] = $order_month[0]['num'] ? number_format($order_month[0]['num']-$order_month1[0]['num']) : 0;
            $return['order_today'] = $order_today['order'] ? $order_today['order'] : 0;
            $return['order_month'] = $order_month['order'] ? $order_month['order'] : 0;
            // 拍摄业绩
            $sql_ps_today = "select count(b.orderid)as num from (select min(photodate) as photodate, orderId from c_customerphoto where  photostate=2  group by orderId  ) as p join c_customerorder b on p.orderId=b.orderId join c_customerinfo a on b.customerid=a.customerid where  b.bargain_money>0 and p.photodate between '".$today."' and '".$today."' ";
            $sql_ps_month = "select count(b.orderid)as num from (select min(photodate) as photodate, orderId from c_customerphoto where  photostate=2  group by orderId  ) as p join c_customerorder b on p.orderId=b.orderId join c_customerinfo a on b.customerid=a.customerid where  b.bargain_money>0 and p.photodate between '".$start."' and '".$today."' ";
            $ps_today = $db->query($sql_ps_today);
            $ps_month = $db->query($sql_ps_month);
            //总拍摄量
            $return['ps_today'] = $ps_today[0]['num'] ? number_format($ps_today[0]['num']) : 0;
            $return['ps_month'] =  $ps_month[0]['num'] ? number_format($ps_month[0]['num']) : 0;
            //选片业绩
            $xp_today_sql = "select sum(b.supplementary_money)as num from (select min(selectday) as selectday, orderId,id from c_customersp  where selectday between '".$today."' and '".$today."'  and  sptstate=1  group by orderId ) as asp join c_customerorder b on asp.orderId=b.orderId join c_customerinfo a on b.customerid=a.customerid ";
            $xp_month_sql = "select sum(b.supplementary_money)as num from (select min(selectday) as selectday, orderId,id from c_customersp  where selectday between '".$start."' and '".$today."'  and  sptstate=1  group by orderId ) as asp join c_customerorder b on asp.orderId=b.orderId join c_customerinfo a on b.customerid=a.customerid ";
            $xp_today = $db->query($xp_today_sql);
            $xp_month = $db->query($xp_month_sql);
            $return['xp_today'] = $xp_today[0]['num'] ? number_format($xp_today[0]['num']) : 0;
            $return['xp_month'] = $xp_month[0]['num'] ? number_format($xp_month[0]['num']) : 0;
            //一销均价
            /*    $sql_yi = "select sum(bargain_money)/count(b.orderid) as yi
            from c_customerinfo a join c_customerorder b on a.customerid = b.customerid
            where b.orderId in (
            select b.orderid  from c_customerinfo a join c_customerorder b on a.customerid=b.customerid
            where b.is_effective=1 and b.is_effectiveday between '".$today."' and '".$today."'
            and targetdate<= '".$today."') and (bargain_money<>0)";*/
            $sql_yi_month = "select sum(bargain_money)/count(b.orderid) as yi from c_customerinfo a join c_customerorder b on a.customerid = b.customerid where b.orderId in ( select b.orderid  from c_customerinfo a join c_customerorder b on a.customerid=b.customerid where b.is_effective=1 and b.is_effectiveday between '".$start."' and '".$today."'and targetdate<= '".$today."') and (bargain_money<>0)";
            // $yi_today = $db->query($sql_yi);
            $yi_month = $db->query($sql_yi_month);
            $return['yi_avg_today'] = $order_today['yixiao']/$order_today['order']>0 ? number_format($order_today['yixiao']/$order_today['order']) : 0;
            $return['yi_avg_month'] =  $order_month['yixiao']/$order_month['order']>0 ? number_format($order_month['yixiao']/$order_month['order']) : 0;
            //二销均价
            $sql_er = "select count(b.orderid) as num from c_customerorder b join c_customerinfo a on b.customerid=a.customerid join (select min(selectday) as selectday, orderId,id from c_customersp where selectday between '".$today."' and '".$today."' and sptstate=1 group by orderId ) as asp on asp.orderId=b.orderId  where b.bargain_money<>0";
            $sql_er_month = "select count(b.orderid) as num from c_customerorder b join c_customerinfo a on b.customerid=a.customerid join (select min(selectday) as selectday, orderId,id from c_customersp where selectday between '".$start."' and '".$today."' and sptstate=1 group by orderId ) as asp on asp.orderId=b.orderId  where b.bargain_money<>0";
            $er_today = $db->query($sql_er);
            $er_month = $db->query($sql_er_month);
            $return['er_avg_today'] = $er_today[0]['num'] ? number_format($xp_today[0]['num']/$er_today[0]['num']) : 0;
            $return['er_avg_month'] =  $er_month[0]['num'] ? number_format($xp_month[0]['num']/$er_month[0]['num']) : 0;
            //广告费
            $cost_today = cache('dp_cost_today');
            if(empty($cost_today)){
                $cost_today= db('s_channel_cost')->where('cost_date','between',[$today,$today])->sum('cost');
                cache('dp_cost_today',$cost_today,130);
            }
            if(empty($cost_month)){
                $cost_month = db('s_channel_cost')->where('cost_date','between',[$start,$today])->sum('cost');
                cache('dp_cost_month',$cost_month,130);
            }
            $return['cost_today'] = $cost_today ? number_format($cost_today) : 0;
            $return['cost_month'] = $cost_month ? number_format($cost_month) : 0;

            $return['yeji_today'] = $order_today['yixiao'];
            $return['yeji_month'] = $order_month['yixiao'];
            cache('dp_mobileBaseData',$return,75);
        }
        return $return;
    }
    //订单情况
    public function orderInfo(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_orderInfo');
        if(empty($return)){
            // $sql_today = "select sum(bargain_money) as yeji, count(b.orderid) as danliang,sum(bargain_money)/count(b.orderid) as junjia from c_customerinfo a join c_customerorder b on a.customerid = b.customerid where b.orderId in (select b.orderid  from c_customerinfo a join c_customerorder b on a.customerid=b.customerid where b.is_effective=1 and b.is_effectiveday between '".$today."' and '".$today."' and targetdate<= '".$today."' ) and (bargain_money<>0)";
            // $sql_month = "select sum(bargain_money) as yeji, count(b.orderid) as danliang,sum(bargain_money)/count(b.orderid) as junjia from c_customerinfo a join c_customerorder b on a.customerid = b.customerid where b.orderId in (select b.orderid  from c_customerinfo a join c_customerorder b on a.customerid=b.customerid where b.is_effective=1 and b.is_effectiveday between '".$start."' and '".$today."' and targetdate<= '".$today."' ) and (bargain_money<>0)";

            // $db = db()->connect('sx_erp_hs');
            // $order_today = $db->query($sql_today);
            // $order_month = $db->query($sql_month);
            $base = $this->mobileBaseData();
            // var_dump($base);die;
            $return['order_today'] = $base['order_today'] ? ($base['order_today']) : 0;
            $return['order_month'] =  $base['order_month'] ? ($base['order_month']) : 0;
            $return['yeji_today']= $base['yeji_today'] ? number_format($base['yeji_today']) : 0;
            $return['yeji_month']= $base['yeji_month'] ? number_format($base['yeji_month']) : 0;
            $return['avg_today'] = $base['yi_avg_today'];
            $return['avg_month'] = $base['yi_avg_month'];
            // $return['today_sql'] = $sql_today;
            // $return['month_sql'] = $sql_month;
            cache('dp_orderInfo',$return,50);
        }

        return $return;
    }
    //渠道单量比重
    public function channelOrder(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_channelOrder');
        if(empty($return)){
            $todays['start'] = $today;
            $todays['end'] = $today;
            $order_today = $this->totalOrder($todays);
            $month['start'] = $start;
            $month['end'] = $today;
            $order_month = $this->totalOrder($month);
            //不同来源的的数据
            $return['channel_order_wx_today'] = $order_today['wx'];
            $return['channel_order_wx_month'] = $order_month['wx'];

            $return['channel_order_jd_today'] = $order_today['jd'];
            $return['channel_order_jd_month'] = $order_month['jd'];

            $return['channel_order_zjs_today'] = $order_today['zjs'];
            $return['channel_order_zjs_month'] = $order_month['zjs'];

            $return['channel_order_hbh_today'] = $order_today['hbh'];
            $return['channel_order_hbh_month'] = $order_month['hbh'];
            cache('dp_channelOrder',$return,60);
        }
        return $return;
    }
    //实收情况
    public function factInfo(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_factInfo');
        if(empty($return)){
            $sql_yi_today = "select sum(payment_money)as num from c_paymentcontent where paymentdate between '".$today."' and '".$today."' and (suoshu ='前期款' or suoshu='前期补款');";
            $sql_yi_month = "select sum(payment_money)as num from c_paymentcontent where paymentdate between '".$start."' and '".$today."' and (suoshu ='前期款' or suoshu='前期补款');";
            $db = db()->connect('sx_erp_hs');
            $fact_today = $db->query($sql_yi_today);
            $fact_month = $db->query($sql_yi_month);

            $sql_er_today = "select sum(payment_money)as num from c_paymentcontent where paymentdate between '".$today."' and '".$today."' and (suoshu ='后期款' or suoshu='后期补款');";
            $sql_er_month = "select sum(payment_money)as num from c_paymentcontent where paymentdate between '".$start."' and '".$today."' and (suoshu ='后期款' or suoshu='后期补款');";
            $fact_er_today = $db->query($sql_er_today);

            $fact_er_month = $db->query($sql_er_month);

            $sql_tui_today = "select sum(payment_money)as num from c_paymentcontent where paymentdate between '".$today."' and '".$today."' and (suoshu ='一销退款' or suoshu='二销退款');";
            $sql_tui_month = "select sum(payment_money)as num from c_paymentcontent where paymentdate between '".$start."' and '".$today."' and (suoshu ='一销退款' or suoshu='二销退款');";
            $fact_tui_today = $db->query($sql_tui_today);

            $fact_tui_month = $db->query($sql_tui_month);

            $return['fact_yi_today'] = $fact_today[0]['num'] ? number_format($fact_today[0]['num']) : 0;
            $return['fact_yi_month'] = $fact_month[0]['num'] ? number_format($fact_month[0]['num']) : 0;
            $return['fact_er_today'] = $fact_er_today[0]['num'] ? number_format($fact_er_today[0]['num']) : 0;
            $return['fact_er_month'] = $fact_er_month[0]['num'] ? number_format($fact_er_month[0]['num']) : 0;
            $return['fact_today'] = number_format($fact_today[0]['num']+$fact_er_today[0]['num']+$fact_tui_today[0]['num']);
            $return['fact_month'] = number_format($fact_month[0]['num']+$fact_er_month[0]['num']+$fact_tui_month[0]['num']);
            cache('dp_factInfo',$return,80);
        }
        return $return;
    }
    //拍摄情况
    public function psInfo(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_psInfo');
        if(empty($return)){
            $sql_today = "select count(b.orderid) as xindan,p.shop_code,sum(bargain_money) as fact from (select min(photodate) as photodate, orderId,shop_code from c_customerphoto where photostate=2 and shop_code in ('JZ003','JZ004') group by orderId ) as p join c_customerorder b on p.orderId=b.orderId join c_customerinfo a on b.customerid=a.customerid where b.bargain_money>0 and p.photodate between '".$today."' and '".$today."' group by p.shop_code ";
            $sql_month = "select count(b.orderid) as xindan,p.shop_code,sum(bargain_money) as fact from (select min(photodate) as photodate, orderId,shop_code from c_customerphoto where photostate=2 and shop_code in ('JZ003','JZ004') group by orderId ) as p join c_customerorder b on p.orderId=b.orderId join c_customerinfo a on b.customerid=a.customerid where b.bargain_money>0 and p.photodate between '".$start."' and '".$today."' group by p.shop_code ";
            $db = db()->connect('sx_erp_hs');
            $ps_today = $db->query($sql_today);

            $today = [];
            foreach($ps_today as $k=>$v){
                $today[$v['shop_code']] = $v;
            }
            $ps_month = $db->query($sql_month);
            $month = [];
            foreach($ps_month as $k=>$v){
                $month[$v['shop_code']] = $v;
            }
            // var_dump($today);die;
            //拍摄新单量
            $return['ps_order_today'] = number_format($today['JZ003']['xindan']+$today['JZ004']['xindan']);
            $return['ps_order_month'] = number_format($month['JZ003']['xindan']+$month['JZ004']['xindan']);
            //蜂巢新单量
            $return['ps_fc_order_today'] = number_format($today['JZ003']['xindan']);
            $return['ps_fc_order_month'] = number_format($month['JZ003']['xindan']);
            //嘉娜新单量
            $return['ps_jn_order_today'] = number_format($today['JZ004']['xindan']);
            $return['ps_jn_order_month'] = number_format($month['JZ004']['xindan']);

            //拍摄均价
            $return['ps_fact_today'] = number_format(($today['JZ003']['fact']+$today['JZ004']['fact'])/($today['JZ003']['xindan']+$today['JZ004']['xindan']));
            $return['ps_fact_month'] = number_format(($month['JZ003']['fact']+$month['JZ004']['fact'])/($month['JZ003']['xindan']+$month['JZ004']['xindan']));
            //蜂巢均价
            $return['ps_fc_fact_today'] = number_format($today['JZ003']['fact']/$today['JZ003']['xindan']);
            $return['ps_fc_fact_month'] = number_format($month['JZ003']['fact']/$month['JZ003']['xindan']);
            //嘉娜均价
            $return['ps_jn_fact_today'] = number_format($today['JZ004']['fact']/$today['JZ004']['xindan']);
            $return['ps_jn_fact_month'] = number_format($month['JZ004']['fact']/$month['JZ004']['xindan']);
            cache('dp_psInfo',$return,130);
        }
        return $return;
    }
    //选片情况
    public function xpInfo(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_xpInfo');
        if(empty($return)){
            $sql_today = "SELECT COUNT(p.id) AS onum,COUNT(oo.id) AS oonum,SUM(o.supplementary_money) AS exje,SUM(o.supplementary_money) / COUNT(oo.id) AS ex_avg,p.shop_code,p.shop_name FROM (SELECT p.orderId,MAX(p.id) AS pid,MAX(s.id) AS sid  FROM c_customerphoto p LEFT JOIN c_customersp s ON p.orderId=s.orderId WHERE s.sptstate = 1 AND s.selectday BETWEEN '".$today."' AND '".$today."' GROUP BY orderId ) tem LEFT JOIN c_customerorder o ON tem.orderId = o.orderId LEFT JOIN c_customerphoto p ON tem.orderId = p.orderId AND p.id=tem.pid LEFT JOIN c_customersp s ON tem.orderId = s.orderId AND s.id=tem.sid LEFT JOIN c_customerorder oo ON oo.orderId = o.orderId AND oo.bargain_money > 0 GROUP BY p.shop_code;";
            $sql_month = "SELECT COUNT(p.id) AS onum,COUNT(oo.id) AS oonum,SUM(o.supplementary_money) AS exje,SUM(o.supplementary_money) / COUNT(oo.id) AS ex_avg,p.shop_code,p.shop_name FROM (SELECT p.orderId,MAX(p.id) AS pid,MAX(s.id) AS sid  FROM c_customerphoto p LEFT JOIN c_customersp s ON p.orderId=s.orderId WHERE s.sptstate = 1 AND s.selectday BETWEEN '".$start."' AND '".$today."' GROUP BY orderId ) tem LEFT JOIN c_customerorder o ON tem.orderId = o.orderId LEFT JOIN c_customerphoto p ON tem.orderId = p.orderId AND p.id=tem.pid LEFT JOIN c_customersp s ON tem.orderId = s.orderId AND s.id=tem.sid LEFT JOIN c_customerorder oo ON oo.orderId = o.orderId AND oo.bargain_money > 0 GROUP BY p.shop_code;";
            // echo $sql_month;die;
            $db = db()->connect('sx_erp_hs');
            // 日
            $temp_xp_today = $db->query($sql_today);
            $xp_today = [];
            foreach ($temp_xp_today as $key => $value) {
                $xp_today[$value['shop_code']] = $value;
            }
            // 月
            $temp_xp_month = $db->query($sql_month);
            $xp_month = [];
            foreach ($temp_xp_month as $key => $value) {
                $xp_month[$value['shop_code']] = $value;
            }
            //选片业绩
            $info = $this->mobileBaseData();
            $return['xp_fact_today'] = $info['xp_today'];
            $return['xp_fact_month'] = $info['xp_month'];
            //选片均价
            $avg = $this->mobileBaseData();
            $return['xp_avg_today'] = ($avg['er_avg_today']);
            $return['xp_avg_month'] = ($avg['er_avg_month']);
            //蜂巢二销均价
            $return['xp_fc_er_today'] = number_format($xp_today['JZ003']['ex_avg']);
            $return['xp_fc_er_month'] = number_format($xp_month['JZ003']['ex_avg']);
            //嘉娜二销均价
            $return['xp_jn_er_today'] = number_format($xp_today['JZ004']['ex_avg']);
            $return['xp_jn_er_month'] = number_format($xp_month['JZ004']['ex_avg']);
            cache('dp_xpInfo',$return,80);
        }
        return $return;
    }
    //门店情况
    public function mdInfo(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('dp_mdInfo');
        if(empty($return)){
            $todays['start'] = $today;
            $todays['end'] = $today;
            $order_today = $this->totalOrder($todays);
            $dayYxNum = 0;// 有效单
            $dayZfNum = 0;// 作废单
            $dayMoney = 0;// 业绩
            foreach ($order_today['sign'] as $key => $value) {
                if ( strpos($this->store,$value['shop_code'])!==false) {
                    $dayYxNum += $value['yx'];
                    $dayZfNum += $value['zf'];
                    $dayMoney += $value['yeji'];
                }
            }
            $month['start'] = $start;
            $month['end'] = $today;
            $order_month = $this->totalOrder($month);
            $monthYxNum = 0;// 有效单
            $monthZfNum = 0;// 作废单
            $monthMoney = 0;// 业绩
            foreach ($order_month['sign'] as $key => $value) {
                if ( strpos($this->store,$value['shop_code'])!==false) {
                    $monthYxNum += $value['yx'];
                    $monthZfNum += $value['zf'];
                    $monthMoney += $value['yeji'];
                }
            }
            //门店订单量
            $return['md_order_today'] = number_format($dayYxNum-$dayZfNum);
            $return['md_order_month'] = number_format($monthYxNum-$monthZfNum);
            //门店业绩
            $return['md_fact_today'] = number_format($dayMoney);
            $return['md_fact_month'] = number_format($monthMoney);
            //门店均价
            $return['md_avg_today'] = number_format($dayMoney/($dayYxNum-$dayZfNum));
            $return['md_avg_month'] = number_format($monthMoney/($monthYxNum-$monthZfNum));
            // 转介绍订单量 
            $return['md_zjs_order_today'] = number_format($order_today['new_zjs']);
            $return['md_zjs_order_month'] = number_format($order_month['new_zjs']);
            //进客量  20191225
            $jdSql = " i.op_signinfo IS NULL OR i.op_signinfo<>'转单' ";
            $jd_today = db('c_customerinfo c')->join('c_customer_intostore i','i.cid=c.id','LEFT')->where('c.is_status',1)->where('i.status',1)->where('i.reback',1)->where('i.is_intostore','in',[2,4,5])->where($jdSql)->whereTime('i.syjd_day','between',[$this->today['start'],$this->today['end']])->count('c.id');
            $jd_month = db('c_customerinfo c')->join('c_customer_intostore i','i.cid=c.id','LEFT')->where('c.is_status',1)->where('i.status',1)->where('i.reback',1)->where('i.is_intostore','in',[2,4,5])->where($jdSql)->whereTime('i.syjd_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->count('c.id');
            // echo db()->getLastSql();die;
            $return['md_jd_today'] = number_format($jd_today);
            $return['md_jd_month'] = number_format($jd_month);
            //成交率
            $return['md_order_rate_today'] = number_format(($dayYxNum-$dayZfNum)/$jd_today*100,2);
            if ($return['md_order_rate_today']>100) {
                $return['md_order_rate_today'] = '100%';
            }else{
                $return['md_order_rate_today'] = $return['md_order_rate_today'].'%';
            }
            $return['md_order_rate_month'] = number_format(($monthYxNum-$monthZfNum)/$jd_month*100,2);
            if ($return['md_order_rate_month']>100) {
                $return['md_order_rate_month'] = '100%';
            }else{
                $return['md_order_rate_month'] = $return['md_order_rate_month'].'%';
            }
            cache('dp_mdInfo',$return,60);
        }
        return $return;
    }
    //推广/网销情况
    public function tuiWang(){
        // $start = date('Ym01');
        // $today = date('Ymd');
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        //网销订单量 来源是电商+网销的订单
        // $return = cache('tuiwang');
        if(empty($return)){
            $todays['start'] = $today;
            $todays['end'] = $today;
            $todays['cssname'] = '电商,网销';
            $today_order = $this->totalOrder($todays);

            $month['start'] = $start;
            $month['end'] = $today;
            $month['cssname'] = '电商,网销';
            $month_order = $this->totalOrder($month);

            $return['wx_order_today'] = number_format($today_order['order']);
            $return['wx_order_month'] = number_format($month_order['order']);
            // 业绩
            $return['wx_fact_today'] = number_format($today_order['yixiao']);
            $return['wx_fact_month'] = number_format($month_order['yixiao']);
            // 均价
            $return['wx_avg_today'] = number_format($today_order['yixiao']/$today_order['order']);
            $return['wx_avg_month'] = number_format($month_order['yixiao']/$month_order['order']);
            // 客资量
            $wx_mkz_today = db('c_customerinfo')
                ->where('is_status',1)
                ->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])
                ->where('shop_code|add_shop_code',$this->shop_code)
                ->count('id');
            $wx_mkz_month = db('c_customerinfo')
                ->where('is_status',1)
                ->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])
                ->where('shop_code|add_shop_code',$this->shop_code)
                ->count('id');
            $return['wx_mkz_today'] = number_format($wx_mkz_today);
            $return['wx_mkz_month'] = number_format($wx_mkz_month);
            //进客量
            $jdSql = " i.op_signinfo IS NULL OR i.op_signinfo<>'转单' ";
            $wx_jd_today= db('c_customerinfo c')->join('c_customer_intostore i','c.id=i.cid','LEFT')
                ->where('c.is_status',1)
                ->where('i.reback',1)
                ->where('i.status',1)
                ->where('i.is_intostore','in',[2,4,5])
                ->where($jdSql)
                ->whereTime('i.syjd_day','between',[$this->today['start'],$this->today['end']])
                ->where('c.customer_cource', 'in', $this->jkcource)
                ->count('c.id');
            $wx_jd_month= db('c_customerinfo c')->join('c_customer_intostore i','c.id=i.cid','LEFT')                
                ->where('c.is_status',1)
                ->where('i.reback',1)
                ->where('i.status',1)
                ->where('i.is_intostore','in',[2,4,5])
                ->where($jdSql)
                ->whereTime('i.syjd_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])
                ->where('c.customer_cource', 'in', $this->jkcource)
                ->count('c.id');
            // echo db()->getLastSql();die;
            $return['wx_jd_today'] = number_format($wx_jd_today);
            $return['wx_jd_month'] = number_format($wx_jd_month);
            //微信通过量    
            $wx_friend_today = db('c_customerinfo')
                ->where('is_status',1)
                ->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])
                ->where('shop_code|add_shop_code',$this->shop_code)
                ->where('add_friend_time','not null')
                ->where('add_friend_time','<>','')
                ->count('id');
            $wx_friend_month = db('c_customerinfo')
                ->where('is_status',1)
                ->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])
                ->where('shop_code|add_shop_code',$this->shop_code)
                ->where('add_friend_time','not null')
                ->where('add_friend_time','<>','')
                ->count('id');
            //通过率
            $return['wx_wechat_today'] = number_format($wx_friend_today/$wx_mkz_today*100,2);
            if ($return['wx_wechat_today']>100) {
                $return['wx_wechat_today'] = '100%';
            }else{
                $return['wx_wechat_today'] = $return['wx_wechat_today'].'%';
            }
            $return['wx_wechat_month'] = number_format($wx_friend_month/$wx_mkz_month*100,2);
            if ($return['wx_wechat_month']>100) {
                $return['wx_wechat_month'] = '100%';
            }else{
                $return['wx_wechat_month'] = $return['wx_wechat_month'].'%';
            }
            // 线上订单
            $todays['start'] = $today;
            $todays['end'] = $today;
            $temp_today = $this->totalOrder($todays);
            $online_today_order = $temp_today['sign']['WX002']['yx']-$temp_today['sign']['WX002']['zf'];
            $month['start'] = $start;
            $month['end'] = $today;
            $temp_month = $this->totalOrder($month);
            $online_month_order = $temp_month['sign']['WX002']['yx']-$temp_month['sign']['WX002']['zf'];
            //网销成交率  （网销订单量-线上订单量）/进客量
            $wxCjRateDay = ($today_order['order']-$online_today_order)/$wx_jd_today;
            $return['wx_order2_rate_today'] = number_format($wxCjRateDay*100,2);
            if ($return['wx_order2_rate_today']>100) {
                $return['wx_order2_rate_today'] = '100%';
            }else{
                $return['wx_order2_rate_today'] = $return['wx_order2_rate_today'].'%';
            }
            $wxCjRateMonth = ($month_order['order']-$online_month_order)/$wx_jd_month;
            $return['wx_order2_rate_month'] = number_format($wxCjRateMonth*100,2);
            if ($return['wx_order2_rate_month']>100) {
                $return['wx_order2_rate_month'] = '100%';
            }else{
                $return['wx_order2_rate_month'] = $return['wx_order2_rate_month'].'%';
            }
            //总客资转化率?
            $return['wx_zh_today'] = number_format((($online_today_order/$wxCjRateDay)+$wx_jd_today)/$wx_mkz_today*100,2);
            if ($return['wx_zh_today']>100) {
                $return['wx_zh_today'] = '100%';
            }else{
                $return['wx_zh_today'] = $return['wx_zh_today'].'%';
            }
            $return['wx_zh_month'] = number_format((($online_month_order/$wxCjRateMonth)+$wx_jd_month)/$wx_mkz_month*100,2);
            if ($return['wx_zh_month']>100) {
                $return['wx_zh_month'] = '100%';
            }else{
                $return['wx_zh_month'] = $return['wx_zh_month'].'%';
            }
            //总客资订单率
            $return['wx_order_rate_today'] = number_format($today_order['order']/$wx_mkz_today*100,2);
            if ($return['wx_order_rate_today']>100) {
                $return['wx_order_rate_today'] = '100%';
            }else{
                $return['wx_order_rate_today'] = $return['wx_order_rate_today'].'%';
            }
            $return['wx_order_rate_month'] = number_format($month_order['order']/$wx_mkz_month*100,2);
            if ($return['wx_order_rate_month']>100) {
                $return['wx_order_rate_month'] = '100%';
            }else{
                $return['wx_order_rate_month'] = $return['wx_order_rate_month'].'%';
            }
            $db = db()->connect('sx_erp_hs');
            // 广告费
            $cost_today = cache('dp_cost_today');
            if(empty($cost_today)){
                $cost_today= db('s_channel_cost')->whereTime('cost_date','between',[$this->today['start'],$this->today['end']])->where('shop_code',$this->tgshop)->sum('cost');
                $return['cost_today'] = $cost_today;
                cache('dp_cost_today',$cost_today,3*60);
            }
            $cost_month = cache('cost_month');
            if(empty($cost_month)){
                $cost_month = db('s_channel_cost')->whereTime('cost_date','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('shop_code',$this->tgshop)->sum('cost');
                $return['cost_month'] = $cost_month;
                cache('dp_cost_month',$cost_month,3*60);
            }
            //订单成本
            $return['wx_order_cost_today'] = number_format($cost_today/$today_order['order']);
            $return['wx_order_cost_month'] = number_format($cost_month/$month_order['order']);
            //ROI 网销业绩 / 广告费
            $return['roi_today'] = number_format($today_order['yixiao']/$cost_today,2);
            $return['roi_month'] = number_format($month_order['yixiao']/$cost_month,2);
            cache('tuiwang',$return,30);
        }
        return $return;
    }
    //转介绍情况
    public function zjsInfo(){
        $start = date('Ym01',strtotime($this->thisMonth['start']));
        $today = date('Ymd',strtotime($this->today['start']));
        // $return = cache('zjsInfo');
        if(empty($return)){
            // 日
            $todays['start'] = $today;
            $todays['end'] = $today;
            $info_today = $this->totalOrder($todays);
            // 月
            $month['start'] = $start;
            $month['end'] = $today;
            $info_month = $this->totalOrder($month);
            //转介绍订单量
            $return['zjs_order_today'] = number_format($info_today['zjs']);
            $return['zjs_order_month'] = number_format($info_month['zjs']);
            //门店业绩
            $return['zjs_fact_today'] = number_format($info_today['zjs_yj']);
            $return['zjs_fact_month'] = number_format($info_month['zjs_yj']);
            //门店均价
            $return['zjs_avg_today'] = number_format($info_today['zjs_yj']/$info_today['zjs']);
            $return['zjs_avg_month'] = number_format($info_month['zjs_yj']/$info_month['zjs']);
            //客资量
            $mkz_today = db('c_customerinfo')->where('is_status',1)->where('c_from',1)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('add_shop_code|shop_code',$this->zjsshop)->count('id');
            $mkz_month = db('c_customerinfo')->where('is_status',1)->where('c_from',1)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('add_shop_code|shop_code',$this->zjsshop)->count('id');
            $return['zjs_mkz_today'] = ($mkz_today);
            $return['zjs_mkz_month'] = ($mkz_month);
            //进客量
            $jdSql = " i.op_signinfo IS NULL OR i.op_signinfo<>'转单' ";
            $jd_today = db('c_customerinfo c')->join('c_customer_intostore i','i.cid=c.id','LEFT')->where('c.is_status',1)->where('i.status',1)->where('c.c_from',1)->whereTime('i.syjd_day','between',[$this->today['start'],$this->today['end']])->where('i.is_intostore','in',[2,4,5])->where($jdSql)->where('i.reback',1)->where('customer_type',2)->count('c.id');
            $jd_month = db('c_customerinfo c')->join('c_customer_intostore i','i.cid=c.id','LEFT')->where('c.is_status',1)->where('i.status',1)->where('c.c_from',1)->whereTime('i.syjd_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('i.is_intostore','in',[2,4,5])->where($jdSql)->where('i.reback',1)->where('customer_type',2)->count('c.id');
            $return['zjs_jd_today'] = number_format($jd_today);
            $return['zjs_jd_month'] = number_format($jd_month);
            //总客资订单率
            $return['zjs_mkz_order_rate_today'] = number_format($info_today['zjs']/$mkz_today*100,2);
            if ($return['zjs_mkz_order_rate_today']>100) {
                $return['zjs_mkz_order_rate_today'] = '100%';
            }else{
                $return['zjs_mkz_order_rate_today'] = $return['zjs_mkz_order_rate_today'].'%';
            }
            $return['zjs_mkz_order_rate_month'] = number_format($info_month['zjs']/$mkz_month*100,2);
            if ($return['zjs_mkz_order_rate_month']>100) {
                $return['zjs_mkz_order_rate_month'] = '100%';
            }else{
                $return['zjs_mkz_order_rate_month'] = $return['zjs_mkz_order_rate_month'].'%';
            }
            // 成交率   (转介绍单量-线上单量）/进客量
            $online_today_order = $info_today['sign']['WX003']['yx']-$info_today['sign']['WX003']['zf'];
            $online_month_order = $info_month['sign']['WX003']['yx']-$info_month['sign']['WX003']['zf'];
            $return['zjs_order_rate_today'] = number_format(($info_today['zjs']-$online_today_order)/$jd_today*100,2);
            if ($return['zjs_order_rate_today']>100) {
                $return['zjs_order_rate_today'] = '100%';
            }else{
                $return['zjs_order_rate_today'] = $return['zjs_order_rate_today'].'%';
            }
            $return['zjs_order_rate_month'] = number_format(($info_month['zjs']-$online_month_order)/$jd_month*100,2);
            if ($return['zjs_order_rate_month']>100) {
                $return['zjs_order_rate_month'] = '100%';
            }else{
                $return['zjs_order_rate_month'] = $return['zjs_order_rate_month'].'%';
            }
            cache('zjsInfo',$return,80);
        }

        return $return;
    }
    /*-------------------手机大屏--------end---------------------*/

    /*-------------------手机大屏--选片------start---------------------*/
        public function xpDetail(){
            $start = date('Ym01',strtotime($this->thisMonth['start']));
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('dp_xpDetail');
            if(empty($return)){
                // 选片sql
                $sp_sql_today = "SELECT COUNT(o.id) AS onum,COUNT(oo.id) AS oonum,SUM(o.supplementary_money) AS exje,SUM(o.supplementary_money)/ COUNT(oo.id) AS ex_avg,s.shop_code,s.shop_name FROM (SELECT p.orderId,MAX(p.id) AS pid,MAX(s.id) AS sid  FROM c_customerphoto p LEFT JOIN c_customersp s ON p.orderId=s.orderId WHERE s.sptstate = 1 AND s.selectday BETWEEN '".$today."' AND '".$today."' GROUP BY orderId ) tem LEFT JOIN c_customerorder o ON tem.orderId = o.orderId LEFT JOIN c_customerphoto p ON tem.orderId = p.orderId AND p.id=tem.pid LEFT JOIN c_customersp s ON tem.orderId = s.orderId AND s.id=tem.sid LEFT JOIN c_customerorder oo on oo.orderId = o.orderId and oo.bargain_money>0 GROUP BY s.shop_code;";
                $sp_sql_month = "SELECT COUNT(o.id) AS onum,COUNT(oo.id) AS oonum,SUM(o.supplementary_money) AS exje,SUM(o.supplementary_money)/ COUNT(oo.id) AS ex_avg,s.shop_code,s.shop_name FROM (SELECT p.orderId,MAX(p.id) AS pid,MAX(s.id) AS sid  FROM c_customerphoto p LEFT JOIN c_customersp s ON p.orderId=s.orderId WHERE s.sptstate = 1 AND s.selectday BETWEEN '".$start."' AND '".$today."' GROUP BY orderId ) tem LEFT JOIN c_customerorder o ON tem.orderId = o.orderId LEFT JOIN c_customerphoto p ON tem.orderId = p.orderId AND p.id=tem.pid LEFT JOIN c_customersp s ON tem.orderId = s.orderId AND s.id=tem.sid LEFT JOIN c_customerorder oo on oo.orderId = o.orderId and oo.bargain_money>0 GROUP BY s.shop_code;";
                // 拍照sql
                $pz_sql_today = "SELECT COUNT(o.id) AS onum,COUNT(oo.id) AS oonum,SUM(o.supplementary_money) AS exje,SUM(o.supplementary_money)/ COUNT(oo.id) AS ex_avg,p.shop_code,p.shop_name FROM (SELECT p.orderId,MAX(p.id) AS pid,MAX(s.id) AS sid  FROM c_customerphoto p LEFT JOIN c_customersp s ON p.orderId=s.orderId WHERE s.sptstate = 1 AND s.selectday BETWEEN '".$today."' AND '".$today."' GROUP BY orderId ) tem LEFT JOIN c_customerorder o ON tem.orderId = o.orderId LEFT JOIN c_customerphoto p ON tem.orderId = p.orderId AND p.id=tem.pid LEFT JOIN c_customersp s ON tem.orderId = s.orderId AND s.id=tem.sid LEFT JOIN c_customerorder oo on oo.orderId = o.orderId and oo.bargain_money>0 GROUP BY p.shop_code;";
                $pz_sql_month = "SELECT COUNT(o.id) AS onum,COUNT(oo.id) AS oonum,SUM(o.supplementary_money) AS exje,SUM(o.supplementary_money)/ COUNT(oo.id) AS ex_avg,p.shop_code,p.shop_name FROM (SELECT p.orderId,MAX(p.id) AS pid,MAX(s.id) AS sid  FROM c_customerphoto p LEFT JOIN c_customersp s ON p.orderId=s.orderId WHERE s.sptstate = 1 AND s.selectday BETWEEN '".$start."' AND '".$today."' GROUP BY orderId ) tem LEFT JOIN c_customerorder o ON tem.orderId = o.orderId LEFT JOIN c_customerphoto p ON tem.orderId = p.orderId AND p.id=tem.pid LEFT JOIN c_customersp s ON tem.orderId = s.orderId AND s.id=tem.sid LEFT JOIN c_customerorder oo on oo.orderId = o.orderId and oo.bargain_money>0 GROUP BY p.shop_code;";

                $db = db()->connect('sx_erp_hs');
                // 选片数据 日
                $sp_info_today = $db->query($sp_sql_today);
                $spData_today = [];
                foreach ($sp_info_today as $key => $value) {
                    $spData_today[$value['shop_code']] = $value;
                }
                $sp_info_month = $db->query($sp_sql_month);
                $spData_month = [];
                foreach ($sp_info_month as $key => $value) {
                    $spData_month[$value['shop_code']] = $value;
                }
                // 拍照数据
                $pz_info_today = $db->query($pz_sql_today);
                $pzData_today = [];
                foreach ($pz_info_today as $key => $value) {
                    $pzData_today[$value['shop_code']] = $value;
                }
                $pz_info_month = $db->query($pz_sql_month);
                $pzData_month = [];
                foreach ($pz_info_month as $key => $value) {
                    $pzData_month[$value['shop_code']] = $value;
                }
                // 选片业绩 门店
                $return['xp_md_mh_yeji_today'] = number_format($spData_today['JZ001']['exje']);
                $return['xp_md_mh_yeji_month'] = number_format($spData_month['JZ001']['exje']);
                $return['xp_md_ja_yeji_today'] = number_format($spData_today['JZ002']['exje']);
                $return['xp_md_ja_yeji_month'] = number_format($spData_month['JZ002']['exje']);
                $return['xp_md_total_yeji_today'] = number_format($spData_today['JZ001']['exje']+$spData_today['JZ002']['exje']);
                $return['xp_md_total_yeji_month'] = number_format($spData_month['JZ001']['exje']+$spData_month['JZ002']['exje']);
                // 选片业绩-基地
                $return['xp_fz_yeji_today'] = number_format($pzData_today['JZ003']['exje']);
                $return['xp_fz_yeji_month'] = number_format($pzData_month['JZ003']['exje']);
                $return['xp_jn_yeji_today'] = number_format($pzData_today['JZ004']['exje']);
                $return['xp_jn_yeji_month'] = number_format($pzData_month['JZ004']['exje']);
                $return['xp_total_yeji_today'] = number_format($pzData_today['JZ003']['exje']+$pzData_today['JZ004']['exje']);
                $return['xp_total_yeji_month'] = number_format($pzData_month['JZ003']['exje']+$pzData_month['JZ004']['exje']);
                // 选片均价-门店
                $return['xp_md_mh_avg_today'] = number_format($spData_today['JZ001']['ex_avg']);
                $return['xp_md_mh_avg_month'] = number_format($spData_month['JZ001']['ex_avg']);
                $return['xp_md_ja_avg_today'] = number_format($spData_today['JZ002']['ex_avg']);
                $return['xp_md_ja_avg_month'] = number_format($spData_month['JZ002']['ex_avg']);
                // 选片均价-基地
                $return['xp_fz_avg_today'] = number_format($pzData_today['JZ003']['ex_avg']);
                $return['xp_fz_avg_month'] = number_format($pzData_month['JZ003']['ex_avg']);
                $return['xp_jn_avg_today'] = number_format($pzData_today['JZ004']['ex_avg']);
                $return['xp_jn_avg_month'] = number_format($pzData_month['JZ004']['ex_avg']);

                cache('dp_xpDetail',$return,40);
            }
            return $return;
        }
    /*-------------------手机大屏--选片------end---------------------*/

    /*-------------------手机大屏--门店情况------start---------------------*/
        //进客量
        public function md_jd(){
            // $return = cache('dp_md_jd');
            if(empty($return)){
                $jdSql = " op_signinfo IS NULL OR op_signinfo='' ";
                $jd_today = db('c_customer_intostore')->where('status',1)->where('is_intostore','in',[2,4,5])->where($jdSql)->where('reback',1)->whereTime('syjd_day','between',[$this->today['start'],$this->today['end']])->group('consulation_shop_code')->column('count(id)','consulation_shop_code');
                $jd_month = db('c_customer_intostore')->where('status',1)->where('is_intostore','in',[2,4,5])->where($jdSql)->where('reback',1)->whereTime('syjd_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->group('consulation_shop_code')->column('count(id)','consulation_shop_code');
                // var_dump($jd_today);
                // var_dump($jd_month);die;
                $return['jd_mh_today'] = $jd_today['JZ001'] ? $jd_today['JZ001'] : 0;//闵行
                $return['jd_ja_today'] = $jd_today['JZ002'] ? $jd_today['JZ002'] : 0;//静安
                $return['jd_xh_today'] = $jd_today['JZ005'] ? $jd_today['JZ005'] : 0;//徐汇
                $return['jd_total_today'] = $jd_today['JZ001']+$jd_today['JZ002']+$jd_today['JZ005'];
                $return['jd_mh_month'] = $jd_month['JZ001'] ? $jd_month['JZ001'] : 0;//闵行
                $return['jd_ja_month'] = $jd_month['JZ002'] ? $jd_month['JZ002'] : 0;//静安
                $return['jd_xh_month'] = $jd_month['JZ005'] ? $jd_month['JZ005'] : 0;//徐汇
                $return['jd_total_month'] = $jd_month['JZ001']+$jd_month['JZ002']+$jd_month['JZ005'];
                cache('dp_md_jd',$return,80);
            }
            return $return;
        }
        //门店 单量比重
        public function md_order(){
            $start = date('Ym01',strtotime($this->thisMonth['start']));
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('dp_md_order');
            if(empty($return)){
                $todays['start'] = $today;
                $todays['end'] = $today;
                $temp_today = $this->totalOrder($todays);
                $order_today = [];
                foreach ($temp_today['sign'] as $key => $value) {
                    $order_today[$value['shop_code']] = $value;
                }
                $month['start'] = $start;
                $month['end'] = $today;
                $temp_month = $this->totalOrder($month);
                $order_month = [];
                foreach ($temp_month['sign'] as $key => $value) {
                    $order_month[$value['shop_code']] = $value;
                }
                //闵行
                $return['jd_order_mh_today'] = $order_today['JZ001']['yx'] - $order_today['JZ001']['zf'];
                $return['jd_order_mh_month'] = $order_month['JZ001']['yx'] - $order_month['JZ001']['zf'];
                // 静安
                $return['jd_order_ja_today'] = $order_today['JZ002']['yx'] - $order_today['JZ002']['zf'];
                $return['jd_order_ja_month'] = $order_month['JZ002']['yx'] - $order_month['JZ002']['zf'];
                // 徐汇
                $return['jd_order_xh_today'] = $order_today['JZ005']['yx'] - $order_today['JZ005']['zf'];
                $return['jd_order_xh_month'] = $order_month['JZ005']['yx'] - $order_month['JZ005']['zf'];
                //线上订单
                $return['jd_order_online_today'] = $order_today['WX002']['yx']+$order_today['WX003']['yx'] - $order_today['WX002']['zf']-$order_today['WX003']['zf'];
                $return['jd_order_online_month'] = $order_month['WX002']['yx']+$order_month['WX003']['yx'] - $order_month['WX002']['zf']-$order_month['WX003']['zf'];
                // 总计
                $return['jd_order_total_today'] = $return['jd_order_mh_today']+$return['jd_order_ja_today']+$return['jd_order_xh_today']+$return['jd_order_online_today'];
                $return['jd_order_total_month'] = $return['jd_order_mh_month']+$return['jd_order_ja_month']+$return['jd_order_xh_month']+$return['jd_order_online_month'];
                cache('dp_md_order',$return,70);
            }
            return $return;
        }
        //门店 转介绍单量
        public function md_zjs_order(){
            $start = date('Ym01',strtotime($this->thisMonth['start']));
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('md_zjs_order');
            if(empty($return)) {
                $todays['start'] = $today;
                $todays['end'] = $today;
                $todays['cssname'] = '转介绍';

                $month['start'] = $start;
                $month['end'] = $today;
                $month['cssname'] = '转介绍';

                // 闵行
                $todays['customer_channel'] = '闵行门市部';
                $mh_today = $this->totalOrder($todays);
                $month['customer_channel'] = '闵行门市部';
                $mh_month = $this->totalOrder($month);
                $return['jd_zjs_order_mh_today'] = $mh_today['order'];
                $return['jd_zjs_order_mh_month'] = $mh_month['order'];
                // 静安
                $todays['customer_channel'] = '静安门市部,静安门市2部,静安门市1部,静安前台';
                $ja_today = $this->totalOrder($todays);
                $month['customer_channel'] = '静安门市部,静安门市2部,静安门市1部,静安前台';
                $ja_month = $this->totalOrder($month);
                $return['jd_zjs_order_ja_today'] = $ja_today['order'];
                $return['jd_zjs_order_ja_month'] = $ja_month['order'];
                // 徐汇
                $todays['customer_channel'] = '徐汇门市部';
                $xh_today = $this->totalOrder($todays);
                $month['customer_channel'] = '徐汇门市部';
                $xh_month = $this->totalOrder($month);
                $return['jd_zjs_order_xh_today'] = $xh_today['order'];
                $return['jd_zjs_order_xh_month'] = $xh_month['order'];
                // 总计
                $return['jd_zjs_order_total_today'] = $return['jd_zjs_order_mh_today']+$return['jd_zjs_order_ja_today']+$return['jd_zjs_order_xh_today'];
                $return['jd_zjs_order_total_month'] = $return['jd_zjs_order_mh_month']+$return['jd_zjs_order_ja_month']+$return['jd_zjs_order_xh_month'];
                cache('md_zjs_order',$return,60);
            }
            return $return;
        }
        //成交率
        public function md_order_rate(){
            $jd = $this->md_jd();
            $order = $this->md_order();
            $return['jd_order_rate_mh_today'] = $order['jd_order_mh_today'] ? number_format($order['jd_order_mh_today']/$jd['jd_mh_today']*100,2) : '0';//闵行
            if ($return['jd_order_rate_mh_today']>100) {
                $return['jd_order_rate_mh_today'] = '100';
            }else{
                $return['jd_order_rate_mh_today'] = $return['jd_order_rate_mh_today'];
            }
            $return['jd_order_rate_ja_today'] = $order['jd_order_ja_today'] ? number_format($order['jd_order_ja_today']/$jd['jd_ja_today']*100,2) : '0';//静安
            if ($return['jd_order_rate_ja_today']>100) {
                $return['jd_order_rate_ja_today'] = '100';
            }else{
                $return['jd_order_rate_ja_today'] = $return['jd_order_rate_ja_today'];
            }
            $return['jd_order_rate_xh_today'] = $order['jd_order_xh_today'] ? number_format($order['jd_order_xh_today']/$jd['jd_xh_today']*100,2) : '0';//徐汇
            if ($return['jd_order_rate_xh_today']>100) {
                $return['jd_order_rate_xh_today'] = '100';
            }else{
                $return['jd_order_rate_xh_today'] = $return['jd_order_rate_xh_today'];
            }
            $return['jd_order_rate_mh_month'] = $order['jd_order_mh_month'] ? number_format($order['jd_order_mh_month']/$jd['jd_mh_month']*100,2) : '0';//闵行
            if ($return['jd_order_rate_mh_month']>100) {
                $return['jd_order_rate_mh_month'] = '100';
            }else{
                $return['jd_order_rate_mh_month'] = $return['jd_order_rate_mh_month'];
            }
            $return['jd_order_rate_ja_month'] = $order['jd_order_ja_month'] ? number_format($order['jd_order_ja_month']/$jd['jd_ja_month']*100,2) : '0';//静安
            if ($return['jd_order_rate_ja_month']>100) {
                $return['jd_order_rate_ja_month'] = '100';
            }else{
                $return['jd_order_rate_ja_month'] = $return['jd_order_rate_ja_month'];
            }
            $return['jd_order_rate_xh_month'] = $order['jd_order_xh_month'] ? number_format($order['jd_order_xh_month']/$jd['jd_xh_month']*100,2) : '0';//徐汇
            if ($return['jd_order_rate_xh_month']>100) {
                $return['jd_order_rate_xh_month'] = '100';
            }else{
                $return['jd_order_rate_xh_month'] = $return['jd_order_rate_xh_month'];
            }
            return $return;
        }
        //门店均价  一销套系均价
        public function md_yi_avg(){
            // $return = cache('dp_md_yi_avg');
            $start = date('Ym01',strtotime($this->thisMonth['start']));
            $today = date('Ymd',strtotime($this->today['start']));
            if(empty($return)){
                // 当日
                $todays['start'] = $today;
                $todays['end'] = $today;
                $md_toady = $this->totalOrder($todays);

                $return['md_mh_avg_today'] = number_format($md_toady['sign']['JZ001']['yeji']/($md_toady['sign']['JZ001']['yx']-$md_toady['sign']['JZ001']['zf']));
                $return['md_ja_avg_today'] = number_format($md_toady['sign']['JZ002']['yeji']/($md_toady['sign']['JZ002']['yx']-$md_toady['sign']['JZ002']['zf']));
                $return['md_xh_avg_today'] = number_format($md_toady['sign']['JZ005']['yeji']/($md_toady['sign']['JZ005']['yx']-$md_toady['sign']['JZ005']['zf']));
                $return['md_online_avg_today'] = number_format(($md_toady['sign']['WX002']['yeji']+$md_toady['sign']['WX003']['yeji'])/($md_toady['sign']['WX002']['yx']+$md_toady['sign']['WX003']['yx']-$md_toady['sign']['WX002']['zf']-$md_toady['sign']['WX003']['zf']));
                // 本月
                $month['start'] = $start;
                $month['end'] = $today;
                $md_month = $this->totalOrder($month);
                $return['md_mh_avg_month'] = number_format($md_month['sign']['JZ001']['yeji']/($md_month['sign']['JZ001']['yx']-$md_month['sign']['JZ001']['zf']));
                $return['md_ja_avg_month'] = number_format($md_month['sign']['JZ002']['yeji']/($md_month['sign']['JZ002']['yx']-$md_month['sign']['JZ002']['zf']));
                $return['md_xh_avg_month'] = number_format($md_month['sign']['JZ005']['yeji']/($md_month['sign']['JZ005']['yx']-$md_month['sign']['JZ005']['zf']));
                $return['md_online_avg_month'] = number_format(($md_month['sign']['WX002']['yeji']+$md_month['sign']['WX003']['yeji'])/($md_month['sign']['WX002']['yx']+$md_month['sign']['WX003']['yx']-$md_month['sign']['WX002']['zf']-$md_month['sign']['WX003']['zf']));
                cache('dp_md_yi_avg',$return,160);
            }
            return $return;
        }
    /*-------------------手机大屏--门店情况------end---------------------*/
    
    /*-------------------手机大屏--转介绍详情------start---------------------*/
        //转介绍门店客资分布量
        public function zjsMkz(){
            // $return = cache('dp_zjsMkz');
            if(empty($return)){
                $mkzWhere['is_status'] = 1;
                $mkzWhere['c_from'] = 1;
                $mkzWhere['shop_code|add_shop_code'] = $this->zjsshop;
                $total_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->count('id');
                $total_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->count('id');
                $return['zjs_total_mkz_today'] = number_format($total_today);
                $return['zjs_total_mkz_month'] = number_format($total_month);
                // 静安毛客资
                $ja_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','in',$this->jachannel)->count('id');
                $ja_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','in',$this->jachannel)->count('id');
                $return['zjs_ja_mkz_today'] = number_format($ja_mkz_today);
                $return['zjs_ja_mkz_month'] = number_format($ja_mkz_month);
                // 闵行毛客资
                $mh_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','in',$this->mhchannel)->count('id');
                $mh_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','in',$this->mhchannel)->count('id');
                $return['zjs_mh_mkz_today'] = number_format($mh_mkz_today);
                $return['zjs_mh_mkz_month'] = number_format($mh_mkz_month);
                // 徐汇毛客资
                $xh_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','in',$this->xhchannel)->count('id');
                $xh_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','in',$this->xhchannel)->count('id');
                $return['zjs_xh_mkz_today'] = number_format($xh_mkz_today);
                $return['zjs_xh_mkz_month'] = number_format($xh_mkz_month);
                // 蜂巢毛客资
                $fc_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','like', '蜂巢%')->count('id');
                $fc_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','like', '蜂巢%')->count('id');
                $return['zjs_fz_mkz_today'] = number_format($fc_mkz_today);
                $return['zjs_fz_mkz_month'] = number_format($fc_mkz_month);
                // 嘉娜毛客资
                $jiana_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','like', '嘉娜%')->count('id');
                $jiana_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','like', '嘉娜%')->count('id');
                $return['zjs_jiana_mkz_today'] = number_format($jiana_mkz_today);
                $return['zjs_jiana_mkz_month'] = number_format($jiana_mkz_month);
                // 其他
                $return['zjs_qita_mkz_today'] = number_format($total_today-$ja_mkz_today-$mh_mkz_today-$xh_mkz_today-$fc_mkz_today-$jiana_mkz_today);
                $return['zjs_qita_mkz_month'] = number_format($total_month-$ja_mkz_month-$mh_mkz_month-$xh_mkz_month-$fc_mkz_month-$jiana_mkz_month);//其他
                cache('dp_zjsMkz',$return,2*60);
            }
            return $return;
        }
        //转介绍 门店-日转介绍情况
        public function mdZjsToday(){
            // $today = date('Ymd');
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('dp_mdZjsToday');
            if(empty($return)){
                // 订单量
                $todays['start'] = $today;
                $todays['end'] = $today;
                $order_today = $this->totalOrder($todays);
                $order_today_new = $order_today['sign'];
                $return['ja_order_today'] = number_format($order_today_new['JZ002']['yx']-$order_today_new['JZ002']['zf']);
                $return['mh_order_today'] = number_format($order_today_new['JZ001']['yx']-$order_today_new['JZ001']['zf']);
                $return['xh_order_today'] = number_format($order_today_new['JZ005']['yx']-$order_today_new['JZ005']['zf']);
                // 客资量
                $ja_mkz_today = db('c_customerinfo')->where('is_status',1)->where('c_from',1)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','in','静安门市部,静安选片部')->count('id');
                $mh_mkz_today = db('c_customerinfo')->where('is_status',1)->where('c_from',1)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','in','闵行门市部,闵行选片部')->count('id');
                $xh_mkz_today = db('c_customerinfo')->where('is_status',1)->where('c_from',1)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','in','徐汇门市部')->count('id');
                $return['zjs_ja_mkz_today'] = number_format($ja_mkz_today);
                $return['zjs_mh_mkz_today'] = number_format($mh_mkz_today);
                $return['zjs_xh_mkz_today'] = number_format($xh_mkz_today);
                // 客资订单率
                $return['ja_mkz_order_today'] = number_format(($order_today_new['JZ002']['yx']-$order_today_new['JZ002']['zf'])/$ja_mkz_today*100,2);
                if ($return['ja_mkz_order_today']>100) {
                    $return['ja_mkz_order_today'] = '100%';
                }else{
                    $return['ja_mkz_order_today'] = $return['ja_mkz_order_today'].'%';
                }
                $return['mh_mkz_order_today'] = number_format(($order_today_new['JZ001']['yx']-$order_today_new['JZ001']['zf'])/$mh_mkz_today*100,2);
                if ($return['mh_mkz_order_today']>100) {
                    $return['mh_mkz_order_today'] = '100%';
                }else{
                    $return['mh_mkz_order_today'] = $return['mh_mkz_order_today'].'%';
                }
                $return['xh_mkz_order_today'] = number_format(($order_today_new['JZ005']['yx']-$order_today_new['JZ005']['zf'])/$xh_mkz_today*100,2);
                if ($return['xh_mkz_order_today']>100) {
                    $return['xh_mkz_order_today'] = '100%';
                }else{
                    $return['xh_mkz_order_today'] = $return['xh_mkz_order_today'].'%';
                }
                //转介绍订单量
                $todays['start'] = $today;
                $todays['end'] = $today;
                $todays['cssname'] = '转介绍';
                // 静安
                $todays['customer_channel'] = '静安门市部,静安门市2部,静安门市1部,静安前台';
                $ja_today = $this->totalOrder($todays);
                $return['zjs_ja_order_today'] = number_format($ja_today['order']);
                // 闵行
                $todays['customer_channel'] = '闵行门市部';
                $mh_today = $this->totalOrder($todays);
                $return['zjs_mh_order_today'] = number_format($mh_today['order']);
                // 徐汇
                $todays['customer_channel'] = '徐汇门市部';
                $xh_today = $this->totalOrder($todays);
                $return['zjs_xh_order_today'] = number_format($xh_today['order']);
                // 转介绍订单率
                $return['zjs_ja_mkz_order_today'] = number_format($ja_today['order']/($order_today_new['JZ002']['yx']-$order_today_new['JZ002']['zf'])*100,2);
                if ($return['zjs_ja_mkz_order_today']>100) {
                    $return['zjs_ja_mkz_order_today'] = '100%';
                }else{
                    $return['zjs_ja_mkz_order_today']= $return['zjs_ja_mkz_order_today'].'%';
                }
                $return['zjs_mh_mkz_order_today'] = number_format($mh_today['order']/($order_today_new['JZ001']['yx']-$order_today_new['JZ001']['zf'])*100,2);
                if ($return['zjs_mh_mkz_order_today']>100) {
                    $return['zjs_mh_mkz_order_today'] = '100%';
                }else{
                    $return['zjs_mh_mkz_order_today']= $return['zjs_mh_mkz_order_today'].'%';
                }
                $return['zjs_xh_mkz_order_today'] = number_format($xh_today['order']/($order_today_new['JZ005']['yx']-$order_today_new['JZ005']['zf'])*100,2);
                if ($return['zjs_xh_mkz_order_today']>100) {
                    $return['zjs_xh_mkz_order_today'] = '100%';
                }else{
                    $return['zjs_xh_mkz_order_today']= $return['zjs_xh_mkz_order_today'].'%';
                }
                cache('dp_mdZjsToday',$return,60);
            }
            return $return;
        }
        //转介绍 门店-月转介绍情况
        public function mdZjsMonth(){
            $start = date('Ym01',strtotime($this->thisMonth['start']));
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('dp_mdZjsMonth');
            if(empty($return)){
                // 订单量
                $month['start'] = $start;
                $month['end'] = $today;
                $order_month = $this->totalOrder($month);
                $order_month_new = $order_month['sign'];
                $return['ja_order_month'] = number_format($order_month_new['JZ002']['yx']-$order_today_new['JZ002']['zf']);
                $return['mh_order_month'] = number_format($order_month_new['JZ001']['yx']-$order_today_new['JZ001']['zf']);
                $return['xh_order_month'] = number_format($order_month_new['JZ005']['yx']-$order_today_new['JZ005']['zf']);
                // 客资量
                $mkzWhere['is_status'] = 1;
                $mkzWhere['c_from'] = 1;
                $mkzWhere['shop_code|add_shop_code'] = $this->zjsshop;
                $ja_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','in','静安门市部,静安选片部')->count('id');
                $mh_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','in','闵行门市部,闵行选片部')->count('id');
                $xh_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','in','徐汇门市部')->count('id');
                $return['zjs_ja_mkz_month'] = number_format($ja_mkz_month);
                $return['zjs_mh_mkz_month'] = number_format($mh_mkz_month);
                $return['zjs_xh_mkz_month'] = number_format($xh_mkz_month);
                // 客资订单率
                $return['ja_mkz_order_month'] = number_format(($order_month_new['JZ002']['yx']-$order_today_new['JZ002']['zf'])/$ja_mkz_month*100,2);
                if ($return['ja_mkz_order_month']>100) {
                    $return['ja_mkz_order_month'] = '100%';
                }else{
                    $return['ja_mkz_order_month']= $return['ja_mkz_order_month'].'%';
                }
                $return['mh_mkz_order_month'] = number_format(($order_month_new['JZ001']['yx']-$order_today_new['JZ001']['zf'])/$mh_mkz_month*100,2);
                if ($return['mh_mkz_order_month']>100) {
                    $return['mh_mkz_order_month'] = '100%';
                }else{
                    $return['mh_mkz_order_month']= $return['mh_mkz_order_month'].'%';
                }
                $return['xh_mkz_order_month'] = number_format(($order_month_new['JZ005']['yx']-$order_today_new['JZ005']['zf'])/$xh_mkz_month*100,2);
                if ($return['xh_mkz_order_month']>100) {
                    $return['xh_mkz_order_month'] = '100%';
                }else{
                    $return['xh_mkz_order_month']= $return['xh_mkz_order_month'].'%';
                }
                //转介绍订单量
                $month['cssname'] = '转介绍';
                // 静安
                $month['customer_channel'] = '静安门市部,静安门市2部,静安门市1部,静安前台';
                $ja_today = $this->totalOrder($month);
                $return['zjs_ja_order_month'] = number_format($ja_today['order']);
                // 闵行
                $month['customer_channel'] = '闵行门市部';
                $mh_today = $this->totalOrder($month);
                $return['zjs_mh_order_month'] = number_format($mh_today['order']);
                // 徐汇
                $month['customer_channel'] = '徐汇门市部';
                $xh_today = $this->totalOrder($month);
                $return['zjs_xh_order_month'] = number_format($xh_today['order']);
                // 转介绍订单率
                $return['zjs_ja_mkz_order_month'] = number_format($ja_today['order']/($order_month_new['JZ002']['yx']-$order_today_new['JZ002']['zf'])*100,2);
                if ($return['zjs_ja_mkz_order_month']>100) {
                    $return['zjs_ja_mkz_order_month'] = '100%';
                }else{
                    $return['zjs_ja_mkz_order_month'] = $return['zjs_ja_mkz_order_month'].'%';
                }
                $return['zjs_mh_mkz_order_month'] = number_format($mh_today['order']/($order_month_new['JZ001']['yx']-$order_today_new['JZ001']['zf'])*100,2);
                if ($return['zjs_mh_mkz_order_month']>100) {
                    $return['zjs_mh_mkz_order_month'] = '100%';
                }else{
                    $return['zjs_mh_mkz_order_month'] = $return['zjs_mh_mkz_order_month'].'%';
                }
                $return['zjs_xh_mkz_order_month'] = number_format($xh_today['order']/($order_month_new['JZ005']['yx']-$order_today_new['JZ005']['zf'])*100,2);
                if ($return['zjs_xh_mkz_order_month']>100) {
                    $return['zjs_xh_mkz_order_month'] = '100%';
                }else{
                    $return['zjs_xh_mkz_order_month'] = $return['zjs_xh_mkz_order_month'].'%';
                }
                cache('dp_mdZjsMonth',$return,90);
            }
            return $return;
        }
        //转介绍 基地 日转介绍情况
        public function zjsJdToday(){
            // $today = date('Ymd');
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('dp_zjsJdToday');
            if(empty($return)){
                $info = $this->psInfo();
                //拍摄新单量
                $return['ps_fz_order_today'] = $info['ps_fc_order_today'];
                $return['ps_jiana_order_today'] = $info['ps_jn_order_today'];
                //客资量
                $mkzWhere['is_status'] = 1;
                $mkzWhere['c_from'] = 1;
                $mkzWhere['shop_code|add_shop_code'] = $this->zjsshop;
                // 蜂巢毛客资
                $fc_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','like', '蜂巢%')->count('id');
                $return['zjs_fz_mkz_today'] = number_format($fc_mkz_today);
                // 嘉娜毛客资
                $jiana_mkz_today = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->today['start'],$this->today['end']])->where('customer_channel','like', '嘉娜%')->count('id');
                $return['zjs_jiana_mkz_today'] = number_format($jiana_mkz_today);
                // 客资提报率
                $return['fz_mkz_order_today'] = number_format($return['ps_fz_order_today']/$fc_mkz_today*100,2);
                if ($return['fz_mkz_order_today']>100) {
                    $return['fz_mkz_order_today'] = '100%';
                }else{
                    $return['fz_mkz_order_today'] = $return['fz_mkz_order_today'].'%';
                }
                $return['jiana_mkz_order_today'] = number_format($return['ps_jiana_order_today']/$jiana_mkz_today*100,2);
                if ($return['jiana_mkz_order_today']>100) {
                    $return['jiana_mkz_order_today'] = '100%';
                }else{
                    $return['jiana_mkz_order_today'] = $return['jiana_mkz_order_today'].'%';
                }
                // 转介绍订单量
                $today['customer_channel'] = '蜂巢';
                $today['seache_type'] = 'like';
                $today['start'] = $today;
                $today['end'] = $today;
                $fz_today = $this->totalOrder($today);
                $today['customer_channel'] = '嘉娜';
                $jn_today = $this->totalOrder($today);
                $return['zjs_fz_order_today'] = number_format($fz_today['zjs']);
                $return['zjs_jiana_order_today'] = number_format($jn_today['zjs']);
                // 转介绍订单率
                $return['zjs_fz_mkz_order_today'] = number_format($fz_today['zjs']/$info['ps_fc_order_today']*100,2);
                if ($return['zjs_fz_mkz_order_today']>100) {
                    $return['zjs_fz_mkz_order_today'] = '100%';
                }else{
                    $return['zjs_fz_mkz_order_today'] = $return['zjs_fz_mkz_order_today'].'%';
                }
                $return['zjs_jiana_mkz_order_today'] = number_format($jn_today['zjs']/$info['ps_jn_order_today']*100,2);
                if ($return['zjs_jiana_mkz_order_today']>100) {
                    $return['zjs_jiana_mkz_order_today'] = '100%';
                }else{
                    $return['zjs_jiana_mkz_order_today'] = $return['zjs_jiana_mkz_order_today'].'%';
                }
                cache('dp_zjsJdToday',$return,120);
            }
            return $return;
        }
        //转介绍 基地 月转介绍情况
        public function zjsJdMonth(){
            // $start= date('Ym01');
            // $today = date('Ymd');
            $start = date('Ym01',strtotime($this->thisMonth['start']));
            $today = date('Ymd',strtotime($this->today['start']));
            // $return = cache('dp_zjsJdMonth');
            if(empty($return)){
                $info = $this->psInfo();
                //拍摄新单量
                $return['ps_fz_order_month'] = $info['ps_fc_order_month'];
                $return['ps_jiana_order_month'] = $info['ps_jn_order_month'];
                //客资量
                $mkzWhere['is_status'] = 1;
                $mkzWhere['c_from'] = 1;
                $mkzWhere['shop_code|add_shop_code'] = $this->zjsshop;
                // 蜂巢毛客资
                $fc_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','like', '蜂巢%')->count('id');
                $return['zjs_fz_mkz_month'] = number_format($fc_mkz_month);
                // 嘉娜毛客资
                $jiana_mkz_month = db('c_customerinfo')->where($mkzWhere)->whereTime('dj_day','between',[$this->thisMonth['start'],$this->thisMonth['end']])->where('customer_channel','like', '嘉娜%')->count('id');
                $return['zjs_jiana_mkz_month'] = number_format($jiana_mkz_month);
                // 客资提报率
                $temp_pc_fc = (explode(',',$info['ps_fc_order_month']));
                $ps_fc_order_month = '';
                foreach ($temp_pc_fc as $key => $value) {
                    $ps_fc_order_month.=$value;
                }
                $temp_pc_jn = (explode(',',$info['ps_jn_order_month']));
                $ps_jn_order_month = '';
                foreach ($temp_pc_jn as $key => $value) {
                    $ps_jn_order_month.=$value;
                }
                $return['fz_mkz_order_month'] = number_format($ps_fc_order_month/$fc_mkz_month*100,2);
                if ($return['fz_mkz_order_month']>100) {
                    $return['fz_mkz_order_month'] = '100%';
                }else{
                    $return['fz_mkz_order_month'] = $return['fz_mkz_order_month'].'%';
                }
                $return['jiana_mkz_order_month'] = number_format($ps_jn_order_month/$jiana_mkz_month*100,2);
                if ($return['jiana_mkz_order_month']>100) {
                    $return['jiana_mkz_order_month'] = '100%';
                }else{
                    $return['jiana_mkz_order_month'] = $return['jiana_mkz_order_month'].'%';
                }
                //转介绍订单量
                $month['customer_channel'] = '蜂巢';
                $month['seache_type'] = 'like';
                $month['start'] = $start;
                $month['end'] = $today;
                $fz_month = $this->totalOrder($month);
                $month['customer_channel'] = '嘉娜';
                $jn_month = $this->totalOrder($month);
                $return['zjs_fz_order_month'] = number_format($fz_month['zjs']);
                $return['zjs_jiana_order_month'] = number_format($jn_month['zjs']);
                // 转介绍订单率
                $return['zjs_fz_mkz_order_month'] = number_format(($fz_month['zjs']/$ps_fc_order_month)*100,2);
                if ($return['zjs_fz_mkz_order_month']>100) {
                    $return['zjs_fz_mkz_order_month'] = '100%';
                }else{
                    $return['zjs_fz_mkz_order_month'] = $return['zjs_fz_mkz_order_month'].'%';
                }
                $return['zjs_jiana_mkz_order_month'] = number_format(($jn_month['zjs']/$ps_jn_order_month)*100,2);
                if ($return['zjs_jiana_mkz_order_month']>100) {
                    $return['zjs_jiana_mkz_order_month'] = '100%';
                }else{
                    $return['zjs_jiana_mkz_order_month'] = $return['zjs_jiana_mkz_order_month'].'%';
                }
                
                cache('dp_zjsJdMonth',$return,110);
            }
            return $return;
        }
    /*-------------------手机大屏--转介绍详情------end---------------------*/
}