diff --git a/api/controllers/wxapp/licheb/Statistics.php b/api/controllers/wxapp/licheb/Statistics.php index 59273a6a..fa823b51 100644 --- a/api/controllers/wxapp/licheb/Statistics.php +++ b/api/controllers/wxapp/licheb/Statistics.php @@ -1,5 +1,5 @@ login_white = array();//登录白名单 @@ -19,47 +22,48 @@ class Statistics extends Wxapp{ $this->check_headimg = array();//授权微信信息 $this->load->model("biz/biz_model"); - $this->load->model("biz/biz_model"); - $this->load->model('receiver/receiver_customers_model','customers_model'); - $this->load->model('receiver/order/receiver_orders_model','orders_model'); - $this->load->model('receiver/receiver_customer_sign_model','customer_sign_model'); + $this->load->model('receiver/receiver_customers_model', 'customers_model'); + $this->load->model('receiver/order/receiver_orders_model', 'orders_model'); + $this->load->model('receiver/receiver_customer_sign_model', 'customer_sign_model'); + } + + protected function get() + { + } - - protected function get(){ - } - //统计客户 - protected function get_cust(){ + protected function get_cust() + { $season = $this->input_param('season'); $city_id = $this->input_param('city_id'); - !strlen($season) && $season = date('n')-1;//当前月份 - $month = $season+1; + !strlen($season) && $season = date('n') - 1;//当前月份 + $month = $season + 1; $season_data = $this->months(); $series = []; $bizs = []; $months_arr = []; $months_arr[] = [ - 'cn' => $season_data[$season], - 's_time' => date("Y-{$month}-01 00:00:00"), - 'e_time' => date("Y-{$month}-t 23:59:59"), + 'cn' => $season_data[$season], + 's_time' => date("Y-{$month}-01 00:00:00"), + 'e_time' => date("Y-{$month}-t 23:59:59"), ]; $fileds = 'id,biz_name'; - $biz_id_arr = explode(',',$this->session['biz_id']); - if($this->session['biz_id'] && $biz_id_arr){ - $city_id && $o_where = ['city_id'=>$city_id]; - $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr,$o_where,$fileds); - }else{ - $bizs_lists = $this->biz_model->select(['status'=>1,'city_id'=>$city_id],'id desc','','',$fileds); + $biz_id_arr = explode(',', $this->session['biz_id']); + if ($this->session['biz_id'] && $biz_id_arr) { + $city_id && $o_where = ['city_id' => $city_id]; + $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr, $o_where, $fileds); + } else { + $bizs_lists = $this->biz_model->select(['status' => 1, 'city_id' => $city_id], 'id desc', '', '', $fileds); } - if($bizs_lists){ - $bizs = array_column($bizs_lists,'biz_name'); - foreach($bizs_lists as $key=>$val){ + if ($bizs_lists) { + $bizs = array_column($bizs_lists, 'biz_name'); + foreach ($bizs_lists as $key => $val) { $count_data = []; - foreach($months_arr as $v2){ + foreach ($months_arr as $v2) { $where = [ 'biz_id' => $val['id'], - 'status>=' => 0, + 'status>=' => 0, 'c_time>=' => strtotime($v2['s_time']), 'c_time<=' => strtotime($v2['e_time']), 'brand_id!=' => 3, @@ -73,32 +77,32 @@ class Statistics extends Wxapp{ ]; } } - $stat_data = [ + $stat_data = [ 'tooltip' => [ 'trigger' => 'axis', - 'axisPointer' => ['type'=>'shadow'] + 'axisPointer' => ['type' => 'shadow'] ], 'legend' => [ 'top' => 'bottom', - 'data'=> $bizs + 'data' => $bizs ], 'grid' => [ - 'top' => '8%', - 'left' => '2%', - 'right' => '5%', - 'bottom' => '12%', - 'containLabel' => true + 'top' => '8%', + 'left' => '2%', + 'right' => '5%', + 'bottom' => '12%', + 'containLabel' => true ], 'xAxis' => [ - 'type' => 'value', - 'boundaryGap' => [0, 0.01] + 'type' => 'value', + 'boundaryGap' => [0, 0.01] ], 'yAxis' => [ - 'type' => 'category', - 'data' => array_column($months_arr,'cn') + 'type' => 'category', + 'data' => array_column($months_arr, 'cn') ], 'series' => $series - ]; + ]; $data = [ 'stat_data' => $stat_data, 'season_data' => $season_data, @@ -108,38 +112,39 @@ class Statistics extends Wxapp{ } //统计订单 - protected function get_orders(){ + protected function get_orders() + { $season = $this->input_param('season'); $city_id = $this->input_param('city_id'); - !strlen($season) && $season = ceil((date('n'))/3)-1;//当月是第几季度 - $season_data = $this->season_data($season+1); - $days = getMonth($season+1); + !strlen($season) && $season = ceil((date('n')) / 3) - 1;//当月是第几季度 + $season_data = $this->season_data($season + 1); + $days = getMonth($season + 1); $series = []; $bizs = []; $months_arr = []; - foreach($days as $val){ + foreach ($days as $val) { $months_arr[] = [ - 'cn' => date('n月',strtotime($val)), - 's_time' => date('Y-m-01 00:00:00',strtotime($val)), - 'e_time' => date('Y-m-t 23:59:59',strtotime($val)), + 'cn' => date('n月', strtotime($val)), + 's_time' => date('Y-m-01 00:00:00', strtotime($val)), + 'e_time' => date('Y-m-t 23:59:59', strtotime($val)), ]; } $fileds = 'id,biz_name'; - $biz_id_arr = explode(',',$this->session['biz_id']); - if($this->session['biz_id'] && $biz_id_arr){ - $city_id && $o_where = ['city_id'=>$city_id]; - $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr,$o_where,$fileds); - }else{ - $bizs_lists = $this->biz_model->select(['status'=>1,'city_id'=>$city_id],'id desc','','',$fileds); + $biz_id_arr = explode(',', $this->session['biz_id']); + if ($this->session['biz_id'] && $biz_id_arr) { + $city_id && $o_where = ['city_id' => $city_id]; + $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr, $o_where, $fileds); + } else { + $bizs_lists = $this->biz_model->select(['status' => 1, 'city_id' => $city_id], 'id desc', '', '', $fileds); } - if($bizs_lists){ - $bizs = array_column($bizs_lists,'biz_name'); - foreach($bizs_lists as $key=>$val){ + if ($bizs_lists) { + $bizs = array_column($bizs_lists, 'biz_name'); + foreach ($bizs_lists as $key => $val) { $count_data = []; - foreach($months_arr as $v2){ + foreach ($months_arr as $v2) { $where = [ 'biz_id' => $val['id'], - 'status>=' => 0, + 'status>=' => 0, 'c_time>=' => strtotime($v2['s_time']), 'c_time<=' => strtotime($v2['e_time']), 'brand_id!=' => 3, @@ -158,7 +163,7 @@ class Statistics extends Wxapp{ } $stat_data = [ 'tooltip' => ['trigger' => 'axis'], - 'legend' => ['top'=>'bottom','data'=>$bizs], + 'legend' => ['top' => 'bottom', 'data' => $bizs], 'grid' => [ 'top' => '10%', 'left' => '2%', @@ -170,9 +175,9 @@ class Statistics extends Wxapp{ 'xAxis' => [ 'type' => 'category', 'boundaryGap' => false, - 'data' => array_column($months_arr,'cn') + 'data' => array_column($months_arr, 'cn') ], - 'yAxis' => ['type'=>'value'], + 'yAxis' => ['type' => 'value'], 'series' => $series, ]; $data = [ @@ -182,47 +187,49 @@ class Statistics extends Wxapp{ ]; return $data; } - //数据分析页面客户数据 - protected function get_scust(){ - $day = $this->input_param('day'); + + //数据分析页面客户数据 + protected function get_scust() + { + $day = $this->input_param('day'); $month = $this->input_param('month'); $biz_id = $this->input_param('biz_id'); $admin_id = $this->input_param('admin_id'); - if(!$biz_id){ + if (!$biz_id) { throw new Exception('参数错误', ERR_PARAMS_ERROR); } - if(!$day && $month){ + if (!$day && $month) { $day = date("Y-{$month}-01"); } !$day && $day = date('Y-m-d');//获取当天 $status_list = [ - [ - 'title' => '订单客户', - 'icon' => 'icon-statistics-custom-1', - 'status' => 2 - ], - [ - 'title' => '到店客户', - 'icon' => 'icon-statistics-custom-2', + [ + 'title' => '订单客户', + 'icon' => 'icon-statistics-custom-1', + 'status' => 2 + ], + [ + 'title' => '到店客户', + 'icon' => 'icon-statistics-custom-2', 'status' => 1 - ], - [ - 'title' => '未见客户', - 'icon' => 'icon-statistics-custom-3', + ], + [ + 'title' => '未见客户', + 'icon' => 'icon-statistics-custom-3', 'status' => 0 - ], - [ - 'title' => '未联潜客', - 'icon' => 'icon-statistics-custom-4', + ], + [ + 'title' => '未联潜客', + 'icon' => 'icon-statistics-custom-4', 'status' => '' - ], - [ - 'title' =>'战败客户', - 'icon' => 'icon-statistics-custom-5', + ], + [ + 'title' => '战败客户', + 'icon' => 'icon-statistics-custom-5', 'status' => 3 - ], + ], ]; - foreach($status_list as $key => $val){ + foreach ($status_list as $key => $val) { $setValue = [ 'title' => $val['title'], 'icon' => $val['icon'], @@ -232,141 +239,143 @@ class Statistics extends Wxapp{ 'brand_id!=' => 3 ]; $admin_id && $where['admin_id'] = $admin_id; - if($day){ - $s_time = date('Y-m-01 00:00:00',strtotime($day)); - $e_time = date('Y-m-t 23:59:59',strtotime($day)); + if ($day) { + $s_time = date('Y-m-01 00:00:00', strtotime($day)); + $e_time = date('Y-m-t 23:59:59', strtotime($day)); $where['c_time>='] = strtotime($s_time); $where['c_time<='] = strtotime($e_time); } - if(strlen($val['status'])){ + if (strlen($val['status'])) { $where['status'] = $val['status']; $setValue['value'] = $this->customers_model->count($where); - }else{ + } else { $where["cont_time = '0000-00-00 00:00:00'"] = null; $setValue['value'] = $this->customers_model->count($where); } $custom[] = $setValue; } $months_arr = []; - for($i=2;$i>=0;$i--){ - $_time = date("Y-m-01",mktime(0, 0 , 0,date("m",strtotime($day))-$i,1,date("Y",strtotime($day)))); + for ($i = 2; $i >= 0; $i--) { + $_time = date("Y-m-01", mktime(0, 0, 0, date("m", strtotime($day)) - $i, 1, date("Y", strtotime($day)))); $months_arr [] = [ - 'cn' => date('n月',strtotime($_time)), - 's_time' => date('Y-m-01 00:00:00',strtotime($_time)), - 'e_time' => date('Y-m-t 23:59:59',strtotime($_time)) + 'cn' => date('n月', strtotime($_time)), + 's_time' => date('Y-m-01 00:00:00', strtotime($_time)), + 'e_time' => date('Y-m-t 23:59:59', strtotime($_time)) ]; } - foreach($months_arr as $val){ + foreach ($months_arr as $val) { $where = [ 'biz_id' => $biz_id, - 'status>=' => 0, + 'status>=' => 0, 'c_time>=' => strtotime($val['s_time']), 'c_time<=' => strtotime($val['e_time']), 'brand_id!=' => 3, ]; $count_data[] = $this->customers_model->count($where); } - + //图标数据 - $stat_data = [ - 'tooltip' => [ - 'trigger' => 'axis', - 'axisPointer' => [ - 'type' => 'shadow' - ] - ], - 'grid' => [ - 'top' => '10%', - 'left' => '2%', - 'right' => '5%', - 'bottom' => '5%', - 'containLabel' => true - ], - 'xAxis' => [ - 'type' => 'value', - 'boundaryGap' => [0, 0.01] - ], - 'yAxis' => [ - 'type' => 'category', - 'data' => array_column($months_arr,'cn'), - ], - 'series' => [ - [ - 'type' => 'bar', - 'itemStyle' => [ - 'color' => '#2e3246', - 'borderRadius' => [0, 20, 20, 0], - ], - 'barWidth' => '15', - 'data' => $count_data, - 'label' => [ - 'show' => true, - 'position' => 'right', - 'formatter' => '{@[n]}', - 'valueAnimation' => true - ] + $stat_data = [ + 'tooltip' => [ + 'trigger' => 'axis', + 'axisPointer' => [ + 'type' => 'shadow' ] - ] - ]; + ], + 'grid' => [ + 'top' => '10%', + 'left' => '2%', + 'right' => '5%', + 'bottom' => '5%', + 'containLabel' => true + ], + 'xAxis' => [ + 'type' => 'value', + 'boundaryGap' => [0, 0.01] + ], + 'yAxis' => [ + 'type' => 'category', + 'data' => array_column($months_arr, 'cn'), + ], + 'series' => [ + [ + 'type' => 'bar', + 'itemStyle' => [ + 'color' => '#2e3246', + 'borderRadius' => [0, 20, 20, 0], + ], + 'barWidth' => '15', + 'data' => $count_data, + 'label' => [ + 'show' => true, + 'position' => 'right', + 'formatter' => '{@[n]}', + 'valueAnimation' => true + ] + ] + ] + ]; $data = [ 'custom' => $custom, - 'stat_data' => $stat_data, + 'stat_data' => $stat_data, ]; return $data; } - //数据分析页面订单数据 - protected function get_ocust(){ - $day = $this->input_param('day'); + + //数据分析页面订单数据 + protected function get_ocust() + { + $day = $this->input_param('day'); $biz_id = $this->input_param('biz_id'); $month = $this->input_param('month'); $admin_id = $this->input_param('admin_id'); - if(!$biz_id){ + if (!$biz_id) { throw new Exception('参数错误', ERR_PARAMS_ERROR); } - if(!$day && $month){ + if (!$day && $month) { $day = date("Y-{$month}-01"); } !$day && $day = date('Y-m-d');//获取当天 - + $status_list = [ - [ - 'title' => '合同签订', - 'icon' => 'icon-statistics-order-1', - 'status' => 0 - ], - [ - 'title' => '分期办理', - 'icon' => 'icon-statistics-order-2', + [ + 'title' => '合同签订', + 'icon' => 'icon-statistics-order-1', + 'status' => 0 + ], + [ + 'title' => '分期办理', + 'icon' => 'icon-statistics-order-2', 'status' => 1 - ], - [ - 'title' => '车辆确认', - 'icon' => 'icon-statistics-order-3', + ], + [ + 'title' => '车辆确认', + 'icon' => 'icon-statistics-order-3', 'status' => 2 - ], - [ - 'title' => '申请开票', - 'icon' => 'icon-statistics-order-4', + ], + [ + 'title' => '申请开票', + 'icon' => 'icon-statistics-order-4', 'status' => 3 - ], - [ - 'title' =>'代办服务', - 'icon' => 'icon-statistics-order-5', + ], + [ + 'title' => '代办服务', + 'icon' => 'icon-statistics-order-5', 'status' => 4 - ], - [ - 'title' =>'交付确认', - 'icon' => 'icon-statistics-order-6', + ], + [ + 'title' => '交付确认', + 'icon' => 'icon-statistics-order-6', 'status' => 5 - ], - [ - 'title' =>'完成交付', - 'icon' => 'icon-statistics-order-7', + ], + [ + 'title' => '完成交付', + 'icon' => 'icon-statistics-order-7', 'status' => 6 - ], + ], ]; - foreach($status_list as $key => $val){ + foreach ($status_list as $key => $val) { $setValue = [ 'title' => $val['title'], 'icon' => $val['icon'], @@ -376,9 +385,9 @@ class Statistics extends Wxapp{ 'biz_id' => $biz_id, 'brand_id!=' => 3, ]; - if($day){ - $s_time = date('Y-m-01 00:00:00',strtotime($day)); - $e_time = date('Y-m-t 23:59:59',strtotime($day)); + if ($day) { + $s_time = date('Y-m-01 00:00:00', strtotime($day)); + $e_time = date('Y-m-t 23:59:59', strtotime($day)); $where['c_time>='] = strtotime($s_time); $where['c_time<='] = strtotime($e_time); } @@ -388,18 +397,18 @@ class Statistics extends Wxapp{ } $months_arr = []; - for($i=2;$i>=0;$i--){ - $_time = date("Y-m-01",mktime(0, 0 , 0,date("m",strtotime($day))-$i,1,date("Y",strtotime($day)))); + for ($i = 2; $i >= 0; $i--) { + $_time = date("Y-m-01", mktime(0, 0, 0, date("m", strtotime($day)) - $i, 1, date("Y", strtotime($day)))); $months_arr [] = [ - 'cn' => date('n月',strtotime($_time)), - 's_time' => date('Y-m-01 00:00:00',strtotime($_time)), - 'e_time' => date('Y-m-t 23:59:59',strtotime($_time)) + 'cn' => date('n月', strtotime($_time)), + 's_time' => date('Y-m-01 00:00:00', strtotime($_time)), + 'e_time' => date('Y-m-t 23:59:59', strtotime($_time)) ]; } - foreach($months_arr as $val){ + foreach ($months_arr as $val) { $where = [ 'biz_id' => $biz_id, - 'status>=' => 0, + 'status>=' => 0, 'c_time>=' => strtotime($val['s_time']), 'c_time<=' => strtotime($val['e_time']), 'brand_id!=' => 3, @@ -408,47 +417,49 @@ class Statistics extends Wxapp{ } $stat_data = [ - 'grid' => [ - 'top' => '15%', - 'left' => '2%', - 'right' => '5%', - 'bottom' => '5%', - 'containLabel' => true - ], - 'xAxis' =>[ - 'type' => 'category', - 'data' => array_column($months_arr,'cn'), - ], - 'yAxis' => [ - 'type' => 'value' - ], - 'series' => [ + 'grid' => [ + 'top' => '15%', + 'left' => '2%', + 'right' => '5%', + 'bottom' => '5%', + 'containLabel' => true + ], + 'xAxis' => [ + 'type' => 'category', + 'data' => array_column($months_arr, 'cn'), + ], + 'yAxis' => [ + 'type' => 'value' + ], + 'series' => [ [ - 'data' => $count_data, - 'type' => 'line', - 'smooth' => true + 'data' => $count_data, + 'type' => 'line', + 'smooth' => true ] - ] + ] ]; $data = [ 'custom' => $custom, - 'stat_data' => $stat_data, + 'stat_data' => $stat_data, ]; return $data; } + //首页饼状图客户统计 - protected function get_hcust(){ + protected function get_hcust() + { $biz_id = $this->input_param('biz_id'); $group_id = $this->session['group_id']; $uid = $this->session['uid']; !$biz_id && $biz_id = intval($this->session['biz_id']); - if(!$biz_id){ + if (!$biz_id) { throw new Exception('参数错误', ERR_PARAMS_ERROR); } $status_list = $this->customers_model->get_status(); - unset($status_list[-1]); + unset($status_list[-1]); $count_data = []; - foreach($status_list as $key => $val){ + foreach ($status_list as $key => $val) { $where = [ 'biz_id' => $biz_id, 'status' => $key @@ -463,91 +474,93 @@ class Statistics extends Wxapp{ } //所有客户数据 $where = [ - 'status>='=>0, - 'biz_id'=>$biz_id + 'status>=' => 0, + 'biz_id' => $biz_id ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //客户成功经理过滤 $count = $this->customers_model->count($where); $where = [ - 'status>='=>0, - 'biz_id'=>$biz_id, - 'is_top'=>1 + 'status>=' => 0, + 'biz_id' => $biz_id, + 'is_top' => 1 ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //客户成功经理过滤 $top_count = $this->customers_model->count($where); //关注 $where = [ - 'status>='=>0, - 'biz_id'=>$biz_id, - "cont_time = '0000-00-00 00:00:00'"=>null + 'status>=' => 0, + 'biz_id' => $biz_id, + "cont_time = '0000-00-00 00:00:00'" => null ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //客户成功经理过滤 $un_count = $this->customers_model->count($where);//未联系 $stat_data = [ - 'tooltip' =>[ - 'trigger' => 'axis', - ], - 'legend' => [ - 'top' => 'bottom', - 'orient' => 'horizontal', - 'textStyle' =>[ - 'fontSize' => 9, - ] - ], - 'series' => [ - 'type' => 'pie', - 'top' => '0', - 'radius' => ['30%', '48%'], - 'data' => $count_data, - 'label' =>[ - 'formatter' => '\n{b|{b}}\n{c|{c}}\n{per|{d}%} ', - 'rich' => [ - 'b' =>[ - 'color' => '#4C5058', - 'fontSize' => 10, - 'lineHeight' => 15, - 'align' => 'left', - ], - 'b' =>[ - 'color' => '#4C5058', - 'fontSize' => 10, - 'lineHeight' => 15, - 'align' => 'left', - ], - 'per' => [ - 'color' => '#4C5058', - 'fontSize' => 10, - 'lineHeight' => 15, - 'align' => 'left', - ], - ] - ], - ] + 'tooltip' => [ + 'trigger' => 'axis', + ], + 'legend' => [ + 'top' => 'bottom', + 'orient' => 'horizontal', + 'textStyle' => [ + 'fontSize' => 9, + ] + ], + 'series' => [ + 'type' => 'pie', + 'top' => '0', + 'radius' => ['30%', '48%'], + 'data' => $count_data, + 'label' => [ + 'formatter' => '\n{b|{b}}\n{c|{c}}\n{per|{d}%} ', + 'rich' => [ + 'b' => [ + 'color' => '#4C5058', + 'fontSize' => 10, + 'lineHeight' => 15, + 'align' => 'left', + ], + 'b' => [ + 'color' => '#4C5058', + 'fontSize' => 10, + 'lineHeight' => 15, + 'align' => 'left', + ], + 'per' => [ + 'color' => '#4C5058', + 'fontSize' => 10, + 'lineHeight' => 15, + 'align' => 'left', + ], + ] + ], + ] ]; $data = [ - 'stat_data' => $stat_data, + 'stat_data' => $stat_data, 'total' => $count, 'cont_total' => $un_count, 'top_total' => $top_count ]; return $data; - } + } + //首页柱状图订单统计 - protected function get_horder(){ + protected function get_horder() + { $biz_id = $this->input_param('biz_id'); $group_id = $this->session['group_id']; $uid = $this->session['uid']; !$biz_id && $biz_id = intval($this->session['biz_id']); - if(!$biz_id){ + if (!$biz_id) { throw new Exception('参数错误', ERR_PARAMS_ERROR); } $status_list = $this->orders_model->get_status(); unset($status_list[7]); $count_data = []; $total = 0; - foreach($status_list as $key => $val){ + foreach ($status_list as $key => $val) { $where = [ 'biz_id' => $biz_id, 'status' => $key @@ -562,66 +575,70 @@ class Statistics extends Wxapp{ ]; } $stat_data = [ - 'tooltip' =>[ - 'trigger' => 'axis', - 'axisPointer' => [ - 'type' => 'shadow' - ] - ], - 'grid' =>[ - 'top' => '8%', - 'left' => '2%', - 'right' => '5%', - 'bottom' => '2%', - 'containLabel' => true - ], - 'xAxis' =>[ - 'type' => 'value', - 'boundaryGap' => [0, 0.01] - ], - 'yAxis' =>[ - 'type' => 'category', - 'data' => array_column($count_data,'name'), - ], - 'series' =>[ - 'type' => 'bar', - 'itemStyle' =>[ - 'color' => '#2e3246', - 'borderRadius' => [0, 20, 20, 0], - ], - 'barWidth' => '15', - 'data' => array_column($count_data,'value'), - 'label'=>[ - 'show' => true, - 'position' => 'right', - 'formatter' => '{@[n]}', - 'valueAnimation' => true - ] - ] + 'tooltip' => [ + 'trigger' => 'axis', + 'axisPointer' => [ + 'type' => 'shadow' + ] + ], + 'grid' => [ + 'top' => '8%', + 'left' => '2%', + 'right' => '5%', + 'bottom' => '2%', + 'containLabel' => true + ], + 'xAxis' => [ + 'type' => 'value', + 'boundaryGap' => [0, 0.01] + ], + 'yAxis' => [ + 'type' => 'category', + 'data' => array_column($count_data, 'name'), + ], + 'series' => [ + 'type' => 'bar', + 'itemStyle' => [ + 'color' => '#2e3246', + 'borderRadius' => [0, 20, 20, 0], + ], + 'barWidth' => '15', + 'data' => array_column($count_data, 'value'), + 'label' => [ + 'show' => true, + 'position' => 'right', + 'formatter' => '{@[n]}', + 'valueAnimation' => true + ] + ] ]; $data = [ - 'stat_data' => $stat_data, + 'stat_data' => $stat_data, 'total' => $total ]; return $data; } + /** * 获取月份 */ - private function months(){ - $months = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']; + private function months() + { + $months = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']; return $months; } + /** * 获取季度 * @param int $season 当前季度 */ - private function season_data($season){ - $chiNum = ['一','二','三','四']; - if($season>4){ + private function season_data($season) + { + $chiNum = ['一', '二', '三', '四']; + if ($season > 4) { return []; } - for($i=0;$i<$season;$i++){ + for ($i = 0; $i < $season; $i++) { $season_data[] = "第{$chiNum[$i]}季度"; } return $season_data; @@ -638,17 +655,19 @@ class Statistics extends Wxapp{ $c_time = ['s_time' => strtotime($s_time), 'e_time' => strtotime(date('Y-m-d 23:59:59', strtotime($e_time)))]; $o_time = ['s_time' => $s_time . ' 00:00:00', 'e_time' => $e_time . ' 23:59:59']; - if($city_id){ - $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + if ($city_id) { +// $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $bizs = array_column($bizs, 'id'); $this->session['biz_id'] && $bizs = array_intersect($bizs, explode(',', $this->session['biz_id'])); $biz_id_arr = implode(',', array_unique($bizs)); - }else{ - if($this->session['biz_id']){ + } else { + if ($this->session['biz_id']) { $biz_id_arr = $this->session['biz_id']; - }else{ - $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + } else { +// $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $biz_id_arr = implode(',', array_unique(array_column($bizs, 'id'))); } @@ -745,17 +764,19 @@ class Statistics extends Wxapp{ 'c_time<=' => $c_time['e_time'], ]; - if($city_id){ - $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + if ($city_id) { +// $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $bizs = array_column($bizs, 'id'); $this->session['biz_id'] && $bizs = array_intersect($bizs, explode(',', $this->session['biz_id'])); $biz_id_arr = implode(',', array_unique($bizs)); - }else{ - if($this->session['biz_id']){ + } else { + if ($this->session['biz_id']) { $biz_id_arr = $this->session['biz_id']; - }else{ - $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + } else { +// $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $biz_id_arr = implode(',', array_unique(array_column($bizs, 'id'))); } @@ -803,29 +824,32 @@ class Statistics extends Wxapp{ $pie1_level = $pie1_offline = $biz_customer = []; $bottom2 = $bottom1 = ''; - if($city_id){ - $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + if ($city_id) { +// $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $bizs = array_column($bizs, 'id'); $this->session['biz_id'] && $bizs = array_intersect($bizs, explode(',', $this->session['biz_id'])); $biz_id_arr = implode(',', array_unique($bizs)); - }else{ - if($this->session['biz_id']){ + } else { + if ($this->session['biz_id']) { $biz_id_arr = $this->session['biz_id']; - }else{ - $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + } else { +// $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $biz_id_arr = implode(',', array_unique(array_column($bizs, 'id'))); } } - if($biz_id_arr){ - $biz_where = array('status' => 1, 'type' => 0, "id in ({$biz_id_arr})" => null); + if ($biz_id_arr) { +// $biz_where = array('status' => 1, 'type' => 0, "id in ({$biz_id_arr})" => null); + $biz_where = array('status' => 1, "id in ({$biz_id_arr})" => null); $bizs = $this->biz_model->select($biz_where); $sdata_level = $this->customers_model->get_sdata('level'); foreach ($sdata_level as $v) { - if($type == 1){ + if ($type == 1) { $title = '到店客户'; // $where = [ // "a.c_time>=" => $c_time['s_time'], @@ -846,7 +870,7 @@ class Statistics extends Wxapp{ "biz_id in ({$biz_id_arr})" => null ]; $value = $this->customers_model->count($where); - }elseif($type == 2){ + } elseif ($type == 2) { $title = '添加微信'; $c_where = [ 'status>=' => 0, @@ -857,7 +881,7 @@ class Statistics extends Wxapp{ "biz_id in ({$biz_id_arr})" => null ]; $value = $this->customers_model->count($c_where); - }elseif($type == 3){ + } elseif ($type == 3) { $title = '所有订单'; $where = [ 'a.order_time>=' => $o_time['s_time'], @@ -871,7 +895,7 @@ class Statistics extends Wxapp{ ->join('lc_receiver_customers as b', "a.customer_id=b.id", 'left') ->where($where) ->count_all_results(); - }else{ + } else { $title = '所有客户'; $c_where = [ 'status>=' => 0, @@ -882,7 +906,7 @@ class Statistics extends Wxapp{ ]; $value = $this->customers_model->count($c_where); } - if($value){ + if ($value) { $pie1_level[] = ['name' => $v, 'value' => $value]; $bottom1 += $value; } @@ -892,7 +916,7 @@ class Statistics extends Wxapp{ foreach ($offlineSources as $k => $v) { $id = count($v["list"]) > 0 ? $k : 0; - if($type == 1){ + if ($type == 1) { //到店 // $where = [ // "a.c_time>=" => $c_time['s_time'], @@ -914,7 +938,7 @@ class Statistics extends Wxapp{ "biz_id in ({$biz_id_arr})" => null ]; $value = $this->customers_model->count($where); - }elseif($type == 2){ + } elseif ($type == 2) { //个微 $c_where = [ 'status>=' => 0, @@ -925,7 +949,7 @@ class Statistics extends Wxapp{ "biz_id in ({$biz_id_arr})" => null ]; $value = $this->customers_model->count($c_where); - }elseif($type == 3){ + } elseif ($type == 3) { //订单 $where = [ 'a.order_time>=' => $o_time['s_time'], @@ -939,7 +963,7 @@ class Statistics extends Wxapp{ ->join('lc_receiver_customers as b', "a.customer_id=b.id", 'left') ->where($where) ->count_all_results(); - }else{ + } else { //所有 $c_where = [ 'status>=' => 0, @@ -951,13 +975,13 @@ class Statistics extends Wxapp{ $value = $this->customers_model->count($c_where); } - $value && $pie1_offline[] = ['id' => $id,'name' => $v['name'], 'value' => $value]; + $value && $pie1_offline[] = ['id' => $id, 'name' => $v['name'], 'value' => $value]; } //门店归属 foreach ($bizs as $k => $v) { $biz_arr[] = str_replace('车卖场', '', $v['biz_name']); - if($type == 1){ + if ($type == 1) { //进店 // $s_where = [ // "c_time>=" => $c_time['s_time'], @@ -973,7 +997,7 @@ class Statistics extends Wxapp{ 'dt_time<=' => $o_time['e_time'], ]; $value = $this->customers_model->count($where); - }elseif($type == 2){ + } elseif ($type == 2) { $where = [ 'status>=' => 0, 'biz_id' => $v['id'], @@ -982,7 +1006,7 @@ class Statistics extends Wxapp{ 'p_time<=' => $o_time['e_time'], ]; $value = $this->customers_model->count($where); - }elseif($type == 3){ + } elseif ($type == 3) { $where = [ 'status>=' => 0, 'biz_id' => $v['id'], @@ -990,7 +1014,7 @@ class Statistics extends Wxapp{ 'order_time<=' => $o_time['e_time'], ]; $value = $this->orders_model->count($where); - }else{ + } else { $where = [ 'status>=' => 0, 'biz_id' => $v['id'], @@ -1004,8 +1028,8 @@ class Statistics extends Wxapp{ } } - $data['pie1'] = ['title' => '客户来源', 'series_data_1' => $pie1_level, 'series_data_2' => $pie1_offline,'bottom' => "合计: {$bottom1}"]; - $data['bar'] = ['title' => '归属门店', 'xAxis_data' => $biz_arr, 'series_data' => $biz_customer,'bottom' => "合计: {$bottom2}"]; + $data['pie1'] = ['title' => '客户来源', 'series_data_1' => $pie1_level, 'series_data_2' => $pie1_offline, 'bottom' => "合计: {$bottom1}"]; + $data['bar'] = ['title' => '归属门店', 'xAxis_data' => $biz_arr, 'series_data' => $biz_customer, 'bottom' => "合计: {$bottom2}"]; $data['title'] = $title; return $data; @@ -1026,33 +1050,35 @@ class Statistics extends Wxapp{ $pie_offline = []; $o_time = ['s_time' => $s_time . ' 00:00:00', 'e_time' => $e_time . ' 23:59:59']; - if($city_id){ - $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + if ($city_id) { +// $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'city_id' => $city_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $bizs = array_column($bizs, 'id'); $this->session['biz_id'] && $bizs = array_intersect($bizs, explode(',', $this->session['biz_id'])); $biz_id_arr = implode(',', array_unique($bizs)); - }else{ - if($this->session['biz_id']){ + } else { + if ($this->session['biz_id']) { $biz_id_arr = $this->session['biz_id']; - }else{ - $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + } else { +// $biz_where = array('province_id' => $province_id, 'status' => 1, 'type' => 0); + $biz_where = array('province_id' => $province_id, 'status' => 1); $bizs = $this->biz_model->select($biz_where); $biz_id_arr = implode(',', array_unique(array_column($bizs, 'id'))); } } - if($biz_id_arr){ + if ($biz_id_arr) { $offlineSources = $this->customers_model->offlineSources($id, 0); foreach ($offlineSources["list"] as $k => $v) { $title = $offlineSources['name']; - if($type==1){ + if ($type == 1) { $where = [ "a.c_time>=" => $c_time['s_time'], "a.c_time<=" => $c_time['e_time'], "a.status" => 1, - 'b.of_id'=> $id, + 'b.of_id' => $id, 'b.of2_id' => $k, "b.biz_id in ({$biz_id_arr})" => null, ]; @@ -1061,8 +1087,8 @@ class Statistics extends Wxapp{ ->join('lc_receiver_customers as b', "a.customer_id=b.id", 'left') ->where($where) ->count_all_results(); - $value_1 && $pie_offline[] = ['id' => $id,'name' => $v, 'value' => $value_1]; - }else if($type==2){ + $value_1 && $pie_offline[] = ['id' => $id, 'name' => $v, 'value' => $value_1]; + } else if ($type == 2) { $where = [ 'status>=' => 0, "biz_id in ({$biz_id_arr})" => null, @@ -1074,7 +1100,7 @@ class Statistics extends Wxapp{ ]; $value_1 = $this->customers_model->count($where); $value_1 && $pie_offline[] = ['name' => $v, 'value' => $value_1]; - }else if($type==3){ + } else if ($type == 3) { $where = [ 'a.order_time>=' => $o_time['s_time'], 'a.order_time<=' => $o_time['e_time'], @@ -1090,14 +1116,14 @@ class Statistics extends Wxapp{ ->count_all_results(); $value_1 && $pie_offline[] = ['name' => $v, 'value' => $value_1]; - }else{ + } else { $where = [ 'status>=' => 0, 'p_time>=' => $o_time['s_time'], 'p_time<=' => $o_time['e_time'], "biz_id in ({$biz_id_arr})" => null, ]; - $value_1 = $this->customers_model->count(array_merge($where, ['of_id'=>$id,'of2_id' => $k])); + $value_1 = $this->customers_model->count(array_merge($where, ['of_id' => $id, 'of2_id' => $k])); $value_1 && $pie_offline[] = ['name' => $v, 'value' => $value_1]; }