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