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