source: pro-violet-viettel/sourcecode/application/modules/admin/models/paidlog_model.php @ 767

Last change on this file since 767 was 767, checked in by namnd, 10 years ago
File size: 3.3 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class 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
13        }
14        function getPaidlogs($data) {
15        $sql = "SELECT * FROM " . $this->table_name. " INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id ";
16                if ($data['paid_type'] == 1){
17                        $sql.=" WHERE paid_type = 1";
18                }
19                if ($data['paid_type'] == 2){
20                        $sql.=" WHERE paid_type = 2";
21                }
22                /*
23        if ($data['keyword']) {
24            if ($data['search_field'] == "cellphone") {
25                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
26            }
27        }else{
28                */
29                if(strlen($data['daterange_start'])>0){
30                        if ($data['paid_type'] ==0){
31                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
32                                //write_file('./log/sql.log', date("m/d/Y H:i:s")." ".$sql."\n", FOPEN_WRITE_CREATE);
33                        }else{
34                                $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
35                        }
36                }
37                //}
38
39        $order = "";
40        if ($data['sorting_order'] != "sorting") {
41            if ($data['sorting_field'] != "money") {
42                $sort = "DESC";
43                if ($data['sorting_order'] == "sorting_asc")
44                    $sort = "ASC";
45                $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
46            }
47        }
48        $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
49        return $this->db->query($sql)->result_array();
50    }
51
52
53
54    function countPaidlog($data) {
55        $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id";
56        /*if ($data['keyword']) {
57            if ($data['search_field'] == "cellphone") {
58                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
59            }
60        }else{
61                */
62                if ($data['paid_type'] == 1){
63                        $sql.=" WHERE paid_type = 1";
64                }
65                if ($data['paid_type'] == 2){
66                        $sql.=" WHERE paid_type = 2";
67                }
68                if(strlen($data['daterange_start'])>0){
69                        if ($data['paid_type'] ==0){
70                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
71                        }else{
72                                $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
73                        }
74                }
75                //}
76               
77       
78        $result = $this->db->query($sql)->row_array();
79        return $result['total'];
80    }
81    function getPaidlog($id)
82    {
83        $sql="SELECT * FROM ".$this->table_name." WHERE ".$this->id_name."=".$id." LIMIT 1";
84        $result = $this->db->query($sql)->row_array();
85        return $result;
86    }
87    function getAllPaidlogs($from)
88    {
89        // get all paidlogs from the last years until now
90        $from = date("Y-m-d 00:00:00",$from);
91        $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."'";
92        $result = $this->db->query($sql)->result_array();
93        foreach ($result as $index=>$paidlog)
94        {
95            $result[$index]['time']=  strtotime($paidlog['paid_time']);
96        }
97         
98        return $result;
99    }
100}
Note: See TracBrowser for help on using the repository browser.