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