1 | <?php
|
---|
2 | if (!defined('BASEPATH'))
|
---|
3 | exit('No direct script access allowed');
|
---|
4 |
|
---|
5 | class Collabolator_model extends MY_Model {
|
---|
6 |
|
---|
7 | protected $table_name = 'tblcollaborator';
|
---|
8 | protected $id_name = 'id';
|
---|
9 |
|
---|
10 | function __construct() {
|
---|
11 | parent::__construct();
|
---|
12 | }
|
---|
13 |
|
---|
14 | function getCollaborators($data) {
|
---|
15 | $sql = "SELECT * FROM " . $this->table_name;
|
---|
16 | if ($data['keyword']) {
|
---|
17 | if ($data['search_field'] == "cellphone") {
|
---|
18 | if(strlen($data['daterange_start'])>0){
|
---|
19 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
20 | }else{
|
---|
21 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
22 | }
|
---|
23 | } else {
|
---|
24 | if(strlen($data['daterange_start'])>0){
|
---|
25 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
26 | }else{
|
---|
27 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }else{
|
---|
31 | if(strlen($data['daterange_start'])>0){
|
---|
32 | $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | $order = "";
|
---|
37 | if ($data['sorting_order'] != "sorting") {
|
---|
38 |
|
---|
39 | $sort = "DESC";
|
---|
40 | if ($data['sorting_order'] == "sorting_asc")
|
---|
41 | $sort = "ASC";
|
---|
42 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
43 |
|
---|
44 | }
|
---|
45 |
|
---|
46 | return $this->db->query($sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ")->result_array();
|
---|
47 | }
|
---|
48 |
|
---|
49 | function getAllCollaboratorUser($from,$id=false)
|
---|
50 | {
|
---|
51 | $from = date("Y-m-d 00:00:00",$from);
|
---|
52 | $where="";
|
---|
53 | if ($id)
|
---|
54 | {
|
---|
55 | $where = " AND tbluser.collaborator = $id ";
|
---|
56 | }
|
---|
57 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id WHERE tbluser.created_time > '".$from."'".$where."";
|
---|
58 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone WHERE tbluser.created_time > '".$from."'".$where."";
|
---|
59 |
|
---|
60 | $result = $this->db->query($sql)->result_array();
|
---|
61 | foreach ($result as $index=>$paidlog)
|
---|
62 | {
|
---|
63 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
64 | }
|
---|
65 |
|
---|
66 | return $result;
|
---|
67 | }
|
---|
68 | function countCountCollaboratorUser($data)
|
---|
69 | {
|
---|
70 | $order = "";
|
---|
71 | if ($data['sorting_order'] != "sorting") {
|
---|
72 |
|
---|
73 | $sort = "DESC";
|
---|
74 | if ($data['sorting_order'] == "sorting_asc")
|
---|
75 | $sort = "ASC";
|
---|
76 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
77 |
|
---|
78 | }
|
---|
79 | $where="";
|
---|
80 | if ($data['keyword']) {
|
---|
81 | if ($data['search_field'] == "cellphone") {
|
---|
82 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
83 | } else {
|
---|
84 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
85 | }
|
---|
86 | }
|
---|
87 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
88 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." GROUP BY tblcollaborator.id ".$order." ";
|
---|
89 |
|
---|
90 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." GROUP BY tblcollaborator.id ".$order." ";
|
---|
91 |
|
---|
92 | $result = $this->db->query($sql)->result_array();
|
---|
93 |
|
---|
94 |
|
---|
95 | return count($result);
|
---|
96 | }
|
---|
97 | function getCountCollaboratorUser($data)
|
---|
98 | {
|
---|
99 | $order = "";
|
---|
100 | if ($data['sorting_order'] != "sorting") {
|
---|
101 |
|
---|
102 | $sort = "DESC";
|
---|
103 | if ($data['sorting_order'] == "sorting_asc")
|
---|
104 | $sort = "ASC";
|
---|
105 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
106 |
|
---|
107 | }
|
---|
108 | $where="";
|
---|
109 | if ($data['keyword']) {
|
---|
110 | if ($data['search_field'] == "cellphone") {
|
---|
111 | $where.=" WHERE (tblcollaborator.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
112 |
|
---|
113 | } else {
|
---|
114 | $where.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
119 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." GROUP BY tblcollaborator.id ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
120 |
|
---|
121 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time, COUNT(tbluser.collaborator) as total_user FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." GROUP BY tblcollaborator.id ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
122 |
|
---|
123 | $result = $this->db->query($sql)->result_array();
|
---|
124 | foreach ($result as $index=>$paidlog)
|
---|
125 | {
|
---|
126 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
127 | }
|
---|
128 |
|
---|
129 | return $result;
|
---|
130 | }
|
---|
131 |
|
---|
132 | function countCountCollaboratorUsers($data)
|
---|
133 | {
|
---|
134 | $order = "";
|
---|
135 | if ($data['sorting_order'] != "sorting") {
|
---|
136 |
|
---|
137 | $sort = "DESC";
|
---|
138 | if ($data['sorting_order'] == "sorting_asc")
|
---|
139 | $sort = "ASC";
|
---|
140 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
141 |
|
---|
142 | }
|
---|
143 | $where="";
|
---|
144 | if ($data['keyword']) {
|
---|
145 | if ($data['search_field'] == "cellphone") {
|
---|
146 | $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
147 | }
|
---|
148 | }
|
---|
149 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
150 | //$sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." AND tbluser.collaborator = ".$data['id']." ".$order."";
|
---|
151 | if(strlen($data['daterange_start'])>0){
|
---|
152 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND (tbluser.created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."') AND tblcollaborator.id = ".$data['id']." ".$order."";
|
---|
153 | }else{
|
---|
154 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND tblcollaborator.id = ".$data['id']." ".$order."";
|
---|
155 | }
|
---|
156 | $result = $this->db->query($sql)->result_array();
|
---|
157 | foreach ($result as $index=>$paidlog)
|
---|
158 | {
|
---|
159 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
160 | }
|
---|
161 |
|
---|
162 | return count($result);
|
---|
163 | }
|
---|
164 | function getCountCollaboratorUsers($data)
|
---|
165 | {
|
---|
166 | $order = "";
|
---|
167 | if ($data['sorting_order'] != "sorting") {
|
---|
168 |
|
---|
169 | $sort = "DESC";
|
---|
170 | if ($data['sorting_order'] == "sorting_asc")
|
---|
171 | $sort = "ASC";
|
---|
172 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
173 |
|
---|
174 | }
|
---|
175 | $where="";
|
---|
176 | if ($data['keyword']) {
|
---|
177 | if ($data['search_field'] == "cellphone") {
|
---|
178 | $where.=" WHERE (tbluser.cellphone LIKE '%" . $data['keyword'] . "%' OR tblcollaborator.district LIKE '%".$data['keyword']."%' OR tblcollaborator.province LIKE '%".$data['keyword']."%')";
|
---|
179 | }
|
---|
180 | }
|
---|
181 | // $from = date("Y-m-d 00:00:00",$from);
|
---|
182 | // $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.id ".$where." AND tbluser.collaborator = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
183 | if(strlen($data['daterange_start'])>0){
|
---|
184 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND (tbluser.created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."') AND tblcollaborator.id = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
185 | }else{
|
---|
186 | $sql="SELECT *,tblcollaborator.created_time as collaborator_created_time,tbluser.cellphone as user_cellphone,tblcollaborator.cellphone as collaborator_cellphone, tbluser.created_time as user_created_time FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.collaborator = tblcollaborator.cellphone ".$where." AND tblcollaborator.id = ".$data['id']." ".$order." LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
|
---|
187 | }
|
---|
188 | $result = $this->db->query($sql)->result_array();
|
---|
189 | foreach ($result as $index=>$paidlog)
|
---|
190 | {
|
---|
191 | $result[$index]['time']= strtotime($paidlog['user_created_time']);
|
---|
192 | }
|
---|
193 |
|
---|
194 | return $result;
|
---|
195 | }
|
---|
196 |
|
---|
197 | function isExist($data) {
|
---|
198 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "'";
|
---|
199 | if (isset($data['id']))
|
---|
200 | {
|
---|
201 | $id=$data['id'];
|
---|
202 | $sql.=" AND id <> ".$id." LIMIT 1";
|
---|
203 | }
|
---|
204 | $result = $this->db->query($sql)->row_array();
|
---|
205 | if ($result['total'] == 1) {
|
---|
206 | return true;
|
---|
207 | } else {
|
---|
208 | return false;
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | function countCollaborator($data) {
|
---|
213 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name;
|
---|
214 | if ($data['keyword']) {
|
---|
215 | if ($data['search_field'] == "cellphone") {
|
---|
216 | if(strlen($data['daterange_start'])>0){
|
---|
217 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
218 | }else{
|
---|
219 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
220 | }
|
---|
221 | } else {
|
---|
222 | if(strlen($data['daterange_start'])>0){
|
---|
223 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
224 | }else{
|
---|
225 | $sql.=" WHERE (full_name LIKE '%" . $data['keyword'] . "%' OR login_name LIKE '%" . $data['keyword'] . "%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }else{
|
---|
229 | if(strlen($data['daterange_start'])>0){
|
---|
230 | $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
231 | }
|
---|
232 | }
|
---|
233 | $result = $this->db->query($sql)->row_array();
|
---|
234 | return $result['total'];
|
---|
235 | }
|
---|
236 | function getCollaborator($id)
|
---|
237 | {
|
---|
238 | $sql="SELECT * FROM ".$this->table_name." WHERE id=".$id." LIMIT 1";
|
---|
239 | $result = $this->db->query($sql)->row_array();
|
---|
240 | return $result;
|
---|
241 | }
|
---|
242 | function getStatistics()
|
---|
243 | {
|
---|
244 |
|
---|
245 | $day = date('w');
|
---|
246 | $data = array();
|
---|
247 | $last_month['start'] = strtotime(date("Y-m-d", strtotime(date("Y-m-d", mktime(0, 0, 0, date("m")-1, 1, date("Y"))))) . " 00:00:00");
|
---|
248 | $last_month['end'] = strtotime(date("Y-m-d", strtotime(date("Y-m-d", mktime(0, 0, 0, date("m"), 0, date("Y"))))) . " 23:59:59");
|
---|
249 |
|
---|
250 | $last_week['start'] = strtotime(date("Y-m-d", strtotime(date('m-d-Y', strtotime('-'.$day.' days')))) . " 00:00:00");
|
---|
251 | $last_week['end'] = strtotime(date("Y-m-d", strtotime(date('m-d-Y', strtotime('+'.(6-$day).' days')))) . " 23:59:59");
|
---|
252 |
|
---|
253 | $last_week['end'] = strtotime('last sunday') + (24 * 60 * 60 - 1);
|
---|
254 | $last_week['start'] = ($last_week['end'] - 7 * 24 * 60 * 60 + 1);
|
---|
255 |
|
---|
256 | $last_year['start'] = strtotime((date("Y") - 1) . "-01-01 00:00:00");
|
---|
257 | $last_year['end'] = strtotime((date("Y") - 1) . "-12-31 23:59:59");
|
---|
258 |
|
---|
259 |
|
---|
260 |
|
---|
261 | $last_quarter = $this->getLastquarter();
|
---|
262 | $last_quarter['start'] = $last_quarter['start'];
|
---|
263 | $last_quarter['end'] = $last_quarter['end'];
|
---|
264 |
|
---|
265 |
|
---|
266 | $this->load->model('paidlog_model');
|
---|
267 | $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
|
---|
268 |
|
---|
269 | $revenue['last_week'] = 0;
|
---|
270 | $revenue['last_month'] = 0;
|
---|
271 | $revenue['last_quarter'] = 0;
|
---|
272 | $revenue['last_year'] = 0;
|
---|
273 |
|
---|
274 | $lastmonth = strtotime(date("Y-m-d", mktime(0, 0, 0, date("m")-1, 1, date("Y"))));
|
---|
275 | $thismonth = strtotime(date('Y-m-01'));
|
---|
276 | $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
|
---|
277 | $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
|
---|
278 |
|
---|
279 | $top['last_month']['user']=0;
|
---|
280 | $top['last_month']['sms']=0;
|
---|
281 | $top['last_month']['card']=0;
|
---|
282 | $top['last_month']['collaborator']=0;
|
---|
283 | $top['this_month']['user']=0;
|
---|
284 | $top['this_month']['sms']=0;
|
---|
285 | $top['this_month']['card']=0;
|
---|
286 | $top['this_month']['collaborator']=0;
|
---|
287 |
|
---|
288 | foreach ($paidlogs as $paidlog) {
|
---|
289 |
|
---|
290 |
|
---|
291 | if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
|
---|
292 |
|
---|
293 | $revenue['last_week']+=$paidlog['amount'];
|
---|
294 | }
|
---|
295 | if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
|
---|
296 |
|
---|
297 | $revenue['last_month']+=$paidlog['amount'];
|
---|
298 | }
|
---|
299 | if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
|
---|
300 |
|
---|
301 | $revenue['last_quarter']+=$paidlog['amount'];
|
---|
302 | }
|
---|
303 | if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
|
---|
304 |
|
---|
305 | $revenue['last_year']+=$paidlog['amount'];
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
|
---|
310 | $charts['last_month'][0]+=$paidlog['amount'];
|
---|
311 | }
|
---|
312 | if (($paidlog['time'] < $lastmonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (7 * 24 * 60 * 60))) {
|
---|
313 | $charts['last_month'][1]+=$paidlog['amount'];
|
---|
314 | }
|
---|
315 | if (($paidlog['time'] < $lastmonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (14 * 24 * 60 * 60))) {
|
---|
316 | $charts['last_month'][2]+=$paidlog['amount'];
|
---|
317 | }
|
---|
318 | if (($paidlog['time'] < $lastmonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (21 * 24 * 60 * 60))) {
|
---|
319 | $charts['last_month'][3]+=$paidlog['amount'];
|
---|
320 | }
|
---|
321 | if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
|
---|
322 | $charts['last_month'][4]+=$paidlog['amount'];
|
---|
323 | }
|
---|
324 |
|
---|
325 | if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth)) {
|
---|
326 | $top['last_month']['user']++;
|
---|
327 | if ($paidlog['paid_type']==1)
|
---|
328 | {
|
---|
329 | $top['last_month']['sms']+=$paidlog['amount'];
|
---|
330 | }
|
---|
331 | if ($paidlog['paid_type']==2)
|
---|
332 | {
|
---|
333 | $top['last_month']['card']+=$paidlog['amount'];
|
---|
334 | }
|
---|
335 | if ($paidlog['collaborator']!="")
|
---|
336 | {
|
---|
337 | $top['last_month']['collaborator']+=$paidlog['amount'];
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 |
|
---|
342 |
|
---|
343 | if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
|
---|
344 |
|
---|
345 | $charts['this_month'][0] += $paidlog['amount'];
|
---|
346 | }
|
---|
347 | if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
|
---|
348 |
|
---|
349 | $charts['this_month'][1]+=$paidlog['amount'];
|
---|
350 | }
|
---|
351 | if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
|
---|
352 |
|
---|
353 | $charts['this_month'][2]+=$paidlog['amount'];
|
---|
354 | }
|
---|
355 | if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
|
---|
356 |
|
---|
357 | $charts['this_month'][3]+=$paidlog['amount'];
|
---|
358 | }
|
---|
359 | if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
|
---|
360 |
|
---|
361 | $charts['this_month'][4]+=$paidlog['amount'];
|
---|
362 | }
|
---|
363 | if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth )) {
|
---|
364 | $top['this_month']['user']++;
|
---|
365 | if ($paidlog['paid_type']==1)
|
---|
366 | {
|
---|
367 | $top['this_month']['sms']+=$paidlog['amount'];
|
---|
368 | }
|
---|
369 | if ($paidlog['paid_type']==2)
|
---|
370 | {
|
---|
371 | $top['this_month']['card']+=$paidlog['amount'];
|
---|
372 | }
|
---|
373 | if ($paidlog['collaborator']!="")
|
---|
374 | {
|
---|
375 | $top['this_month']['collaborator']+=$paidlog['amount'];
|
---|
376 | }
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | $percent=array();
|
---|
381 | foreach ($top['this_month'] as $index=>$value)
|
---|
382 | {
|
---|
383 | $percent[$index]['class']="down";
|
---|
384 | $percent[$index]['display']="giảm";
|
---|
385 | $percent[$index]['value']="n/a";
|
---|
386 | if (($top['this_month'][$index]>0)&&($top['last_month'][$index]>0))
|
---|
387 | {
|
---|
388 | $percent[$index]['value']=round((($top['this_month'][$index] / $top['last_month'][$index])*100),1);
|
---|
389 | if ($top['this_month'][$index] > $top['last_month'][$index])
|
---|
390 | {
|
---|
391 | $percent[$index]['class']="up";
|
---|
392 | $percent[$index]['display']="tăng";
|
---|
393 | }
|
---|
394 | }
|
---|
395 | }
|
---|
396 | $data['percent']=$percent;
|
---|
397 | $data['top']=$top;
|
---|
398 | $max = 0;
|
---|
399 | foreach ($charts['last_month'] as $index => $total) {
|
---|
400 | if ($total > $max) {
|
---|
401 | $max = $total;
|
---|
402 | }
|
---|
403 | $chart_last_month[] = array($index, $total);
|
---|
404 | }
|
---|
405 | foreach ($charts['this_month'] as $index => $total) {
|
---|
406 | if ($total > $max) {
|
---|
407 | $max = $total;
|
---|
408 | }
|
---|
409 | $chart_this_month[] = array($index, $total);
|
---|
410 | }
|
---|
411 |
|
---|
412 | $data['revenue'] = $revenue;
|
---|
413 | $data['max'] = $max;
|
---|
414 | $chard[] = array("color" => "#e67e22", "label" => "Tháng hiện tại", "data" => $chart_this_month);
|
---|
415 | $chard[] = array("color" => "#1abc9c", "label" => "Tháng trước", "data" => $chart_last_month);
|
---|
416 |
|
---|
417 | $data['chard'] = $chard;
|
---|
418 |
|
---|
419 | return $data;
|
---|
420 | }
|
---|
421 | public function getLastquarter() {
|
---|
422 | $current_month = date('m');
|
---|
423 | $current_year = date('Y');
|
---|
424 |
|
---|
425 | if ($current_month >= 1 && $current_month <= 3) {
|
---|
426 | $start_date = strtotime('1-October-' . ($current_year - 1)); // timestamp or 1-October Last Year 12:00:00 AM
|
---|
427 | $end_date = strtotime('1-Janauary-' . $current_year); // // timestamp or 1-January 12:00:00 AM means end of 31 December Last year
|
---|
428 | } else if ($current_month >= 4 && $current_month <= 6) {
|
---|
429 | $start_date = strtotime('1-January-' . $current_year); // timestamp or 1-Janauray 12:00:00 AM
|
---|
430 | $end_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM means end of 31 March
|
---|
431 | } else if ($current_month >= 7 && $current_month <= 9) {
|
---|
432 | $start_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM
|
---|
433 | $end_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM means end of 30 June
|
---|
434 | } else if ($current_month >= 10 && $current_month <= 12) {
|
---|
435 | $start_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM
|
---|
436 | $end_date = strtotime('1-October-' . $current_year); // timestamp or 1-October 12:00:00 AM means end of 30 September
|
---|
437 | }
|
---|
438 | return array("start" => $start_date, "end" => $end_date);
|
---|
439 | }
|
---|
440 |
|
---|
441 | }
|
---|