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 | |
---|
27 | public function viewAsistant() { |
---|
28 | $data = array(); |
---|
29 | |
---|
30 | $admin_info = $this->session->userdata('adminInfo'); |
---|
31 | if ($admin_info) { |
---|
32 | $id = $this->uri->segment(3); |
---|
33 | $data['id'] = $id; |
---|
34 | $data['statistics'] = $this->getStatistics($id); |
---|
35 | $data['content'] = $this->getCollaboratorsUsers(array(), $id); |
---|
36 | $this->load->view('reportAsistant/indexCollaborator', $data); |
---|
37 | } else { |
---|
38 | $this->load->view('login'); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | public function getStatistics($id = false) { |
---|
43 | $data = array(); |
---|
44 | |
---|
45 | $this_year['start'] = strtotime(date("Y") . "-01-01 00:00:00"); |
---|
46 | |
---|
47 | $this->load->model('collabolator_model'); |
---|
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"); |
---|
53 | foreach ($collaborators as $collaborator) { |
---|
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 | } |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
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']; |
---|
132 | $data['total'] = $this->collabolator_model->countCountCollaboratorUser($data); |
---|
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 | } |
---|
144 | |
---|
145 | public function getCollaboratorsUsers($filters = array(), $id = false) { |
---|
146 | |
---|
147 | $this->load->helper('pagging'); |
---|
148 | $this->load->model('collabolator_model'); |
---|
149 | $data['current_page'] = $this->uri->segment(5, 1); |
---|
150 | |
---|
151 | $data['itemsoptions'] = array(10, 25, 50, 100); |
---|
152 | $data['perpage'] = 10; |
---|
153 | if (!$id) { |
---|
154 | $data['id'] = $this->uri->segment(4, 1); |
---|
155 | } else { |
---|
156 | $data['id'] = $id; |
---|
157 | } |
---|
158 | |
---|
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['daterange_start'] = ""; |
---|
182 | $data['daterange_end'] = ""; |
---|
183 | if ($this->input->post('daterange')){ |
---|
184 | $daterange = explode(" - ", $this->input->post('daterange')); |
---|
185 | $daterange[0] = str_replace('/', '-', $daterange[0]); |
---|
186 | $daterange[1] = str_replace('/', '-', $daterange[1]); |
---|
187 | $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0])); |
---|
188 | $data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day')); |
---|
189 | } |
---|
190 | |
---|
191 | $data['start'] = ($data['current_page'] - 1) * $data['perpage']; |
---|
192 | $data['total'] = $this->collabolator_model->countCountCollaboratorUsers($data); |
---|
193 | $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUsers($data); |
---|
194 | foreach ($data['paidlogs'] as $index=>$paidlog) |
---|
195 | { |
---|
196 | $data['paidlogs'][$index]['username']=$this->get_fullname($paidlog['us_id']); |
---|
197 | } |
---|
198 | $data['paging_url'] = base_url() . "/admin/thong_ke_cong_tac_vien/trang_ctv/" . $data['id']; |
---|
199 | $data['num_links'] = 2; |
---|
200 | $data['paging'] = pagging($data); |
---|
201 | |
---|
202 | if ($this->input->is_ajax_request()) { |
---|
203 | return $this->load->view('reportAsistant/listview_user', $data); |
---|
204 | } |
---|
205 | return $this->load->view('reportAsistant/listview_user', $data, true); |
---|
206 | } |
---|
207 | |
---|
208 | private function get_fullname($us_id) { |
---|
209 | $fullname=""; |
---|
210 | $src = 'violet'; |
---|
211 | $token = md5($us_id . self::TOKENPW); |
---|
212 | $this->load->model('user_model'); |
---|
213 | $data = $this->user_model->get_user_info($src, $us_id, $token); |
---|
214 | parse_str($data,$data); |
---|
215 | if (isset($data['fullname'])) |
---|
216 | { |
---|
217 | $fullname=$data['fullname']; |
---|
218 | } |
---|
219 | return $fullname; |
---|
220 | } |
---|
221 | |
---|
222 | public function test() { |
---|
223 | |
---|
224 | |
---|
225 | for ($i = 1; $i <= 5000; $i++) { |
---|
226 | $input['us_id'] = rand(1, 100); |
---|
227 | $input['paid_type'] = rand(1, 2); |
---|
228 | $input['amount'] = rand(3, 10) * 1000; |
---|
229 | $time = (rand((time() - (12 * 30 * 24 * 60 * 60)), time())); |
---|
230 | $input['paid_time'] = date("Y-m-d H:i:s", $time); |
---|
231 | $this->load->model('paidlog_model'); |
---|
232 | $this->paidlog_model->insert($input); |
---|
233 | } |
---|
234 | |
---|
235 | die(); |
---|
236 | |
---|
237 | for ($i = 1; $i <= 100; $i++) { |
---|
238 | $input['us_id'] = $i; |
---|
239 | $input['cellphone'] = "01234567" . (100 + $i); |
---|
240 | $input['collaborator'] = rand(1, 100); |
---|
241 | $input['acc_balanced'] = rand(100000, 1000000); |
---|
242 | $input['expire_date'] = date("Y-m-d H:i:s", time()); |
---|
243 | $input['created_time'] = date("Y-m-d H:i:s", time()); |
---|
244 | $input['updated_time'] = date("Y-m-d H:i:s", time()); |
---|
245 | $this->load->model('user_model'); |
---|
246 | $this->user_model->insert($input); |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | } |
---|