[435] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
[579] | 3 | class 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){
|
---|
[767] | 27 | $sql.=" WHERE expire_date > NOW() AND p_id <> 5";
|
---|
[435] | 28 | }
|
---|
| 29 | if ($data['status'] == 2){
|
---|
[767] | 30 | $sql.=" WHERE expire_date > NOW() AND p_id = 5";
|
---|
[435] | 31 | }
|
---|
[767] | 32 | if ($data['status'] == 3){
|
---|
| 33 | $sql.=" WHERE expire_date < NOW() AND p_id = 5";
|
---|
| 34 | }
|
---|
| 35 | if ($data['status'] == 4){
|
---|
| 36 | $sql.=" WHERE expire_date < NOW() AND p_id <> 5";
|
---|
| 37 | }
|
---|
[610] | 38 | if (isset($data['keyword']))
|
---|
| 39 | {
|
---|
| 40 | if (strlen($data['keyword'])>0){
|
---|
| 41 | if ($data['status']==0){
|
---|
[690] | 42 | if(strlen($data['daterange_start'])>0){
|
---|
[706] | 43 | $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
[690] | 44 | }else
|
---|
| 45 | {
|
---|
[706] | 46 | $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%')";
|
---|
[690] | 47 | }
|
---|
[610] | 48 | }else
|
---|
| 49 | {
|
---|
[690] | 50 | if(strlen($data['daterange_start'])>0){
|
---|
[706] | 51 | $sql.=" AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced 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']."')";
|
---|
[690] | 52 | }else{
|
---|
[706] | 53 | $sql.=" AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
|
---|
[690] | 54 | }
|
---|
[610] | 55 | }
|
---|
[690] | 56 | }else
|
---|
| 57 | {
|
---|
| 58 | if(strlen($data['daterange_start'])>0){
|
---|
| 59 | if ($data['status']==0){
|
---|
| 60 | $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
| 61 | }else{
|
---|
| 62 | $sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
[610] | 65 | }
|
---|
| 66 | }
|
---|
[435] | 67 | $order = "";
|
---|
| 68 | if ($data['sorting_order'] != "sorting") {
|
---|
| 69 | if($data['sorting_field'] != "status"){
|
---|
| 70 | $sort = "DESC";
|
---|
| 71 | if ($data['sorting_order'] == "sorting_asc")
|
---|
| 72 | $sort = "ASC";
|
---|
| 73 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | function get_total_users($data)
|
---|
| 80 | {
|
---|
| 81 | $sql="SELECT COUNT(".$this->id_name.") AS total FROM ".$this->table_name;
|
---|
| 82 |
|
---|
| 83 | if ($data['status'] == 1){
|
---|
[767] | 84 | $sql.=" WHERE expire_date > NOW() AND p_id <> 5";
|
---|
[435] | 85 | }
|
---|
| 86 | if ($data['status'] == 2){
|
---|
[767] | 87 | $sql.=" WHERE expire_date > NOW() AND p_id = 5";
|
---|
[435] | 88 | }
|
---|
[767] | 89 | if ($data['status'] == 3){
|
---|
| 90 | $sql.=" WHERE expire_date < NOW() AND p_id = 5";
|
---|
| 91 | }
|
---|
| 92 | if ($data['status'] == 4){
|
---|
| 93 | $sql.=" WHERE expire_date < NOW() AND p_id <> 5";
|
---|
| 94 | }
|
---|
[435] | 95 |
|
---|
| 96 | if (isset($data['keyword']))
|
---|
| 97 | {
|
---|
[610] | 98 | if (strlen($data['keyword'])>0){
|
---|
| 99 | if ($data['status']==0){
|
---|
[690] | 100 | if(strlen($data['daterange_start'])>0){
|
---|
| 101 | $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']."')";
|
---|
| 102 | }else
|
---|
| 103 | {
|
---|
| 104 | $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']."%')";
|
---|
| 105 | }
|
---|
[610] | 106 | }else
|
---|
| 107 | {
|
---|
[690] | 108 | if(strlen($data['daterange_start'])>0){
|
---|
| 109 | $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']."')";
|
---|
| 110 | }else{
|
---|
| 111 | $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']."%') ";
|
---|
| 112 | }
|
---|
[610] | 113 | }
|
---|
[690] | 114 | }else
|
---|
| 115 | {
|
---|
| 116 | if(strlen($data['daterange_start'])>0){
|
---|
| 117 | if ($data['status']==0){
|
---|
| 118 | $sql.=" WHERE created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
|
---|
| 119 | }else{
|
---|
| 120 | $sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
[610] | 123 | }
|
---|
[690] | 124 |
|
---|
[435] | 125 | }
|
---|
[579] | 126 |
|
---|
| 127 | $query = $this->db->query($sql);
|
---|
| 128 | $row = $query->row_array();
|
---|
| 129 |
|
---|
| 130 | return $row['total'];
|
---|
[435] | 131 | }
|
---|
| 132 |
|
---|
| 133 | function get_user_info($src, $us_id, $token)
|
---|
| 134 | {
|
---|
| 135 | $data = $this->vservices->actionExecute('getinfo', array('src' => $src, 'us_id' => $us_id, 'token'=>$token), 'user');
|
---|
[459] | 136 | return $data;
|
---|
[435] | 137 | }
|
---|
[584] | 138 |
|
---|
[435] | 139 | } |
---|