[369] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
[328] | 2 |
|
---|
| 3 | class User_model extends MY_Model
|
---|
| 4 | {
|
---|
| 5 |
|
---|
| 6 | protected $table_name = 'tbluser';
|
---|
| 7 | protected $id_name = 'us_id';
|
---|
| 8 |
|
---|
| 9 | function __construct()
|
---|
| 10 | {
|
---|
| 11 | parent::__construct();
|
---|
[408] | 12 | $this->vservices->setApiUrl($this->config->item('api_url'));
|
---|
| 13 | $this->vservices->setConnection($this->curl);
|
---|
[328] | 14 | }
|
---|
[369] | 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 | }
|
---|
[375] | 22 |
|
---|
| 23 | function get_list_users($data)
|
---|
| 24 | {
|
---|
| 25 | $sql="SELECT * FROM ".$this->table_name;
|
---|
| 26 | if ($data['keyword'])
|
---|
| 27 | {
|
---|
| 28 | $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%') ";
|
---|
| 29 | }
|
---|
[408] | 30 | if ($data['status'] == 1){
|
---|
| 31 | $sql.=" WHERE expire_date > NOW()";
|
---|
| 32 | }
|
---|
| 33 | if ($data['status'] == 2){
|
---|
| 34 | $sql.=" WHERE expire_date < NOW()";
|
---|
| 35 | }
|
---|
[396] | 36 | $order = "";
|
---|
| 37 | if ($data['sorting_order'] != "sorting") {
|
---|
[408] | 38 | if($data['sorting_field'] != "status"){
|
---|
| 39 | $sort = "DESC";
|
---|
| 40 | if ($data['sorting_order'] == "sorting_asc")
|
---|
| 41 | $sort = "ASC";
|
---|
| 42 | $order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
|
---|
| 43 | }
|
---|
[396] | 44 | }
|
---|
[397] | 45 | return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
|
---|
[375] | 46 | }
|
---|
[328] | 47 |
|
---|
[375] | 48 | function get_total_users($data)
|
---|
| 49 | {
|
---|
| 50 | $sql="SELECT COUNT(".$this->id_name.") AS total FROM ".$this->table_name;
|
---|
[408] | 51 |
|
---|
| 52 | if ($data['status'] == 1){
|
---|
| 53 | $sql.=" WHERE expire_date > NOW()";
|
---|
| 54 | }
|
---|
| 55 | if ($data['status'] == 2){
|
---|
| 56 | $sql.=" WHERE expire_date < NOW()";
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[375] | 59 | if (isset($data['keyword']))
|
---|
| 60 | {
|
---|
[408] | 61 | if (strlen($data['keyword'])>0)
|
---|
| 62 | $sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%') ";
|
---|
[375] | 63 | }
|
---|
| 64 | return $this->db->query($sql)->row_array()['total'];
|
---|
| 65 | }
|
---|
[408] | 66 |
|
---|
| 67 | function get_user_info($src, $us_id, $token)
|
---|
| 68 | {
|
---|
| 69 | $data = $this->vservices->actionExecute('getinfo', array('src' => $src, 'us_id' => $us_id, 'token'=>$token), 'user');
|
---|
| 70 | return $data;
|
---|
| 71 | }
|
---|
[328] | 72 | } |
---|