[422] | 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(); |
---|
[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 | //write_file('./log/sql.log', date("m/d/Y H:i:s")." ".$sql."\n", FOPEN_WRITE_CREATE); |
---|
| 40 | }else{ |
---|
| 41 | $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
[690] | 42 | } |
---|
| 43 | } |
---|
[767] | 44 | //} |
---|
[422] | 45 | |
---|
| 46 | $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 | $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " "; |
---|
[777] | 56 | //return $this->db->query($sql)->result_array(); |
---|
| 57 | $re = $this->db->query($sql)->result_array(); |
---|
| 58 | $result['paid_logs'] = $re; |
---|
| 59 | $result['total_amount'] = $total_amount; |
---|
| 60 | return $result; |
---|
[422] | 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
[444] | 64 | |
---|
[441] | 65 | function countPaidlog($data) { |
---|
[442] | 66 | $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id"; |
---|
[767] | 67 | /*if ($data['keyword']) { |
---|
[422] | 68 | if ($data['search_field'] == "cellphone") { |
---|
[442] | 69 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
| 70 | } |
---|
[690] | 71 | }else{ |
---|
[767] | 72 | */ |
---|
| 73 | if ($data['paid_type'] == 1){ |
---|
| 74 | $sql.=" WHERE paid_type = 1"; |
---|
| 75 | } |
---|
| 76 | if ($data['paid_type'] == 2){ |
---|
| 77 | $sql.=" WHERE paid_type = 2"; |
---|
| 78 | } |
---|
| 79 | if(strlen($data['daterange_start'])>0){ |
---|
| 80 | if ($data['paid_type'] ==0){ |
---|
[690] | 81 | $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'"; |
---|
[767] | 82 | }else{ |
---|
| 83 | $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
[690] | 84 | } |
---|
| 85 | } |
---|
[767] | 86 | //} |
---|
[690] | 87 | |
---|
[442] | 88 | |
---|
[422] | 89 | $result = $this->db->query($sql)->row_array(); |
---|
| 90 | return $result['total']; |
---|
| 91 | } |
---|
[441] | 92 | function getPaidlog($id) |
---|
[422] | 93 | { |
---|
| 94 | $sql="SELECT * FROM ".$this->table_name." WHERE ".$this->id_name."=".$id." LIMIT 1"; |
---|
| 95 | $result = $this->db->query($sql)->row_array(); |
---|
| 96 | return $result; |
---|
| 97 | } |
---|
[441] | 98 | function getAllPaidlogs($from) |
---|
| 99 | { |
---|
| 100 | // get all paidlogs from the last years until now |
---|
| 101 | $from = date("Y-m-d 00:00:00",$from); |
---|
[586] | 102 | $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] | 103 | $result = $this->db->query($sql)->result_array(); |
---|
| 104 | foreach ($result as $index=>$paidlog) |
---|
| 105 | { |
---|
| 106 | $result[$index]['time']= strtotime($paidlog['paid_time']); |
---|
| 107 | } |
---|
[741] | 108 | |
---|
[441] | 109 | return $result; |
---|
| 110 | } |
---|
[422] | 111 | } |
---|