1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
---|
2 | |
---|
3 | class Paidlog_model extends MY_Model |
---|
4 | { |
---|
5 | |
---|
6 | protected $table_name = 'tblpaidlog'; |
---|
7 | protected $id_name = 'paid_id'; |
---|
8 | |
---|
9 | function __construct() |
---|
10 | { |
---|
11 | parent::__construct(); |
---|
12 | |
---|
13 | } |
---|
14 | function getPaidlogs($data) { |
---|
15 | if ($data['paid_type'] == 0){ |
---|
16 | $sql = "SELECT SUM(amount) as total_amount FROM tblpaidlog"; |
---|
17 | }else{ |
---|
18 | $sql = "SELECT SUM(amount) as total_amount FROM tblpaidlog WHERE paid_type = ".$data['paid_type'];
|
---|
19 | } |
---|
20 | $r = $this->db->query($sql)->row_array(); |
---|
21 | $total_amount = (int)$r['total_amount']; |
---|
22 | $sql = "SELECT * FROM " . $this->table_name. " INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id "; |
---|
23 | if ($data['paid_type'] == 1){ |
---|
24 | $sql.=" WHERE paid_type = 1";
|
---|
25 | } |
---|
26 | if ($data['paid_type'] == 2){ |
---|
27 | $sql.=" WHERE paid_type = 2";
|
---|
28 | } |
---|
29 | /* |
---|
30 | if ($data['keyword']) { |
---|
31 | if ($data['search_field'] == "cellphone") { |
---|
32 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
33 | } |
---|
34 | }else{ |
---|
35 | */ |
---|
36 | if(strlen($data['daterange_start'])>0){ |
---|
37 | if ($data['paid_type'] ==0){ |
---|
38 | $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'"; |
---|
39 | }else{ |
---|
40 | $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
41 | } |
---|
42 | } |
---|
43 | //} |
---|
44 | |
---|
45 | $order = ""; |
---|
46 | if ($data['sorting_order']){ |
---|
47 | if ($data['sorting_order'] != "sorting") { |
---|
48 | if ($data['sorting_field'] != "money") { |
---|
49 | $sort = "DESC"; |
---|
50 | if ($data['sorting_order'] == "sorting_asc") |
---|
51 | $sort = "ASC"; |
---|
52 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | if ($data['start']){ |
---|
57 | $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " "; |
---|
58 | } |
---|
59 | //return $this->db->query($sql)->result_array(); |
---|
60 | $re = $this->db->query($sql)->result_array(); |
---|
61 | $result['paid_logs'] = $re; |
---|
62 | $result['total_amount'] = $total_amount; |
---|
63 | return $result; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | function countPaidlog($data) { |
---|
69 | $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id"; |
---|
70 | /*if ($data['keyword']) { |
---|
71 | if ($data['search_field'] == "cellphone") { |
---|
72 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
73 | } |
---|
74 | }else{ |
---|
75 | */ |
---|
76 | if ($data['paid_type'] == 1){ |
---|
77 | $sql.=" WHERE paid_type = 1"; |
---|
78 | } |
---|
79 | if ($data['paid_type'] == 2){ |
---|
80 | $sql.=" WHERE paid_type = 2"; |
---|
81 | } |
---|
82 | if(strlen($data['daterange_start'])>0){ |
---|
83 | if ($data['paid_type'] ==0){ |
---|
84 | $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'"; |
---|
85 | }else{ |
---|
86 | $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
87 | } |
---|
88 | } |
---|
89 | //} |
---|
90 | |
---|
91 | |
---|
92 | $result = $this->db->query($sql)->row_array(); |
---|
93 | return $result['total']; |
---|
94 | } |
---|
95 | function getPaidlog($id) |
---|
96 | { |
---|
97 | $sql="SELECT * FROM ".$this->table_name." WHERE ".$this->id_name."=".$id." LIMIT 1"; |
---|
98 | $result = $this->db->query($sql)->row_array(); |
---|
99 | return $result; |
---|
100 | } |
---|
101 | function getAllPaidlogs($from) |
---|
102 | { |
---|
103 | // get all paidlogs from the last years until now |
---|
104 | $from = date("Y-m-d 00:00:00",$from); |
---|
105 | $sql="SELECT * FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.us_id = ".$this->table_name.".us_id WHERE ".$this->table_name.".paid_time > '".$from."'"; |
---|
106 | $result = $this->db->query($sql)->result_array(); |
---|
107 | foreach ($result as $index=>$paidlog) |
---|
108 | { |
---|
109 | $result[$index]['time']= strtotime($paidlog['paid_time']); |
---|
110 | } |
---|
111 | |
---|
112 | return $result; |
---|
113 | } |
---|
114 | } |
---|