[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) { |
---|
[422] | 15 | $sql = "SELECT * FROM " . $this->table_name. " INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id "; |
---|
| 16 | if ($data['keyword']) { |
---|
| 17 | if ($data['search_field'] == "cellphone") { |
---|
[442] | 18 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
| 19 | } |
---|
[422] | 20 | } |
---|
| 21 | |
---|
| 22 | $order = ""; |
---|
| 23 | if ($data['sorting_order'] != "sorting") { |
---|
| 24 | if ($data['sorting_field'] != "money") { |
---|
| 25 | $sort = "DESC"; |
---|
| 26 | if ($data['sorting_order'] == "sorting_asc") |
---|
| 27 | $sort = "ASC"; |
---|
| 28 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort; |
---|
| 29 | } |
---|
| 30 | } |
---|
| 31 | $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " "; |
---|
| 32 | // echo $sql; |
---|
| 33 | return $this->db->query($sql)->result_array(); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | function isExist($data) { |
---|
| 37 | $sql = "SELECT COUNT(id) as total FROM " . $this->table_name . " WHERE " . $data['field'] . " = '" . $data['value'] . "'"; |
---|
| 38 | if (isset($data['id'])) |
---|
| 39 | { |
---|
| 40 | $id=$data['id']; |
---|
| 41 | $sql.=" AND id <> ".$id." LIMIT 1"; |
---|
| 42 | } |
---|
| 43 | $result = $this->db->query($sql)->row_array(); |
---|
| 44 | if ($result['total'] == 1) { |
---|
| 45 | return true; |
---|
| 46 | } else { |
---|
| 47 | return false; |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
[441] | 51 | function countPaidlog($data) { |
---|
[442] | 52 | $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id"; |
---|
[422] | 53 | if ($data['keyword']) { |
---|
| 54 | if ($data['search_field'] == "cellphone") { |
---|
[442] | 55 | $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')"; |
---|
| 56 | } |
---|
[422] | 57 | } |
---|
[442] | 58 | |
---|
[422] | 59 | $result = $this->db->query($sql)->row_array(); |
---|
| 60 | return $result['total']; |
---|
| 61 | } |
---|
[441] | 62 | function getPaidlog($id) |
---|
[422] | 63 | { |
---|
| 64 | $sql="SELECT * FROM ".$this->table_name." WHERE ".$this->id_name."=".$id." LIMIT 1"; |
---|
| 65 | $result = $this->db->query($sql)->row_array(); |
---|
| 66 | return $result; |
---|
| 67 | } |
---|
[441] | 68 | function getAllPaidlogs($from) |
---|
| 69 | { |
---|
| 70 | // get all paidlogs from the last years until now |
---|
| 71 | $from = date("Y-m-d 00:00:00",$from); |
---|
| 72 | $sql="SELECT * FROM ".$this->table_name." WHERE paid_time > '".$from."'"; |
---|
| 73 | $result = $this->db->query($sql)->result_array(); |
---|
| 74 | foreach ($result as $index=>$paidlog) |
---|
| 75 | { |
---|
| 76 | $result[$index]['time']= strtotime($paidlog['paid_time']); |
---|
| 77 | } |
---|
| 78 | return $result; |
---|
| 79 | } |
---|
[422] | 80 | } |
---|