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

Last change on this file was 883, checked in by namnd, 10 years ago
File size: 3.6 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               
16                if ($data['paid_type'] == 0){
17                        $sql = "SELECT SUM(amount) as total_amount FROM tblpaidlog";
18                }else{
19                        $sql = "SELECT SUM(amount) as total_amount FROM tblpaidlog WHERE paid_type = ".$data['paid_type'];
20                }
21                $r = $this->db->query($sql)->row_array();
22               
23                $total_amount = (int)$r['total_amount'];
24        $sql = "SELECT * FROM " . $this->table_name. " INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id ";
25                if ($data['paid_type'] == 1){
26                        $sql.=" WHERE paid_type = 1";
27                }
28                if ($data['paid_type'] == 2){
29                        $sql.=" WHERE paid_type = 2";
30                }
31                /*
32        if ($data['keyword']) {
33            if ($data['search_field'] == "cellphone") {
34                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
35            }
36        }else{
37                */
38                if(strlen($data['daterange_start'])>0){
39                        if ($data['paid_type'] ==0){
40                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
41                        }else{
42                                $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
43                        }
44                }
45                //}
46
47        $order = "";
48                if ($data['sorting_order']){
49                        if ($data['sorting_order'] != "sorting") {
50                                if ($data['sorting_field'] != "money") {
51                                        $sort = "DESC";
52                                        if ($data['sorting_order'] == "sorting_asc")
53                                                $sort = "ASC";
54                                        $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
55                                }
56                        }
57                }
58
59                //if ($data['start']){
60               
61                        $sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
62                //}
63       
64        //return $this->db->query($sql)->result_array();
65                $re = $this->db->query($sql)->result_array();
66               
67                $result['paid_logs'] = $re;
68               
69                $result['total_amount'] = $total_amount;
70                return $result;
71    }
72
73
74
75    function countPaidlog($data) {
76        $sql = "SELECT COUNT(".$this->id_name.") as total FROM " . $this->table_name." INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id";
77        /*if ($data['keyword']) {
78            if ($data['search_field'] == "cellphone") {
79                $sql.=" WHERE (cellphone LIKE '%" . $data['keyword'] . "%')";
80            }
81        }else{
82                */
83                if ($data['paid_type'] == 1){
84                        $sql.=" WHERE paid_type = 1";
85                }
86                if ($data['paid_type'] == 2){
87                        $sql.=" WHERE paid_type = 2";
88                }
89                if(strlen($data['daterange_start'])>0){
90                        if ($data['paid_type'] ==0){
91                                $sql.=" WHERE paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
92                        }else{
93                                $sql.=" AND paid_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
94                        }
95                }
96                //}
97               
98       
99        $result = $this->db->query($sql)->row_array();
100        return $result['total'];
101    }
102    function getPaidlog($id)
103    {
104        $sql="SELECT * FROM ".$this->table_name." WHERE ".$this->id_name."=".$id." LIMIT 1";
105        $result = $this->db->query($sql)->row_array();
106        return $result;
107    }
108    function getAllPaidlogs($from)
109    {
110        // get all paidlogs from the last years until now
111        $from = date("Y-m-d 00:00:00",$from);
112        $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."'";
113        $result = $this->db->query($sql)->result_array();
114        foreach ($result as $index=>$paidlog)
115        {
116            $result[$index]['time']=  strtotime($paidlog['paid_time']);
117        }
118         
119        return $result;
120    }
121}
Note: See TracBrowser for help on using the repository browser.