source: pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php @ 690

Last change on this file since 690 was 690, checked in by namnd, 10 years ago
File size: 5.7 KB
RevLine 
[435]1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
[579]3class User_model extends CI_Model
[435]4{
5       
6        protected $table_name = 'tbluser';
7        protected $id_name = 'us_id';
8
9        function __construct()
10        {
11                parent::__construct();
12                $this->vservices->setApiUrl($this->config->item('api_url'));
13                $this->vservices->setConnection($this->curl);
14        }
15       
16        function check_data($login_name)
17        {
18                $this->db->where('login_name', $login_name);
19                $query = $this->db->get($this->table_name);
20                return $query->num_rows();
21        }
22       
23        function get_list_users($data)
24        {
25                $sql="SELECT * FROM ".$this->table_name;
26                if ($data['status'] == 1){
27                        $sql.=" WHERE expire_date > NOW()";
28                }
29                if ($data['status'] == 2){
30                        $sql.=" WHERE expire_date < NOW()";
31                }
[610]32                if (isset($data['keyword']))
33                {
34                        if (strlen($data['keyword'])>0){
35                                if ($data['status']==0){
[690]36                                        if(strlen($data['daterange_start'])>0){
37                                                $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
38                                        }else
39                                        {
40                                                $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
41                                        }
[610]42                                }else
43                                {
[690]44                                        if(strlen($data['daterange_start'])>0){
45                                                $sql.=" AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
46                                        }else{
47                                                $sql.=" AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
48                                        }
[610]49                                }
[690]50                        }else
51                        {
52                                if(strlen($data['daterange_start'])>0){
53                                        if ($data['status']==0){
54                                                $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
55                                        }else{
56                                                $sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
57                                        }
58                                }
[610]59                        }
60                }
[435]61                $order = "";
62                if ($data['sorting_order'] != "sorting") {
63                        if($data['sorting_field'] != "status"){
64                                $sort = "DESC";
65                                if ($data['sorting_order'] == "sorting_asc")
66                                        $sort = "ASC";
67                                $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
68                        }
69                }
70                return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
71        }
72
73        function get_total_users($data)
74        {
75                $sql="SELECT COUNT(".$this->id_name.") AS total FROM ".$this->table_name;
76               
77                if ($data['status'] == 1){
78                        $sql.=" WHERE expire_date > NOW()";
79                }
80                if ($data['status'] == 2){
81                        $sql.=" WHERE expire_date < NOW()";
82                }
83               
84                if (isset($data['keyword']))
85                {
[610]86                        if (strlen($data['keyword'])>0){
87                                if ($data['status']==0){
[690]88                                        if(strlen($data['daterange_start'])>0){
89                                                $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
90                                        }else
91                                        {
92                                                $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
93                                        }
[610]94                                }else
95                                {
[690]96                                        if(strlen($data['daterange_start'])>0){
97                                                $sql.=" AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
98                                        }else{
99                                                $sql.=" AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
100                                        }
[610]101                                }
[690]102                        }else
103                        {
104                                if(strlen($data['daterange_start'])>0){
105                                        if ($data['status']==0){
106                                                $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
107                                        }else{
108                                                $sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
109                                        }
110                                }
[610]111                        }
[690]112                       
[435]113                }
[579]114               
115                $query = $this->db->query($sql);
116                $row = $query->row_array();
117               
118                return $row['total'];
[435]119        }
120       
121        function get_user_info($src, $us_id, $token)
122        {
123                $data = $this->vservices->actionExecute('getinfo', array('src' => $src, 'us_id' => $us_id, 'token'=>$token), 'user');
[459]124        return $data;
[435]125        }
[584]126       
[435]127}
Note: See TracBrowser for help on using the repository browser.