From 636e2d8ff8ab9173d38611c06e3231930378b04c Mon Sep 17 00:00:00 2001 From: dengbw Date: Mon, 22 Aug 2022 11:17:25 +0800 Subject: [PATCH] order_822 --- admin/controllers/stats/Order.php | 302 ++++++++++-------- .../stats/order/{hozonauto.php => common.php} | 4 +- 2 files changed, 169 insertions(+), 137 deletions(-) rename admin/views/stats/order/{hozonauto.php => common.php} (98%) diff --git a/admin/controllers/stats/Order.php b/admin/controllers/stats/Order.php index 9e542303..41d6dee7 100644 --- a/admin/controllers/stats/Order.php +++ b/admin/controllers/stats/Order.php @@ -20,6 +20,27 @@ class order extends HD_Controller return $this->get_dfmc(); } + /** + * Notes:零跑 + * Created on: 2022/8/22 14:19 + * Created by: dengbw + */ + public function get_leapmotor() + { + $params = $this->input->get(); + $config['brand_id'] = 5; + $config['bizs'] = [ + 1 => ['biz_name' => '泉州零跑品牌店', 'ids' => '63', 'rowspan' => 1], + 2 => ['biz_name' => '泉州渠道', 'not_ids' => '63', 'city_id' => '350500'], + 3 => ['biz_name' => '厦门渠道', 'city_id' => '350200']]; + $res = $this->commonSelect($params, $config); + $this->data['info'] = $res['info']; + $this->data['params'] = $res['params']; + $this->data['url'] = '/stats/order/get_leapmotor'; + $this->data['_title'] = '零跑'; + return $this->show_view('stats/order/common', true); + } + /** * Notes:哪吒 * Created on: 2022/8/17 14:19 @@ -27,144 +48,22 @@ class order extends HD_Controller */ public function get_hozonauto() { - $brand_id = 4;//品牌id $params = $this->input->get(); - !$params['type'] && $params['type'] = 1; - $start_date = date('Y-m', strtotime("-2 month"));//取最近3个月 - $end_date = date('Y-m'); - if ($params['time']) { - $time = explode(' ~ ', $params['time']); - $time[0] && $start_date = $time[0]; - $time[1] && $end_date = $time[1]; - } else { - $params['time'] = $start_date . ' ~ ' . $end_date; - } - $date_months = $this->dateMonths($start_date, $end_date); - rsort($date_months); - $days = []; - foreach ($date_months as $k => $v) { - $month = date('n', strtotime($v . '-01')); - $days[$v] = ['month' => $month, 'num' => 0]; - } - $bizs = [1 => ['biz_name' => '宁德哪吒品牌店', 'ids' => '70', 'rowspan' => 1], 2 => ['biz_name' => '宁德哪吒代理店', 'type' => 3, 'city_id' => '350900'] - , 3 => ['biz_name' => '厦门哪吒订单中心', 'city_id' => '350200'], 4 => ['biz_name' => '泉州哪吒订单中心', 'city_id' => '350500'] - , 5 => ['biz_name' => '福州哪吒订单中心', 'city_id' => '350100']]; - foreach ($bizs as $k => $v) { - $str_ids = $v['ids'] ? $v['ids'] : ''; - if (!$str_ids) { - $where_b = ['status' => 1, 'city_id' => $v['city_id']]; - $v['type'] && $where_b['type'] = $v['type']; - $res = $this->mdBiz->select($where_b, 'id desc', 0, 0, 'id'); - if ($res) { - $str_ids = implode(',', array_unique(array_column($res, 'id'))); - $str_ids = $str_ids ? $str_ids : '-1'; - } - } - $list = []; - foreach ($days as $k2 => $v2) { - $order_time = $this->getTime($k2); - $c_time = $this->getTime($k2, 1); - if ($params['type'] == 2) { - $num = $this->mdOrders->count(["biz_id in({$str_ids})" => null, 'brand_id' => $brand_id, - 'status>=' => 0, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]); - } else { - $num = $this->mdOrders->db->select('a.id') - ->from('lc_receiver_orders_v2 as a') - ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') - ->where(["a.biz_id in({$str_ids})" => null, 'a.brand_id' => $brand_id, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'] - , 'a.order_time<=' => $order_time['e_time'], 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']]) - ->count_all_results(); - } - $list[$k2] = $num; - $days[$k2]['num'] = $v2['num'] + $num; - } - $v['list'] = $list; - $v['ids'] = $str_ids; - $bizs[$k] = $v; - } - $offlineSources = $this->mdCustomers->offlineSources(); - $offlineSources_count = count($offlineSources); - //过程数据 - $process_cus = $process_into = $process_ord = []; - foreach ($bizs as $k => $v) { - $list_cus = $cus_sum = $list_into = $ord_into = $into_sum = $list_ord = $ord_sum = []; - foreach ($offlineSources as $k2 => $v2) { - $stats_per_cus = $stats_cus = $stats_per_into = $stats_into = $stats_per_ord = $stats_ord = []; - foreach ($days as $k3 => $v3) { - $order_time = $this->getTime($k3); - $c_time = $this->getTime($k3, 1); - //线索数 - $num_cus = 0; - if ($k2 != 1) {//不包括自然到店 - $num_cus = $this->mdCustomers->count(["biz_id in({$v['ids']})" => null, 'of_id' => $k2, 'status>=' => 0, 'c_time>=' => $c_time['s_time'], 'c_time<=' => $c_time['e_time']]); - $cus_sum[$k3] += $num_cus; - $stats_cus[] = $num_cus; - $stats_per_cus[$k3] = $num_cus; - } - //进店数 - if ($params['type'] == 2) { - $num_into = $this->mdUsersLog->db->select('a.id') - ->from('lc_receiver_customer_oplogs as a') - ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') - ->where(['a.type' => 4, 'a.log' => '客户到店', 'a.c_time>=' => $c_time['s_time'], 'a.c_time<=' => $c_time['e_time'], - 'b.status>=' => 0, "b.biz_id in({$v['ids']})" => null, 'b.of_id' => $k2]) - ->count_all_results(); - } else { - $num_into = $this->mdUsersLog->db->select('a.id') - ->from('lc_receiver_customer_oplogs as a') - ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') - ->where(['a.type' => 4, 'a.log' => '客户到店', 'a.c_time>=' => $c_time['s_time'], 'a.c_time<=' => $c_time['e_time'], - 'b.status>=' => 0, "b.biz_id in({$v['ids']})" => null, 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']]) - ->count_all_results(); - } - $into_sum[$k3] += $num_into; - $stats_into[] = $num_into; - $num_into_per = ''; - if ($k2 != 1) {//转化率=进店数/客户数 - $num_into_per = $this->getPercentage(['num' => $num_into, 'sum' => $num_cus]); - } - $stats_per_into[$k3] = $num_into_per; - //成交数 - if ($params['type'] == 2) { - $num_ord = $this->mdOrders->db->select('a.id') - ->from('lc_receiver_orders_v2 as a') - ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') - ->where(["a.biz_id in({$v['ids']})" => null, 'a.brand_id' => $brand_id, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'] - , 'a.order_time<=' => $order_time['e_time'], 'b.of_id' => $k2]) - ->count_all_results(); - } else { - $num_ord = $this->mdOrders->db->select('a.id') - ->from('lc_receiver_orders_v2 as a') - ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') - ->where(["a.biz_id in({$v['ids']})" => null, 'a.brand_id' => $brand_id, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'], 'a.order_time<=' => $order_time['e_time'] - , 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']]) - ->count_all_results(); - } - $ord_sum[$k3] += $num_ord; - $stats_ord[] = $num_ord; - //转化率=订单数/进店数 - $stats_per_ord[$k3] = $this->getPercentage(['num' => $num_ord, 'sum' => $num_into]); - } - if ($k2 != 1) {//不包括自然到店 - $list_cus[] = ['name' => $v2['name'], 'stats_per' => $stats_per_cus, 'stats' => $stats_cus]; - } - $list_into[] = ['name' => $v2['name'], 'stats_per' => $stats_per_into, 'stats' => $stats_into]; - $list_ord[] = ['name' => $v2['name'], 'stats_per' => $stats_per_ord, 'stats' => $stats_ord]; - } - $process_cus[] = ['biz_name' => $v['biz_name'], 'num_sum' => $cus_sum, 'list' => $list_cus]; - $process_into[] = ['biz_name' => $v['biz_name'], 'num_sum' => $into_sum, 'list' => $list_into]; - $process_ord[] = ['biz_name' => $v['biz_name'], 'num_sum' => $ord_sum, 'list' => $list_ord]; - } - $process = ['customers' => $process_cus, 'into_shop' => $process_into, 'orders' => $process_ord]; - $this->data['info'] = ['days' => $days, 'bizs' => $bizs, 'bizs_count' => count($bizs), 'days_count' => count($days) - , 'brands_count' => 1, 'offlineSources_count' => $offlineSources_count, 'process' => $process, - 'type_ary' => [1 => '月销售模型(当月线索)', 2 => '月销售模型']]; - $this->data['params'] = $params; + $config['brand_id'] = 4; + $config['bizs'] = [ + 1 => ['biz_name' => '宁德哪吒品牌店', 'ids' => '70', 'rowspan' => 1], + 2 => ['biz_name' => '宁德哪吒代理店', 'type' => 3, 'city_id' => '350900'], + 3 => ['biz_name' => '厦门哪吒订单中心', 'city_id' => '350200'], + 4 => ['biz_name' => '泉州哪吒订单中心', 'city_id' => '350500'], + 5 => ['biz_name' => '福州哪吒订单中心', 'city_id' => '350100']]; + $res = $this->commonSelect($params, $config); + $this->data['info'] = $res['info']; + $this->data['params'] = $res['params']; + $this->data['url'] = '/stats/order/get_hozonauto'; $this->data['_title'] = '哪吒'; - return $this->show_view('stats/order/hozonauto', true); + return $this->show_view('stats/order/common', true); } - /** * Notes:东风品牌店群 * Created on: 2022/8/17 14:17 @@ -369,8 +268,141 @@ class order extends HD_Controller return $this->show_view('stats/order/dfmc', true); } - private function dataSelect($params) + private function commonSelect($params, $config) { + $brand_id = $config['brand_id'];//品牌id + !$params['type'] && $params['type'] = 1; + $start_date = date('Y-m', strtotime("-2 month"));//取最近3个月 + $end_date = date('Y-m'); + if ($params['time']) { + $time = explode(' ~ ', $params['time']); + $time[0] && $start_date = $time[0]; + $time[1] && $end_date = $time[1]; + } else { + $params['time'] = $start_date . ' ~ ' . $end_date; + } + $date_months = $this->dateMonths($start_date, $end_date); + rsort($date_months); + $days = []; + foreach ($date_months as $k => $v) { + $month = date('n', strtotime($v . '-01')); + $days[$v] = ['month' => $month, 'num' => 0]; + } + $bizs = $config['bizs']; + foreach ($bizs as $k => $v) { + $str_ids = $v['ids'] ? $v['ids'] : ''; + if (!$str_ids) { + $where_b = ['status' => 1, 'city_id' => $v['city_id']]; + $v['type'] && $where_b['type'] = $v['type']; + $v['not_ids'] && $where_b["id not in({$v['not_ids']})"] = null; + $res = $this->mdBiz->select($where_b, 'id desc', 0, 0, 'id'); + if ($res) { + $str_ids = implode(',', array_unique(array_column($res, 'id'))); + $str_ids = $str_ids ? $str_ids : '-2'; + } + } + $list = []; + foreach ($days as $k2 => $v2) { + $order_time = $this->getTime($k2); + $c_time = $this->getTime($k2, 1); + if ($params['type'] == 2) { + $num = $this->mdOrders->count(["biz_id in({$str_ids})" => null, 'brand_id' => $brand_id, + 'status>=' => 0, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]); + } else { + $num = $this->mdOrders->db->select('a.id') + ->from('lc_receiver_orders_v2 as a') + ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') + ->where(["a.biz_id in({$str_ids})" => null, 'a.brand_id' => $brand_id, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'] + , 'a.order_time<=' => $order_time['e_time'], 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']]) + ->count_all_results(); + } + $list[$k2] = $num; + $days[$k2]['num'] = $v2['num'] + $num; + } + $v['list'] = $list; + $v['ids'] = $str_ids; + $bizs[$k] = $v; + } + //echo json_encode($bizs,JSON_UNESCAPED_UNICODE); + $offlineSources = $this->mdCustomers->offlineSources(); + $offlineSources_count = count($offlineSources); + //过程数据 + $process_cus = $process_into = $process_ord = []; + foreach ($bizs as $k => $v) { + $list_cus = $cus_sum = $list_into = $ord_into = $into_sum = $list_ord = $ord_sum = []; + foreach ($offlineSources as $k2 => $v2) { + $stats_per_cus = $stats_cus = $stats_per_into = $stats_into = $stats_per_ord = $stats_ord = []; + foreach ($days as $k3 => $v3) { + $order_time = $this->getTime($k3); + $c_time = $this->getTime($k3, 1); + //线索数 + $num_cus = 0; + if ($k2 != 1) {//不包括自然到店 + $num_cus = $this->mdCustomers->count(["biz_id in({$v['ids']})" => null, 'of_id' => $k2, 'status>=' => 0, 'c_time>=' => $c_time['s_time'], 'c_time<=' => $c_time['e_time']]); + $cus_sum[$k3] += $num_cus; + $stats_cus[] = $num_cus; + $stats_per_cus[$k3] = $num_cus; + } + //进店数 + if ($params['type'] == 2) { + $num_into = $this->mdUsersLog->db->select('a.id') + ->from('lc_receiver_customer_oplogs as a') + ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') + ->where(['a.type' => 4, 'a.log' => '客户到店', 'a.c_time>=' => $c_time['s_time'], 'a.c_time<=' => $c_time['e_time'], + 'b.status>=' => 0, "b.biz_id in({$v['ids']})" => null, 'b.of_id' => $k2]) + ->count_all_results(); + } else { + $num_into = $this->mdUsersLog->db->select('a.id') + ->from('lc_receiver_customer_oplogs as a') + ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') + ->where(['a.type' => 4, 'a.log' => '客户到店', 'a.c_time>=' => $c_time['s_time'], 'a.c_time<=' => $c_time['e_time'], + 'b.status>=' => 0, "b.biz_id in({$v['ids']})" => null, 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']]) + ->count_all_results(); + } + $into_sum[$k3] += $num_into; + $stats_into[] = $num_into; + $num_into_per = ''; + if ($k2 != 1) {//转化率=进店数/客户数 + $num_into_per = $this->getPercentage(['num' => $num_into, 'sum' => $num_cus]); + } + $stats_per_into[$k3] = $num_into_per; + //成交数 + if ($params['type'] == 2) { + $num_ord = $this->mdOrders->db->select('a.id') + ->from('lc_receiver_orders_v2 as a') + ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') + ->where(["a.biz_id in({$v['ids']})" => null, 'a.brand_id' => $brand_id, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'] + , 'a.order_time<=' => $order_time['e_time'], 'b.of_id' => $k2]) + ->count_all_results(); + } else { + $num_ord = $this->mdOrders->db->select('a.id') + ->from('lc_receiver_orders_v2 as a') + ->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left') + ->where(["a.biz_id in({$v['ids']})" => null, 'a.brand_id' => $brand_id, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'], 'a.order_time<=' => $order_time['e_time'] + , 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']]) + ->count_all_results(); + } + $ord_sum[$k3] += $num_ord; + $stats_ord[] = $num_ord; + //转化率=订单数/进店数 + $stats_per_ord[$k3] = $this->getPercentage(['num' => $num_ord, 'sum' => $num_into]); + } + if ($k2 != 1) {//不包括自然到店 + $list_cus[] = ['name' => $v2['name'], 'stats_per' => $stats_per_cus, 'stats' => $stats_cus]; + } + $list_into[] = ['name' => $v2['name'], 'stats_per' => $stats_per_into, 'stats' => $stats_into]; + $list_ord[] = ['name' => $v2['name'], 'stats_per' => $stats_per_ord, 'stats' => $stats_ord]; + } + $process_cus[] = ['biz_name' => $v['biz_name'], 'num_sum' => $cus_sum, 'list' => $list_cus]; + $process_into[] = ['biz_name' => $v['biz_name'], 'num_sum' => $into_sum, 'list' => $list_into]; + $process_ord[] = ['biz_name' => $v['biz_name'], 'num_sum' => $ord_sum, 'list' => $list_ord]; + } + $process = ['customers' => $process_cus, 'into_shop' => $process_into, 'orders' => $process_ord]; + $data['info'] = ['days' => $days, 'bizs' => $bizs, 'bizs_count' => count($bizs), 'days_count' => count($days) + , 'brands_count' => 1, 'offlineSources_count' => $offlineSources_count, 'process' => $process, + 'type_ary' => [1 => '月销售模型(当月线索)', 2 => '月销售模型']]; + $data['params'] = $params; + return $data; } /** diff --git a/admin/views/stats/order/hozonauto.php b/admin/views/stats/order/common.php similarity index 98% rename from admin/views/stats/order/hozonauto.php rename to admin/views/stats/order/common.php index a4d983cf..5d1d3bea 100644 --- a/admin/views/stats/order/hozonauto.php +++ b/admin/views/stats/order/common.php @@ -1,6 +1,6 @@