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
RevLine 
[422]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();
[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 ";
[767]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                /*
[422]23        if ($data['keyword']) {
24            if ($data['search_field'] == "cellphone") {
[442]25                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
26            }
[690]27        }else{
[767]28                */
29                if(strlen($data['daterange_start'])>0){
30                        if ($data['paid_type'] ==0){
[690]31                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
[767]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']."'";
[690]35                        }
36                }
[767]37                //}
[422]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
[444]53
[441]54    function countPaidlog($data) {
[442]55        $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id";
[767]56        /*if ($data['keyword']) {
[422]57            if ($data['search_field'] == "cellphone") {
[442]58                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
59            }
[690]60        }else{
[767]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){
[690]70                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
[767]71                        }else{
72                                $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
[690]73                        }
74                }
[767]75                //}
[690]76               
[442]77       
[422]78        $result = $this->db->query($sql)->row_array();
79        return $result['total'];
80    }
[441]81    function getPaidlog($id)
[422]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    }
[441]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);
[586]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."'";
[441]92        $result = $this->db->query($sql)->result_array();
93        foreach ($result as $index=>$paidlog)
94        {
95            $result[$index]['time']=  strtotime($paidlog['paid_time']);
96        }
[741]97         
[441]98        return $result;
99    }
[422]100}
Note: See TracBrowser for help on using the repository browser.