[462] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('BASEPATH')) |
---|
| 4 | exit('No direct script access allowed'); |
---|
| 5 | |
---|
| 6 | class ReportAsistant extends MX_Controller { |
---|
| 7 | |
---|
[479] | 8 | const TOKENPW = 'violet'; |
---|
[462] | 9 | |
---|
| 10 | public function __construct() { |
---|
| 11 | parent::__construct(); |
---|
| 12 | $this->load->helper('cookie'); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | public function index() { |
---|
| 16 | $data = array(); |
---|
| 17 | $admin_info = $this->session->userdata('adminInfo'); |
---|
| 18 | if ($admin_info) { |
---|
| 19 | $data['statistics'] = $this->getStatistics(); |
---|
| 20 | $data['content'] = $this->getCollaborators(); |
---|
| 21 | $this->load->view('reportAsistant/index', $data); |
---|
| 22 | } else { |
---|
| 23 | $this->load->view('login'); |
---|
| 24 | } |
---|
| 25 | } |
---|
[479] | 26 | |
---|
| 27 | public function viewAsistant() { |
---|
[462] | 28 | $data = array(); |
---|
[479] | 29 | |
---|
[462] | 30 | $admin_info = $this->session->userdata('adminInfo'); |
---|
| 31 | if ($admin_info) { |
---|
[479] | 32 | $id = $this->uri->segment(3); |
---|
| 33 | $data['id'] = $id; |
---|
[464] | 34 | $data['statistics'] = $this->getStatistics($id); |
---|
[479] | 35 | $data['content'] = $this->getCollaboratorsUsers(array(), $id); |
---|
[478] | 36 | $this->load->view('reportAsistant/indexCollaborator', $data); |
---|
[462] | 37 | } else { |
---|
| 38 | $this->load->view('login'); |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | |
---|
[479] | 42 | public function getStatistics($id = false) { |
---|
[462] | 43 | $data = array(); |
---|
| 44 | |
---|
| 45 | $this_year['start'] = strtotime(date("Y") . "-01-01 00:00:00"); |
---|
| 46 | |
---|
| 47 | $this->load->model('collabolator_model'); |
---|
[479] | 48 | $collaborators = $this->collabolator_model->getAllCollaboratorUser($this_year['start'], $id); |
---|
| 49 | for ($i = 1; $i <= 12; $i++) { |
---|
| 50 | $statistics[$i] = 0; |
---|
| 51 | } |
---|
| 52 | $y = date("Y"); |
---|
[462] | 53 | foreach ($collaborators as $collaborator) { |
---|
[479] | 54 | for ($i = 1; $i <= 12; $i++) { |
---|
| 55 | if ($i < 12) { |
---|
| 56 | if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime($y . "-" . ($i + 1) . "-1 00:00:00")))) { |
---|
| 57 | $statistics[$i] ++; |
---|
| 58 | } |
---|
| 59 | } else { |
---|
| 60 | if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime(($y + 1) . "-1-1 00:00:00")))) { |
---|
| 61 | $statistics[$i] ++; |
---|
| 62 | } |
---|
[462] | 63 | } |
---|
| 64 | } |
---|
| 65 | } |
---|
[479] | 66 | |
---|
[462] | 67 | $max = 0; |
---|
| 68 | foreach ($statistics as $index => $total) { |
---|
| 69 | if ($total > $max) { |
---|
| 70 | $max = $total; |
---|
| 71 | } |
---|
| 72 | $chart[] = array($index, $total); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | $data['max'] = $max; |
---|
| 76 | $chard[] = array("color" => "#e67e22", "label" => "Lượng ngưá»i dùng giá»i thiá»u bá»i cá»ng tác viên theo từng tháng", "data" => $chart); |
---|
| 77 | $data['chard'] = $chard; |
---|
| 78 | |
---|
| 79 | return $this->load->view('reportAsistant/statistics', $data, true); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | public function getLastquarter() { |
---|
| 83 | $current_month = date('m'); |
---|
| 84 | $current_year = date('Y'); |
---|
| 85 | |
---|
| 86 | if ($current_month >= 1 && $current_month <= 3) { |
---|
| 87 | $start_date = strtotime('1-October-' . ($current_year - 1)); // timestamp or 1-October Last Year 12:00:00 AM |
---|
| 88 | $end_date = strtotime('1-Janauary-' . $current_year); // // timestamp or 1-January 12:00:00 AM means end of 31 December Last year |
---|
| 89 | } else if ($current_month >= 4 && $current_month <= 6) { |
---|
| 90 | $start_date = strtotime('1-January-' . $current_year); // timestamp or 1-Janauray 12:00:00 AM |
---|
| 91 | $end_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM means end of 31 March |
---|
| 92 | } else if ($current_month >= 7 && $current_month <= 9) { |
---|
| 93 | $start_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM |
---|
| 94 | $end_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM means end of 30 June |
---|
| 95 | } else if ($current_month >= 10 && $current_month <= 12) { |
---|
| 96 | $start_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM |
---|
| 97 | $end_date = strtotime('1-October-' . $current_year); // timestamp or 1-October 12:00:00 AM means end of 30 September |
---|
| 98 | } |
---|
| 99 | return array("start" => $start_date, "end" => $end_date); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | public function getCollaborators($filters = array()) { |
---|
| 103 | |
---|
| 104 | $this->load->helper('pagging'); |
---|
| 105 | $this->load->model('collabolator_model'); |
---|
| 106 | $data['current_page'] = $this->uri->segment(4, 1); |
---|
| 107 | $data['itemsoptions'] = array(10, 25, 50, 100); |
---|
| 108 | $data['perpage'] = 10; |
---|
| 109 | $data['keyword'] = ""; |
---|
| 110 | $data['sorting_order'] = "sorting_desc"; |
---|
| 111 | $data['sorting_field'] = "id"; |
---|
| 112 | |
---|
| 113 | if ($this->input->post('sorting_order')) { |
---|
| 114 | if ($this->input->post('sorting_order') != "sorting") { |
---|
| 115 | $data['sorting_order'] = $this->input->post('sorting_order'); |
---|
| 116 | $data['sorting_field'] = $this->input->post('sorting_field'); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | if ($this->input->post('items')) { |
---|
| 120 | $data['perpage'] = $this->input->post('items'); |
---|
| 121 | } |
---|
| 122 | if ($this->input->post('keyword')) { |
---|
| 123 | $data['search_field'] = ""; |
---|
| 124 | $data['keyword'] = $this->input->post('keyword'); |
---|
| 125 | |
---|
| 126 | if (preg_match("/[0-9]/", $data['keyword'])) { |
---|
| 127 | $data['search_field'] = "cellphone"; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | $data['start'] = ($data['current_page'] - 1) * $data['perpage']; |
---|
[464] | 132 | $data['total'] = $this->collabolator_model->countCountCollaboratorUser($data); |
---|
[462] | 133 | $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUser($data); |
---|
| 134 | |
---|
| 135 | $data['paging_url'] = base_url() . "/admin/thong_ke_cong_tac_vien/trang/"; |
---|
| 136 | $data['num_links'] = 2; |
---|
| 137 | $data['paging'] = pagging($data); |
---|
| 138 | |
---|
| 139 | if ($this->input->is_ajax_request()) { |
---|
| 140 | return $this->load->view('reportAsistant/listview', $data); |
---|
| 141 | } |
---|
| 142 | return $this->load->view('reportAsistant/listview', $data, true); |
---|
| 143 | } |
---|
[479] | 144 | |
---|
| 145 | public function getCollaboratorsUsers($filters = array(), $id = false) { |
---|
| 146 | |
---|
[464] | 147 | $this->load->helper('pagging'); |
---|
| 148 | $this->load->model('collabolator_model'); |
---|
[478] | 149 | $data['current_page'] = $this->uri->segment(5, 1); |
---|
[479] | 150 | |
---|
[464] | 151 | $data['itemsoptions'] = array(10, 25, 50, 100); |
---|
| 152 | $data['perpage'] = 10; |
---|
[479] | 153 | if (!$id) { |
---|
| 154 | $data['id'] = $this->uri->segment(4, 1); |
---|
| 155 | } else { |
---|
| 156 | $data['id'] = $id; |
---|
[478] | 157 | } |
---|
[479] | 158 | |
---|
[464] | 159 | $data['keyword'] = ""; |
---|
| 160 | $data['sorting_order'] = "sorting_desc"; |
---|
| 161 | $data['sorting_field'] = "id"; |
---|
| 162 | |
---|
| 163 | if ($this->input->post('sorting_order')) { |
---|
| 164 | if ($this->input->post('sorting_order') != "sorting") { |
---|
| 165 | $data['sorting_order'] = $this->input->post('sorting_order'); |
---|
| 166 | $data['sorting_field'] = $this->input->post('sorting_field'); |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | if ($this->input->post('items')) { |
---|
| 170 | $data['perpage'] = $this->input->post('items'); |
---|
| 171 | } |
---|
| 172 | if ($this->input->post('keyword')) { |
---|
| 173 | $data['search_field'] = ""; |
---|
| 174 | $data['keyword'] = $this->input->post('keyword'); |
---|
| 175 | |
---|
| 176 | if (preg_match("/[0-9]/", $data['keyword'])) { |
---|
| 177 | $data['search_field'] = "cellphone"; |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | $data['start'] = ($data['current_page'] - 1) * $data['perpage']; |
---|
| 182 | $data['total'] = $this->collabolator_model->countCountCollaboratorUsers($data); |
---|
| 183 | $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUsers($data); |
---|
[479] | 184 | foreach ($data['paidlogs'] as $index=>$paidlog) |
---|
| 185 | { |
---|
| 186 | $data['paidlogs'][$index]['username']=$this->get_username($paidlog['us_id']); |
---|
| 187 | } |
---|
| 188 | $data['paging_url'] = base_url() . "/admin/thong_ke_cong_tac_vien/trang_ctv/" . $data['id']; |
---|
[464] | 189 | $data['num_links'] = 2; |
---|
| 190 | $data['paging'] = pagging($data); |
---|
| 191 | |
---|
| 192 | if ($this->input->is_ajax_request()) { |
---|
| 193 | return $this->load->view('reportAsistant/listview_user', $data); |
---|
| 194 | } |
---|
| 195 | return $this->load->view('reportAsistant/listview_user', $data, true); |
---|
| 196 | } |
---|
| 197 | |
---|
[479] | 198 | private function get_username($us_id) { |
---|
[462] | 199 | $src = 'violet'; |
---|
| 200 | $token = md5($us_id . self::TOKENPW); |
---|
| 201 | $this->load->model('user_model'); |
---|
| 202 | $data = $this->user_model->get_user_info($src, $us_id, $token); |
---|
[479] | 203 | if (strpos($data, '&')) { |
---|
[462] | 204 | $arr_users = explode("&", $data); |
---|
| 205 | $str_username = $arr_users[1]; |
---|
| 206 | $arr_username = explode("=", $str_username); |
---|
| 207 | return $arr_username[1]; |
---|
| 208 | } else { |
---|
| 209 | return ""; |
---|
| 210 | } |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | public function test() { |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | for ($i = 1; $i <= 5000; $i++) { |
---|
| 217 | $input['us_id'] = rand(1, 100); |
---|
| 218 | $input['paid_type'] = rand(1, 2); |
---|
| 219 | $input['amount'] = rand(3, 10) * 1000; |
---|
| 220 | $time = (rand((time() - (12 * 30 * 24 * 60 * 60)), time())); |
---|
| 221 | $input['paid_time'] = date("Y-m-d H:i:s", $time); |
---|
| 222 | $this->load->model('paidlog_model'); |
---|
| 223 | $this->paidlog_model->insert($input); |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | die(); |
---|
| 227 | |
---|
| 228 | for ($i = 1; $i <= 100; $i++) { |
---|
| 229 | $input['us_id'] = $i; |
---|
| 230 | $input['cellphone'] = "01234567" . (100 + $i); |
---|
| 231 | $input['collaborator'] = rand(1, 100); |
---|
| 232 | $input['acc_balanced'] = rand(100000, 1000000); |
---|
| 233 | $input['expire_date'] = date("Y-m-d H:i:s", time()); |
---|
| 234 | $input['created_time'] = date("Y-m-d H:i:s", time()); |
---|
| 235 | $input['updated_time'] = date("Y-m-d H:i:s", time()); |
---|
| 236 | $this->load->model('user_model'); |
---|
| 237 | $this->user_model->insert($input); |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | } |
---|