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