source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportAsistant.php @ 478

Last change on this file since 478 was 478, checked in by quyenla, 11 years ago

thong ke

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