diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index fe7dfea0..8f8b03bd 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -25,6 +25,8 @@ class Customer extends HD_Controller $this->load->model('receiver/receiver_clues_model', 'clues_model'); $this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model'); $this->load->model('receiver/receiver_xz_model'); + $this->load->model('receiver/Receiver_customer_stat_plan_model', 'statplan'); + $this->load->model('receiver/Receiver_customer_stat_data_model', 'statdata'); $this->load->model('app/licheb/app_licheb_users_model'); $this->load->model("biz/biz_model"); @@ -117,6 +119,116 @@ class Customer extends HD_Controller return $this->show_view('receiver/customer/lists', true); } + public function lists_statplan(){ + $params = $this->input->get(); + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; + !$params['of_id'] && $params['of_id'] = ''; + !$params['of2_id'] && $params['of2_id'] = ''; + !$params['sp_name'] && $params['sp_name'] = ''; + $where = array(); + if ($params['of_id']) { + $where['of_id'] = $params['of_id']; + } + if ($params['of2_id']) { + $where['of2_id'] = $params['of2_id']; + } + if ($params['sp_name']) { + $where["sp_name like '%{$params['sp_name']}%'"] = null; + } + + $count = $this->statplan->count($where); + $lists = []; + $offlineSources = $this->customers_model->offlineSources(); + if ($count){ + $rows = $this->statplan->select($where, 'id desc', $page, $size, '*'); + foreach ($rows as $key => $val){ + $of_title = ''; + if ($val['of_id']) { + $of_ary = $offlineSources[$val['of_id']]; + $of_title = $of_ary['name']; + $val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']]; + } + $lists[] = array( + 'id' => $val['id'], + 'sp_name' => $val['sp_name'], + 'mobile' => $val['mobile'], + 'of_title' => $of_title, + 's_date' => $val['s_date'], + 'e_date' => $val['e_date'], + 'last_date' => $val['last_date'], + 'c_time' => date('Y-m-d H:i:s', $val['c_time']), + 'u_time' => $val['u_time'], + ); + } + } + + $show_info['offlineSourcesAry'] = $this->customers_model->offlineSources_search(); + $this->data['show_info'] = $show_info; + $this->data['lists'] = $lists; + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['params'] = $params; + $this->data['_title'] = '客户统计计划列表'; + return $this->show_view('receiver/customer/lists_statplan', true); + } + + public function lists_statdata(){ + $params = $this->input->get(); + $id = intval($params['id']); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $where = ['id' => $id]; + $re = $this->statplan->get($where); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '计划不存在!'); + } + + $stat_data = $this->get_statdata($id); + $indexs = $stat_data['indexs']; + $lists = $stat_data['lists']; + + $this->data['indexs'] = $indexs; + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['_title'] = $re['sp_name'].'_统计数据'; + return $this->show_view('receiver/customer/lists_statdata', true); + } + + private function get_statdata($id){ + if (!$id){ + return array(); + } + + $lists = array(); + $where = ['spid' => $id]; + $rows_group_id_k = $this->statdata->select_groupby('group_id,k', $where, 'group_id,k', 0, 0, 'group_id,k'); + $rows_stat_date = $this->statdata->select_groupby('stat_date', $where, 'stat_date', 0, 0, 'stat_date'); + $key_v = $this->statdata->map($map_key = 'k', $map_value = 'v', $where, $order = '', $page = 0, $page_size = 0, $select = "concat(group_id, '-', k, '-', stat_date) as k, v"); + $indexs = ['序号', '栏目']; + $i = 1; + foreach ($rows_group_id_k as $key => $val){ + $group_id = $val['group_id']; + $k = $val['k']; + $list['序号'] = $i; + $list['栏目'] = $k; + foreach ($rows_stat_date as $key_date => $val_date){ + $stat_date = $val_date['stat_date']; + #$index = str_replace('-', '', substr($stat_date, 5)); + $index = substr($stat_date, 5); + if (!in_array($index, $indexs)){ + $indexs[] = $index; + } + $key_ = $group_id . '-' . $k . '-' . $stat_date; + $list[$index] = $key_v[$key_] ? $key_v[$key_] : 0; + } + $lists[] = $list; + $i += 1; + } + + return array('indexs' => $indexs, 'lists' => $lists); + } + private function get_where(&$params) { !$params['biz_id'] && $params['biz_id'] = ''; @@ -415,6 +527,33 @@ class Customer extends HD_Controller return $this->show_view('receiver/customer/get', true); } + public function get_statplan() + { + $id = intval($this->input->get('id')); + if ($id) { + $url = "/receiver/customer/edit_statplan"; + $re = $this->statplan->get(['id' => $id]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '计划不存在!'); + } + $sp_name = $re['sp_name']; + $of_id = $re['of_id']; + $of2_id = $re['of2_id']; + $s_date = $re['s_date']; + $e_date = $re['e_date']; + $s_e_date = $s_date .' ~ '.$e_date; + } else { + $url = "/receiver/customer/edit_statplan"; + $sp_name = ''; + $of_id = ''; + $of2_id = ''; + $s_e_date = ''; + } + $this->data['info'] = ['id' => $id, 'sp_name' => $sp_name, 'of_id' => $of_id, 'of2_id' => $of2_id, 's_e_date' => $s_e_date, 'url' => $url]; + $this->data['show_info'] = ['offlineSourcesAry' => $this->customers_model->offlineSources()]; + return $this->show_view('/receiver/customer/edit_statplan'); + } + public function add() { // TODO: Implement add() method. @@ -450,6 +589,54 @@ class Customer extends HD_Controller } } + public function edit_statplan() + { + $params = $this->input->post()['info']; + $id = intval($params['id']); + if (!$params['sp_name']) { + return $this->show_json(SYS_CODE_FAIL, '计划名不能为空!'); + } + if (!$params['of_id']) { + return $this->show_json(SYS_CODE_FAIL, '来源1不能为空!'); + } + if (!$params['of2_id']) { + return $this->show_json(SYS_CODE_FAIL, '来源2不能为空!'); + } + if (!$params['s_e_date']) { + return $this->show_json(SYS_CODE_FAIL, '起止日期不能为空!'); + } + + $s_e_date = explode(' ~ ', $params['s_e_date']); + $s_date = $s_e_date[0]; + $e_date = $s_e_date[1] ; + if (!$s_date){ + return $this->show_json(SYS_CODE_FAIL, '开始日期不能为空!'); + } + if (!$e_date){ + return $this->show_json(SYS_CODE_FAIL, '结束日期不能为空!'); + } + + $data = [ + 'sp_name' => $params['sp_name'], + 'of_id' => $params['of_id'], + 'of2_id' => $params['of2_id'], + 's_date' => $s_date, + 'e_date' => $e_date, + ]; + + if (!$id){ + $data['c_time'] = time(); + $res = $this->statplan->add($data); + } + else{ + $res = $this->statplan->update($data, array('id' => $id)); + } + if (!$res) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + /** * 编辑 * @return bool @@ -675,6 +862,31 @@ class Customer extends HD_Controller $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis')); } + public function export_statdata(){ + $params = $this->input->get(); + $id = intval($params['id']); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $where = ['id' => $id]; + $re = $this->statplan->get($where); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '计划不存在!'); + } + + $stat_data = $this->get_statdata($id); + $indexs = array(); + foreach ($stat_data['indexs'] as $index){ + $indexs[$index] = $index; + } + $data = $stat_data['lists']; + + $fileName = $re['sp_name'].'_统计数据'; + array_unshift($data, $indexs); + $this->load->library('excel'); + $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis')); + } + //改派 public function edit_adviser() { diff --git a/admin/views/receiver/customer/edit_statplan.php b/admin/views/receiver/customer/edit_statplan.php new file mode 100644 index 00000000..ebaaf0c5 --- /dev/null +++ b/admin/views/receiver/customer/edit_statplan.php @@ -0,0 +1,158 @@ +
+
+ +
+
+ +
+ +
+
+ +
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ + + 本周 + 本月 +
+
+
+ +
+
+ + +
+
+
+ + + + \ No newline at end of file diff --git a/admin/views/receiver/customer/lists_statdata.php b/admin/views/receiver/customer/lists_statdata.php new file mode 100644 index 00000000..b843251c --- /dev/null +++ b/admin/views/receiver/customer/lists_statdata.php @@ -0,0 +1,62 @@ + +
+
+
+
+ +
+
+
+ +
+ + + + + + + + +
+
+
+ + diff --git a/admin/views/receiver/customer/lists_statplan.php b/admin/views/receiver/customer/lists_statplan.php new file mode 100644 index 00000000..0d431d9b --- /dev/null +++ b/admin/views/receiver/customer/lists_statplan.php @@ -0,0 +1,121 @@ + +
+ + +
+
+ 条    +
+ + + + + + + + + + + + + + +
ID计划名客户来源起止时间最近执行日期最后更新时间操作
+
+ +
+
+
+
+ +
+
+
+ +