source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/report.php @ 441

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

paidlogs

File size: 10.7 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Report extends MX_Controller {
7
8    public function __construct() {
9        parent::__construct();
10        $this->load->helper('cookie');
11    }
12
13    public function index() {
14        $data = array();
15        $admin_info = $this->session->userdata('adminInfo');
16        if ($admin_info) {
17            $data['statistics'] = $this->getStatistics();           
18            $data['content'] = $this->getPaidlogs();
19            $this->load->view('report/index', $data);
20        } else {
21            $this->load->view('login');
22        }
23    }
24    public function getStatistics()
25    {
26        $data=array();
27       
28        $last_month['start']= strtotime(date("Y-m-d", strtotime("first day of previous month"))." 00:00:00");
29        $last_month['end']= strtotime(date("Y-m-d", strtotime("last day of previous month"))." 23:59:59");
30       
31        $last_week['start']= strtotime(date("Y-m-d", strtotime("first day of previous week"))." 00:00:00");
32        $last_week['end']= strtotime(date("Y-m-d", strtotime("last day of previous week"))." 23:59:59");
33       
34        $last_week['end']=strtotime('last sunday')+(24*60*60-1);
35        $last_week['start']=($last_week['end']-7*24*60*60+1);
36       
37        $last_year['start']=  strtotime((date("Y")-1)."-01-01 00:00:00");
38        $last_year['end']=  strtotime((date("Y")-1)."-12-31 23:59:59");
39       
40       
41       
42        $last_quarter=$this->getLastquarter();
43        $last_quarter['start']=  $last_quarter['start'];
44        $last_quarter['end']=  $last_quarter['end'];
45       
46       
47        $this->load->model('paidlog_model');
48        $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
49       
50        $revenue['last_week']=0;
51        $revenue['last_month']=0;
52        $revenue['last_quarter']=0;
53        $revenue['last_year']=0;
54        foreach ($paidlogs as $paidlog)
55        {
56           
57            if (($paidlog['time'] < $last_week['end'])&&($paidlog['time'] > $last_week['start']))
58            {
59                $revenue['last_week']+=$paidlog['amount'];
60            }
61            if (($paidlog['time'] < $last_month['end'])&&($paidlog['time'] > $last_month['start']))
62            {
63                $revenue['last_month']+=$paidlog['amount'];
64            }
65            if (($paidlog['time'] < $last_quarter['end'])&&($paidlog['time'] > $last_quarter['start']))
66            {
67                $revenue['last_quarter']+=$paidlog['amount'];
68            }
69            if (($paidlog['time'] < $last_year['end'])&&($paidlog['time'] > $last_year['start']))
70            {
71                $revenue['last_year']+=$paidlog['amount'];
72            }
73        }
74        $data['revenue']=$revenue;
75        return $this->load->view('report/statistics', $data, true);
76    }
77    public function getLastquarter()
78    {
79        $current_month = date('m');
80          $current_year = date('Y');
81
82          if($current_month>=1 && $current_month<=3)
83          {
84            $start_date = strtotime('1-October-'.($current_year-1));  // timestamp or 1-October Last Year 12:00:00 AM
85            $end_date = strtotime('1-Janauary-'.$current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
86          }
87          else if($current_month>=4 && $current_month<=6)
88          {
89            $start_date = strtotime('1-January-'.$current_year);  // timestamp or 1-Janauray 12:00:00 AM
90            $end_date = strtotime('1-April-'.$current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
91          }
92          else  if($current_month>=7 && $current_month<=9)
93          {
94            $start_date = strtotime('1-April-'.$current_year);  // timestamp or 1-April 12:00:00 AM
95            $end_date = strtotime('1-July-'.$current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
96          }
97          else  if($current_month>=10 && $current_month<=12)
98          {
99            $start_date = strtotime('1-July-'.$current_year);  // timestamp or 1-July 12:00:00 AM
100            $end_date = strtotime('1-October-'.$current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
101          }
102          return array("start"=>$start_date,"end"=>$end_date);
103    }
104    public function getPaidlogs($filters = array()) {
105        $this->load->helper('pagging');
106        $this->load->model('paidlog_model');
107        $data['current_page'] = $this->uri->segment(4, 1);
108        $data['itemsoptions'] = array(10, 25, 50, 100);
109        $data['perpage'] = 10;
110        $data['keyword'] = "";
111        $data['sorting_order']="sorting_desc";
112        $data['sorting_field']="paid_id";
113       
114        if ($this->input->post('sorting_order')) {
115            if ($this->input->post('sorting_order') != "sorting")
116            {
117               $data['sorting_order']=$this->input->post('sorting_order');
118               $data['sorting_field']=$this->input->post('sorting_field');
119            }
120        }
121        if ($this->input->post('items')) {
122            $data['perpage'] = $this->input->post('items');
123        }
124        if ($this->input->post('keyword')) {
125            $data['search_field']="";
126            $data['keyword'] = $this->input->post('keyword');
127           
128            if (preg_match("/[0-9]/", $data['keyword']))
129            {
130               $data['search_field']="cellphone";
131            }
132           
133        }
134       
135        $data['start'] = ($data['current_page'] - 1) * $data['perpage'];   
136        $data['total'] = $this->paidlog_model->countPaidlog($data); 
137        $data['paidlogs'] = $this->paidlog_model->getPaidlogs($data);
138
139        $data['paging_url'] = base_url() . "/admin/doanh_thu_tong_hop/trang/";
140        $data['num_links'] = 2;
141        $data['paging'] = pagging($data);
142
143        if ($this->input->is_ajax_request()) {
144            return $this->load->view('report/listview', $data);
145        }
146        return $this->load->view('report/listview', $data, true);
147    }
148
149    public function addPaidlog() {
150        $result['success'] = 0;
151        $result = array();
152        $input = $this->input->post();
153        $this->load->model('paidlog_model');
154        if (strlen($input['sms_content'])==0)
155        {
156            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
157        }
158        if (strlen($input['sms_reply'])==0)
159        {
160            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
161        }
162        else
163        {
164            /*
165            if ($this->paidlog_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
166            {
167                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
168            }
169             *
170             */
171        }
172        if (strlen($input['service_id'])==0)
173        {
174            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
175        }
176        else
177        {
178            /*
179            if ($this->paidlog_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
180            {
181                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
182            }
183             *
184             */
185        }
186        if (!isset($result['errors']))
187        {
188            $this->load->model('paidlog_model');
189            $this->paidlog_model->insert($input);
190            $result['success'] = 1;
191        }
192
193       
194        echo json_encode($result);
195    }
196    public function viewSms()
197    {
198        $id=$this->uri->segment(4);
199        $this->load->model('paidlog_model');
200        $data=$this->paidlog_model->getPaidlog($id);
201        $this->load->view('report/viewSms',$data);
202    }
203    public function editSms()
204    {
205        $id=$this->uri->segment(4);
206        $this->load->model('paidlog_model');
207        $data=$this->paidlog_model->getPaidlog($id);
208        $this->load->view('report/editSms',$data);
209    }
210    public function dodeleteSms()
211    {
212        $input=$this->input->post();
213        $id=$input['sms_id'];
214        $this->load->model('paidlog_model');
215        $data=$this->paidlog_model->delete($id);
216        $result['success']=1;
217        echo json_encode($result);
218    }
219    public function deleteSms()
220    {
221        $id=$this->uri->segment(4);
222        $this->load->model('paidlog_model');
223        $data=$this->paidlog_model->getPaidlog($id);
224        $this->load->view('report/deleteSms',$data);
225    }
226    public function updateSms()
227    {
228       
229        $input=  $this->input->post();
230        $this->load->model('paidlog_model');
231        if (strlen($input['sms_content'])==0)
232        {
233            $result['errors'][]="Nội dung tin nhắn khÃŽng được để trống";
234        }
235        if (strlen($input['sms_reply'])==0)
236        {
237            $result['errors'][]="Tin nhắn trả về khÃŽng được để trống";
238        }
239        else
240        {
241            /*
242            if ($this->paidlog_model->isExist(array('field'=>'login_name','value'=>$input['login_name'],'id'=>$input['id'])))
243            {
244                $result['errors'][]="Tên đăng nhập đã được sá»­ dụng";
245            }
246             *
247             */
248        }
249        if (strlen($input['service_id'])==0)
250        {
251            $result['errors'][]="Mã dịch vụ khÃŽng được để trống";
252        }
253        else
254        {
255            /*
256            if ($this->paidlog_model->isExist(array('field'=>'cellphone','value'=>$input['cellphone'],'id'=>$input['id'])))
257            {
258                $result['errors'][]="Số điện thoại đã được sá»­ dụng";
259            }
260             *
261             */
262        }
263       
264        if (!isset($result['errors']))
265        {
266            $this->load->model('paidlog_model');
267            $this->paidlog_model->update($input['sms_id'],$input);
268            $result['success'] = 1;
269        }
270        echo json_encode($result);
271    }
272    public function test() {
273       
274     
275        for ($i = 1; $i <= 5000; $i++) {
276            $input['us_id']=rand(1,100);
277            $input['paid_type']=rand(1,2);
278            $input['amount']=rand(3,10)*1000;
279            $time=(rand((time()-(12*30*24*60*60)),time()));
280            $input['paid_time']= date("Y-m-d H:i:s",$time);
281            $this->load->model('paidlog_model');
282            $this->paidlog_model->insert($input);
283        }
284       
285       die();
286     
287        for ($i = 1; $i <= 100; $i++) {
288            $input['us_id']=$i;
289            $input['cellphone']="01234567".(100+$i);
290            $input['collaborator']=rand(1,100);
291            $input['acc_balanced']=rand(100000,1000000);
292            $input['expire_date']=date("Y-m-d H:i:s",time());
293            $input['created_time']=date("Y-m-d H:i:s",time());
294            $input['updated_time']=date("Y-m-d H:i:s",time());
295            $this->load->model('user_model');
296            $this->user_model->insert($input);
297        }
298    }
299
300}
Note: See TracBrowser for help on using the repository browser.