[818] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
---|
[422] | 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(); |
---|
[442] | 12 | |
---|
[422] | 13 | } |
---|
[441] | 14 | function getPaidlogs($data) { |
---|
[777] | 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']; |
---|
[422] | 22 | $sql = "SELECT * FROM " . $this->table_name. " INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id "; |
---|
[767] | 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 | /* |
---|
[422] | 30 | if ($data['keyword']) { |
---|
| 31 | if ($data['search_field'] == "cellphone") { |
---|
[442] | 32 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
| 33 | } |
---|
[690] | 34 | }else{ |
---|
[767] | 35 | */ |
---|
| 36 | if(strlen($data['daterange_start'])>0){ |
---|
| 37 | if ($data['paid_type'] ==0){ |
---|
[690] | 38 | $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'"; |
---|
[767] | 39 | }else{ |
---|
| 40 | $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
[690] | 41 | } |
---|
| 42 | } |
---|
[767] | 43 | //} |
---|
[422] | 44 | |
---|
| 45 | $order = ""; |
---|
[818] | 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 | } |
---|
[777] | 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; |
---|
[422] | 64 | } |
---|
| 65 | |
---|
| 66 | |
---|
[444] | 67 | |
---|
[441] | 68 | function countPaidlog($data) { |
---|
[442] | 69 | $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id"; |
---|
[767] | 70 | /*if ($data['keyword']) { |
---|
[422] | 71 | if ($data['search_field'] == "cellphone") { |
---|
[442] | 72 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
| 73 | } |
---|
[690] | 74 | }else{ |
---|
[767] | 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){ |
---|
[690] | 84 | $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'"; |
---|
[767] | 85 | }else{ |
---|
| 86 | $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
[690] | 87 | } |
---|
| 88 | } |
---|
[767] | 89 | //} |
---|
[690] | 90 | |
---|
[442] | 91 | |
---|
[422] | 92 | $result = $this->db->query($sql)->row_array(); |
---|
| 93 | return $result['total']; |
---|
| 94 | } |
---|
[441] | 95 | function getPaidlog($id) |
---|
[422] | 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 | } |
---|
[441] | 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); |
---|
[586] | 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."'"; |
---|
[441] | 106 | $result = $this->db->query($sql)->result_array(); |
---|
| 107 | foreach ($result as $index=>$paidlog) |
---|
| 108 | { |
---|
| 109 | $result[$index]['time']= strtotime($paidlog['paid_time']); |
---|
| 110 | } |
---|
[741] | 111 | |
---|
[441] | 112 | return $result; |
---|
| 113 | } |
---|
[422] | 114 | } |
---|