diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php index bbf85fbf..66036ee0 100644 --- a/api/controllers/wxapp/licheb/User.php +++ b/api/controllers/wxapp/licheb/User.php @@ -94,8 +94,11 @@ class User extends Wxapp } /** - * 用户信息 + * Notes:用户信息 + * Created on: 2022/10/12 14:09 + * Created by: dengbw * @return array + * @throws Exception */ protected function get() { @@ -226,7 +229,7 @@ class User extends Wxapp $this->load->model('receiver/order/receiver_orders_v2_model'); $this->load->model('receiver/order/receiver_order_signs_model', 'order_signs_model'); $this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData'); - $where = ['status>' => -1, 'is_top' => 1, 'biz_id' => $biz_id, 'cs_biz_id<>' => -1,'status!='=>2]; + $where = ['status>' => -1, 'is_top' => 1, 'biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'status!=' => 2]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $gz_count = $this->customers_model->count($where); @@ -238,7 +241,6 @@ class User extends Wxapp $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $loan_count = $this->orders_model->count($where); - //客户代办事项 if ($group_id == 1) { $customer_op_list = []; @@ -256,20 +258,20 @@ class User extends Wxapp ]; } $where = ['status>=' => 0, 'payway' => 0, 'id>=' => Orders_v2_entity::V2_START_ID, - 'brand_id>' => 0, 'biz_id' => $biz_id,'status!='=>2, + 'brand_id>' => 0, 'biz_id' => $biz_id, 'status!=' => 2, 'id not in (select o_id from lc_receiver_order_status where pid_status=1 and status=2)' => null]; $group_id == 1 && $where['sale_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $fq_total = $this->receiver_orders_v2_model->count($where); $where = ['status>=' => 0, 'id>=' => Orders_v2_entity::V2_START_ID, - 'brand_id>' => 0, 'biz_id' => $biz_id,'status!='=>2, + 'brand_id>' => 0, 'biz_id' => $biz_id, 'status!=' => 2, 'id not in (select o_id from lc_receiver_order_status where pid_status=2 and status=1)' => null]; $group_id == 1 && $where['sale_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $pc_total = $this->receiver_orders_v2_model->count($where); $where = [ 'status>=' => 0, 'id>=' => Orders_v2_entity::V2_START_ID, - 'brand_id>' => 0, 'biz_id' => $biz_id,'status!='=>2, + 'brand_id>' => 0, 'biz_id' => $biz_id, 'status!=' => 2, 'id not in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)' => null, 'id in (select o_id from lc_receiver_order_status where pid_status=0 and status=2)' => null]; $group_id == 1 && $where['sale_id'] = $uid; @@ -277,7 +279,7 @@ class User extends Wxapp $kp_total = $this->receiver_orders_v2_model->count($where); $where = [ 'status>=' => 0, 'id>=' => Orders_v2_entity::V2_START_ID, - 'brand_id>' => 0, 'biz_id' => $biz_id,'status!='=>2, + 'brand_id>' => 0, 'biz_id' => $biz_id, 'status!=' => 2, 'id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)' => null, 'id not in (select o_id from lc_receiver_order_status where pid_status=4 and status=2)' => null ]; @@ -318,6 +320,84 @@ class User extends Wxapp , ['title' => '今日已跟进 >', 'num' => $b_num_2, 'url' => '/pages/customer/filterList/index?level=B&status=2&visit=1&title=B级今日已跟进']]], ]; $wl_num = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['b.status<>' => 2])); + //数据统计 + $this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOpLogs'); + $s_today = date('Y-m-d') . ' 00:00:00'; + $e_today = date('Y-m-d') . ' 23:59:59'; + $s_month = date('Y-m-01', strtotime(date("Y-m-d"))) . ' 00:00:00'; + $e_month = date('Y-m-d', strtotime("$s_month +1 month -1 day")) . ' 23:59:59'; + //线索 + $where_today_xs = ['cs_biz_id<>' => -1, 'status>=' => 0, 'c_time>=' => strtotime($s_today), 'c_time<=' => strtotime($e_today)]; + $where_month_xs = ['cs_biz_id<>' => -1, 'status>=' => 0, 'c_time>=' => strtotime($s_month), 'c_time<=' => strtotime($e_month)]; + //企微 + $where_today_qy = ['change_type' => 'add_external_contact', 'c_time>=' => strtotime($s_today), 'c_time<=' => strtotime($e_today)]; + $where_month_qy = ['change_type' => 'add_external_contact', 'c_time>=' => strtotime($s_today), 'c_time<=' => strtotime($e_today)]; + //到店 + $where_today_dd = ['type' => 4, 'c_time>=' => strtotime($s_today), 'c_time<=' => strtotime($e_today)]; + $where_month_dd = ['type' => 4, 'c_time>=' => strtotime($s_month), 'c_time<=' => strtotime($e_month)]; + //订单 + $where_today_order = ['biz_id' => $biz_id, 'status>=' => 0, 'order_time>=' => $s_today, 'order_time<=' => $e_today]; + $where_month_order = ['biz_id' => $biz_id, 'status>=' => 0, 'order_time>=' => $s_month, 'order_time<=' => $e_month]; + //战败 + $where_today_defeat = ['type' => 7, 'c_time>=' => strtotime($s_today), 'c_time<=' => strtotime($e_today)]; + $where_month_defeat = ['type' => 7, 'c_time>=' => strtotime($s_month), 'c_time<=' => strtotime($e_month)]; + $where_customer_id = "customer_id in(select id from lc_receiver_customers where biz_id={$biz_id} and cs_biz_id!=-1)"; + if ($group_id == 1) { + $where_today_xs['admin_id'] = $uid; + $where_month_xs['admin_id'] = $uid; + $where_today_dd['uid'] = $uid; + $where_month_dd['uid'] = $uid; + $where_today_order['sale_id'] = $uid; + $where_month_order['sale_id'] = $uid; + $where_today_defeat['uid'] = $uid; + $where_month_defeat['uid'] = $uid; + $where_customer_id = "customer_id in(select id from lc_receiver_customers where admin_id={$uid} and biz_id={$biz_id} and cs_biz_id!=-1)"; + if ($this->session['userid']) { + $where_today_qy['userid'] = $this->session['userid']; + $where_month_qy['userid'] = $this->session['userid']; + } else { + $where_today_qy = ''; + } + } else { + $res_user = $this->app_user_model->select(['biz_id' => $biz_id, 'group_id <' => 4, 'status' => 1, 'userid!=' => ''], 'id asc', 0, 0, 'userid'); + if ($res_user) { + $str_userids = implode("','", array_column($res_user, 'userid')); + $where_today_qy["userid in ('" . $str_userids . "')"] = null; + $where_month_qy["userid in ('" . $str_userids . "')"] = null; + } else { + $where_today_qy = ''; + } + } + $today_qy = $month_qy = 0; + if ($where_today_qy) { + $re_biz = $this->biz_model->get(['id' => $biz_id]); + if ($re_biz['type'] == 5) {//异业店 + $this->load->model('app/app_different_qy_log_model', 'mdDifferentQyLog'); + $today_qy = $this->mdDifferentQyLog->count($where_today_qy); + $month_qy = $this->mdDifferentQyLog->count($where_month_qy); + } else { + $this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog'); + $today_qy = $this->mdWechatqyLog->count($where_today_qy); + $month_qy = $this->mdWechatqyLog->count($where_month_qy); + } + } + $where_today_dd[$where_customer_id] = null; + $where_month_dd[$where_customer_id] = null; + $where_today_order[$where_customer_id] = null; + $where_month_order[$where_customer_id] = null; + $where_today_defeat[$where_customer_id] = null; + $where_month_defeat[$where_customer_id] = null; + $statistics = [ + ['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_xs)] + , 'month' => ['title' => '本月线索', 'value' => $this->customers_model->count($where_month_xs)]], + ['today' => ['title' => '今日', 'value' => $today_qy], 'month' => ['title' => '本月企v', 'value' => $month_qy]], + ['today' => ['title' => '今日', 'value' => $this->mdCustomerOpLogs->count($where_today_dd)] + , 'month' => ['title' => '本月到店', 'value' => $this->mdCustomerOpLogs->count($where_month_dd)]], + ['today' => ['title' => '今日', 'value' => $this->receiver_orders_v2_model->count($where_today_order)] + , 'month' => ['title' => '本月订单', 'value' => $this->receiver_orders_v2_model->count($where_month_order)]], + ['today' => ['title' => '今日', 'value' => $this->mdCustomerOpLogs->count($where_today_defeat)] + , 'month' => ['title' => '本月战败', 'value' => $this->mdCustomerOpLogs->count($where_month_defeat)]] + ]; $data = [ 'wl_count' => ['title' => '待跟进客户(人)', 'num' => $wl_num, 'url' => '/pages/customer/filterList/index?status=1&visit=1&title=待跟进客户'], 'gz_count' => ['title' => '特别关注客户(人)', 'num' => $gz_count, 'url' => '/pages/customer/filterList/index?istop=1&title=特别关注客户'], @@ -326,6 +406,7 @@ class User extends Wxapp 'deallist' => $deallist, 'customer_op_list' => $customer_op_list, 'levelSt' => $levelSt, + 'statistics' => $statistics ]; return $data; }