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

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

paidlogs

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