source: pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php @ 818

Last change on this file since 818 was 818, checked in by namnd, 10 years ago
File size: 20.5 KB
Line 
1<?php
2
3if (! defined ( 'BASEPATH' ))
4        exit ( 'No direct script access allowed' );
5
6if ( ! defined('_SBG_PAIDTYPE_SMS')) define('_SBG_PAIDTYPE_SMS', 1);
7if ( ! defined('_SBG_PAIDTYPE_CARD')) define('_SBG_PAIDTYPE_CARD', 2);
8
9class User_model extends CI_Model {
10        const TOKENPW = 'violet';
11       
12        public function __construct() {
13                parent::__construct ();
14                $this->vservices->setApiUrl ( $this->config->item ( 'api_url' ) );
15                $this->vservices->setConnection ( $this->curl );
16                $this->load->helper('language');
17                $this->lang->load('messages', 'message');
18        }
19       
20        public function checkLogin($src, $token, $username, $password) {
21                $data = $this->vservices->actionExecute ( 'login', array (
22                                'src' => $src,
23                                'token' => $token,
24                                'username' => $username,
25                                'password' => $password
26                ), 'user' );
27                if(!($data) || is_null($data)) return array('success'=>-1, 'data'=>$data);
28                parse_str ( $data );
29                if ($status == 0 || $status == 4) {
30                        $us_id = ( int ) $id;
31                        $query = "SELECT * FROM tbluser WHERE us_id = ?";
32                        $result = $this->db->query ( $query, array (
33                                        $us_id
34                        ) );
35                        if ($result->num_rows () == 1) {
36                                return array('success'=>1, 'data'=>$data);
37                        } else {
38                                return array('success'=>0, 'data'=>$data);
39                        }
40                } else {
41                        return array('success'=>0, 'data'=>$data);
42                }
43        }
44       
45        public function register($username, $collaborator, &$collaboratorMsg = '') {
46               
47                $user = array ();
48                $password = $this->create_random_password ();
49                $src = 'SBG';
50                $sms = '';
51                $id = 0;
52                $errMsg = '';
53                $token = md5 ( $username . self::TOKENPW );
54                $phone = $username;
55                $status = 0;
56               
57                if (! is_null ( $collaborator ) || $collaborator != '') {
58                        if (! $this->isExistcollaborator ( $collaborator )) {
59                                $aryPatterns = array('/:collaborator:/');
60                                $sms = preg_replace($aryPatterns, array($collaborator), lang('_SBG_MO_COLLABORATOR_NOT_FOUND_MSG'));
61                                $collaboratorMsg = $status . '|'.$sms;
62                                return $status . '|' . $sms;
63                        }
64                }
65               
66                $data = $this->vservices->actionExecute ( 'update', array (
67                                'src' => $src,
68                                'username' => $username,
69                                'password' => $password,
70                                'fullname' => null,
71                                'phone' => $username,
72                                'token' => $token
73                ), 'user' );
74               
75                if(!($data) || is_null($data))
76                {
77                        $sms = lang('_SBG_MO_REGISTER_DISCONTINUE_MSG');
78                        $collaboratorMsg = $status . '|'.$sms;
79                        return $status . '|' . $sms;
80                }
81               
82                parse_str ( $data );
83
84                switch (( int ) $status) {
85                        case 0 :
86                $this->load->model('frontend/Servicepackage_model');
87                                $trialpackage=$this->Servicepackage_model->getTrialPackage();
88                                $us_id = $id;
89                                $user ['created_time'] = date ( 'Y-m-d H:i:s' );
90                                $user ['updated_time'] = date ( 'Y-m-d H:i:s' );
91                                $user ['us_id'] = $us_id;
92                                $user ['p_id'] = $trialpackage['p_id'];
93                                $user ['expire_date'] = date('Y-m-d', strtotime("+" . $this->config->item("trial_period") . " days", time()));
94                                $user ['cellphone'] = $username;
95                                $user['province'] = $province;
96                                if (! is_null ( $collaborator ) || $collaborator != '') {
97                                        $user ['collaborator'] = $collaborator;
98                                }
99                                $this->db->query ( 'UNLOCK TABLES' );
100                                $this->db->insert ( 'tbluser', $user );
101                                //write_file('./log/test.log', date("H:i:s m-d-Y").": ". var_export($user, TRUE)."\n" , FOPEN_WRITE_CREATE);
102                                $aryPatterns = array ('/:trialdays:/', '/:username:/', '/:password:/');
103                                $trialdays = $this->config->item('trial_period');
104                                $trialdays = strlen($trialdays) < 2 ? '0'. $trialdays : $trialdays;
105                                if ($this->isViettel($username)){
106                                        $sms = preg_replace($aryPatterns, array($trialdays. ' ngay', $username, $password), lang('_SBG_MO_USER_VIETTEL_REGISTER_SUCCESS_MSG'));
107                                }else{
108                                        $aryPatterns = array ('/:username:/', '/:password:/');
109                                        $sms = preg_replace($aryPatterns, array($username, $password), lang('_SBG_MO_USER_NOT_VIETTEL_REGISTER_SUCCESS_MSG'));
110                                }
111                                $status = 1;
112                                $aryPatterns = array('/:username:/');
113                                $collaboratorMsg = $status . '|'. preg_replace($aryPatterns, array($username), lang('_SBG_MO_COLLABOLATOR_REGISTER_SUCCESS_MSG'));
114                                break;
115                        case 2 :
116                        case 4 :
117                                $sms = lang('_SBG_MO_USER_REGISTER_DUPLICATE_MSG');
118                                $status = 0;
119                                $aryPatterns = array('/:username:/');
120                                $collaboratorMsg = $status . '|'. preg_replace($aryPatterns, array($username), lang('_SBG_MO_COLLABOLATOR_REGISTER_DUPLICATE_MSG'));
121                                break;
122                        default :
123                                $status = 0;
124                                $sms = $errMsg;
125                                $collaboratorMsg = $status . '|'. $sms;
126                                break;
127                }
128               
129                return $status . '|' . $sms;
130        }
131       
132        public function create_random_password() {
133                // $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
134                $alphabet = "0123456789";
135                $pass = array ();
136                $alphaLength = strlen ( $alphabet ) - 1;
137                for($i = 0; $i < 6; $i ++) {
138                        $n = rand ( 0, $alphaLength );
139                        $pass [] = $alphabet [$n];
140                }
141                return implode ( $pass );
142        }
143       
144        public function get_user_by_id($us_id) {
145                $this->db->query ( 'UNLOCK TABLES' );
146                $this->db->select ( '*' )->from ( 'tbluser' )->join('tblservicepackage','tbluser.p_id=tblservicepackage.p_id','left')->where ( 'tbluser.us_id', $us_id );
147                $query = $this->db->get ();
148                if ($query->num_rows () > 0) {
149                        $row = $query->row_array ();
150                        return $row;
151                }
152        }
153       
154        public function get_user_info($src, $token, $us_id) {
155                $data = $this->vservices->actionExecute ( 'getinfo', array (
156                                'src' => $src,
157                                'us_id' => $us_id,
158                                'token' => $token
159                ), 'user' );
160                return $data;
161        }
162       
163        public function update_user($src, $token, $user, $us_id) {
164                $data = $this->vservices->actionExecute ( 'update', array (
165                                'src' => $src,
166                                'token' => $token,
167                                'us_id' => $us_id,
168                                'password' => $user ['password'],
169                                'fullname' => $user ['fullname'],
170                                'school' => $user ['school'],
171                                'province' => $user ['province'],
172                                'oldpass' => $user ['oldpass']
173                ), 'user' );
174                $u = array('province'=>$user['province'],
175                                'updated_time'=>date('Y-m-d H:i:s')
176                                );
177                $this->db->where('us_id', $us_id);
178                $this->db->update('tbluser', $u);
179                return $data;
180        }
181        public function update_local_user($input,$us_id)
182        {
183            $this->db->where('us_id', $us_id);
184            $this->db->update('tbluser', $input);
185        }
186       
187        public function changeProfile($sentNumber, $username, $password, &$status = '') {
188                $user = array ();
189                $src = 'SBG';
190                $errMsg = '';
191                $sms = '';
192                $checkSentNumber = $this->get_user_by_cellphone ( $sentNumber );
193               
194                if ($checkSentNumber) {
195                        $aryPatterns = array('/:sentNumber:/');
196                        $sms =  preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_USER_PHONENUM_CHANGE_DUPLICATE_MSG'));
197                        $status = 0;
198                        return $status . '|' . $sms;
199                }
200               
201                $result = $this->get_user_by_cellphone ( $username );
202               
203                if ($result) {
204                       
205                        $us_id = $result ['us_id'];
206                        $token = md5 ( $us_id . self::TOKENPW );
207                        $isCorrectPassword = $this->checkPassword($src, $us_id, $token, $password);
208                        if(!$isCorrectPassword) return '0|'.lang('_SBG_MO_USER_PHONENUM_CHANGE_INCORRECT_PASSWORD_MSG');
209
210                        $data = $this->vservices->actionExecute ( 'update', array (
211                                        'src' => $src,
212                                        'token' => $token,
213                                        'us_id' => $us_id,
214                                        'username' => $sentNumber,
215                                        "password" => $password,
216                                        'oldpass' => $password,
217                                        'phone' => $sentNumber
218                        ), 'user' );
219
220                        if(!($data) || is_null($data))
221                        {
222                                $sms = lang('_SBG_MO_PHONENUM_CHANGE_DISCONTINUE_MSG');
223                                $status = 0;
224                                return $status . '|' . $sms;
225                        }
226                        parse_str ( $data );
227                        switch (( int ) $status) {
228                                case 0 :
229                                        $us_id = $id;
230                                        $user ['updated_time'] = date ( 'Y-m-d H:i:s' );
231                                        $user ['us_id'] = $us_id;
232                                        $user ['cellphone'] = $sentNumber;
233                                        $this->updateUser ( $us_id, $user );
234                                        $aryPatterns = array('/:username:/', '/:sentNumber:/');
235                                        $sms =  preg_replace($aryPatterns, array($username, $sentNumber), lang('_SBG_MO_USER_NEW_PHONENUM_CHANGE_SUCCESS_MSG'));
236                                        $status = 1;
237                                        break;
238                                case 2:
239                                        $aryPatterns = array('/:sentNumber:/');
240                                        $sms = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_USER_PHONENUM_CHANGE_DUPLICATE_MSG'));
241                                        $status = 0;
242                                        break;
243                                case 5 :
244                                        $aryPatterns = array('/:username:/');
245                                        $sms = preg_replace($aryPatterns, array($username), lang('_SBG_MO_USER_PHONENUM_NOT_REGISTER_MSG'));
246                                        $status = 0;
247                                        break;
248                                default :
249                                        $status = 0;
250                                        $sms = $errMsg;
251                                        break;
252                        }
253                } else {
254                        $aryPatterns = array('/:username:/');
255                        $sms = preg_replace($aryPatterns, array($username), lang('_SBG_MO_USER_PHONENUM_NOT_REGISTER_MSG'));
256                        $status = 0;
257                }
258                return $status . '|' . $sms;
259        }
260       
261        public function changePassword($username, $password, &$status = '') {
262                $user = array ();
263                $src = 'SBG';
264                $errMsg = '';
265                $sms = '';
266                $isForgotPassword = false;
267                $pass = $password;
268               
269                if (is_null ( $password ) || $password == '') {
270                        $pass = $this->create_random_password ();
271                        $isForgotPassword = true;
272                }
273               
274                $result = $this->get_user_by_cellphone ( $username );
275               
276                if ($result) {
277                        $us_id = $result ['us_id'];
278                        $token = md5 ( $us_id . self::TOKENPW );
279                        $data = $this->vservices->actionExecute ( 'update', array (
280                                        'src' => $src,
281                                        'token' => $token,
282                                        'us_id' => $us_id,
283                                        "password" => $pass
284                        ), 'user' );
285                       
286                        if(!($data) || is_null($data))
287                        {
288                                $sms = lang('_SBG_MO_PASSWORD_CHANGE_DISCONTINUE_MSG');
289                                $status = 0;
290                                return $status . '|' . $sms;
291                        }
292                        parse_str ( $data );
293                        switch (( int ) $status) {
294                                case 0 :
295                                        $us_id = $id;
296                                        $user ['updated_time'] = date ( 'Y-m-d H:i:s' );
297                                        $this->updateUser ( $us_id, $user );
298                                        if ($isForgotPassword) {
299                                                $aryPatterns = array('/:pass:/');
300                                                $sms = preg_replace($aryPatterns, array($pass), lang('_SBG_MO_USER_PASSWORD_RECOVERY_MSG'));
301                                        } else {
302                                                $aryPatterns = array('/:password:/');
303                                                $sms = preg_replace($aryPatterns, array($pass), lang('_SBG_MO_USER_PASSWORD_CHANGE_SUCCESS_MSG'));
304                                        }
305                                        $status = 1;
306                                        break;
307                                case 5 :
308                                        $aryPatterns = array('/:username:/');
309                                        $sms = preg_replace($aryPatterns, array($username), lang('_SBG_MO_USER_PHONENUM_NOT_REGISTER_MSG'));
310                                        $status = 0;
311                                        break;
312                                default :
313                                        $status = 0;
314                                        $sms = $errMsg;
315                                        break;
316                        }
317                } else {
318                        $aryPatterns = array('/:username:/');
319                        $sms = preg_replace($aryPatterns, array($username), lang('_SBG_MO_USER_PHONENUM_NOT_REGISTER_MSG'));
320                        $status = 0;
321                }
322                return $status . '|' . $sms;
323        }
324       
325        public function checkLicense($userId) {
326                $isNotExpired = false;
327                $userInfo = array ();
328                $userInfo = $this->get_user_by_id ( $userId );
329               
330                $expireDate = $userInfo ['expire_date'];
331               
332                if ((trim ( $expireDate ) == ''))
333                        return $isNotExpired;
334               
335                $today = mktime ();
336                $expireTime = strtotime ( $expireDate . ' 23:59:59' );
337                $isNotExpired = ($today < $expireTime);
338        return $isNotExpired;
339        }
340       
341        public function registerVip($username, $p_code, &$packageData = null) {
342                $user = array ();
343                $sms = '';
344               
345                $result = $this->get_user_by_cellphone ( $username );
346                $package = $this->get_package ( ( int ) $p_code );
347               
348                if (!$package)
349                {
350                        $sms = lang('_SBG_MO_USER_REGISTER_VIP_NOT_FOUND_MSG');
351                        $status = 0;
352                        return $status . '|' . $sms;
353                }
354                       
355                $packageData = $package;
356
357                if ($result) {
358                        if ($result ['acc_balanced'] >= $package ['p_price']) {
359                                $us_id = $result ['us_id'];
360                                $user ['acc_balanced'] = $result ['acc_balanced'] - $package ['p_price'];
361                                if ($this->checkLicense ( $us_id )) {
362                                        $user ['expire_date'] = date ( 'Y-m-d', strtotime ( $result ['expire_date'] . ' + ' . $package ['p_period'] . ' month' ) );
363                                } else {
364                                        $user ['expire_date'] = date ( 'Y-m-d', strtotime ( 'now + ' . $package ['p_period'] . ' month' ) );
365                                }
366                               
367                                $user ['p_id'] = $package ['p_id'];
368                                $user ['updated_time'] = date ( 'Y-m-d H:i:s' );
369                               
370                                $this->updateUser ( $us_id, $user );
371                                $aryPatterns = array('/:period:/');
372                                $sms = preg_replace($aryPatterns, array(date ( 'd/m/Y', strtotime ( $user ['expire_date'] ) )), lang('_SBG_MO_USER_REGISTER_VIP_SUCCESS_MSG'));
373                                $status = 1;
374                        } else {
375                                $sms = lang('_SBG_MO_USER_REGISTER_VIP_FAIL_NOT_ENOUGH_MSG');
376                                $status = 0;
377                        }
378                } else {
379                        $aryPatterns = array('/:username:/');
380                        $sms = preg_replace($aryPatterns, array($username), lang('_SBG_MO_ACCOUNT_NOT_FOUND_MSG'));
381                        $status = 0;
382                }
383                return $status . '|' . $sms;
384        }
385       
386        public function rechargeAccount($username, $amount) {
387                $user = array ();
388                $sms = '';
389                $result = $this->get_user_by_cellphone ( $username );
390                if ($result) {
391                        $us_id = $result ['us_id'];
392                        $user ['acc_balanced'] = $result ['acc_balanced'] + $amount;
393                        $user ['updated_time'] = date ( 'Y-m-d H:i:s' );
394                        $this->updateUser ( $us_id, $user );
395                        $aryPatterns = array('/:amount:/', '/:username:/');
396                        $sms = preg_replace($aryPatterns, array($amount, $username), lang('_SBG_MO_PAY_TO_ACCOUNT_SUCCESS_MSG'));
397                        $status = 1;
398                } else {
399                        $aryPatterns = array('/:username:/');
400                        $sms = preg_replace($aryPatterns, array($username), lang('_SBG_MO_ACCOUNT_NOT_FOUND_MSG'));
401                        $status = 0;
402                }
403                return $status . '|' . $sms;
404        }
405       
406        public function get_user_by_cellphone($cellphone) {
407                $this->db->query ( 'UNLOCK TABLES' );
408                $sql = 'SELECT * FROM tbluser where cellphone = ? LIMIT 0,1';
409                $query = $this->db->query ( $sql, array (
410                                $cellphone
411                ) );
412                $row = $query->row_array ();
413                return $row;
414        }
415       
416        public function isExistcollaborator($collaborator) {
417                $this->db->query ( 'UNLOCK TABLES' );
418                //$this->db->select ( '*' )->from ( 'tblcollaborator' )->where ( 'login_name', $collaborator )->limit ( 1 );
419                $this->db->select ( '*' )->from ( 'tblcollaborator' )->where ( 'cellphone', $collaborator )->limit ( 1 );
420                $result = $this->db->get ()->row_array ();
421                if ($result)
422                        return true;
423                else
424                        return false;
425        }
426       
427        public function updateUser($us_id, $data) {
428                //$this->db->query ( 'UNLOCK TABLES' );
429                $this->db->where ( 'us_id', $us_id );
430                return $this->db->update ( 'tbluser', $data );
431                //write_file('./log/test.log', $this->db->update('tbluser', $data), FOPEN_WRITE_CREATE);
432        }
433       
434        public function get_package($p_code) {
435                $this->db->query ( 'UNLOCK TABLES' );
436                $sql = 'SELECT * FROM tblservicepackage where p_code = ? LIMIT 0,1';
437                $query = $this->db->query ( $sql, array (
438                                $p_code
439                ) );
440                $row = $query->row_array ();
441                return $row;
442        }
443       
444        public function insertSmslog($sentNumber, $serviceID, $commandcode, $info, $receiveTime, $mtbody = null, $responseTime = null) {
445                if (preg_match ( '/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch ) == 1) {
446                        $sentNumber = '0' . $aryMatch [2];
447                }
448               
449                try {
450                        $user = $this->get_user_by_cellphone ( $sentNumber );
451                } catch ( Exception $e ) {
452                }
453               
454                $smslog = array ();
455                $smslog ['sender'] = $sentNumber;
456                $smslog ['us_id'] = isset ( $user ['us_id'] ) ? $user ['us_id'] : NULL;
457                $smslog ['service_id'] = $serviceID;
458                $smslog ['commandcode'] = $commandcode;
459                $smslog ['info'] = $info;
460                $smslog ['created_time'] = $receiveTime;
461                $smslog ['mtbody'] = $mtbody;
462                $smslog ['response_time'] = $responseTime;
463               
464                $this->db->query ( 'UNLOCK TABLES' );
465                $sql = 'INSERT INTO tblsmslog(sender, us_id, service_id, commandcode, info, created_time, mtbody, response_time) VALUES(?,?,?,?,?,?,?,?)';
466                $query = $this->db->query($sql, $smslog);
467        }
468       
469        public function insertPaidlog($sentNumber, $receiveID, $paidType, $amount, $paidTime) {
470                if (preg_match ( '/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch ) == 1) {
471                        $sentNumber = '0' . $aryMatch [2];
472                }
473               
474                try {
475                        $user = $this->get_user_by_cellphone ( $receiveID );
476                } catch ( Exception $e ) {
477                }
478                $paidlog = array ();
479                $paidlog ['us_id'] = isset ( $user ['us_id'] ) ? $user ['us_id'] : NULL;
480                $paidlog ['paid_type'] = $paidType;
481                $paidlog ['amount'] = $amount;
482                $paidlog['source'] = "";
483                if ($paidType == 1)
484                {
485                        $paidlog['source'] = $sentNumber;
486                }
487                elseif ($paidType == 2)
488                {
489                        $paidlog['source'] = 'Thẻ cào';
490                }
491                else
492                {
493                        $paidlog['source'] = '';
494                }
495                $paidlog ['paid_time'] = $paidTime;
496                $sql = 'INSERT INTO tblpaidlog(us_id, paid_type, amount, source, paid_time) VALUES (?,?,?,?,?)';
497
498                return $this->db->query ( $sql, $paidlog );
499        }
500       
501        public function insertCardlog($username, $us_id, $status, $pinCode, $serialNum, $cardValue, $receiveTime)
502        {
503                try {
504                        $user = $this->get_user_by_cellphone ( $username );
505                } catch ( Exception $e ) {
506                }
507               
508                $cardlog = array();
509                $cardlog['sender'] = $username;
510                $cardlog['us_id'] = $us_id;
511                $cardlog['status'] = $status;
512                $cardlog['pin_code'] = $pinCode;
513                $cardlog['serial_num'] = $serialNum;
514                $cardlog['card_value'] = $cardValue;
515                $cardlog['created_time'] = $receiveTime;
516                $this->db->query ( 'UNLOCK TABLES' );
517                $sql = 'INSERT INTO tblcardlog(sender, us_id, status, pin_code, serial_num, card_value, created_time) VALUES(?,?,?,?,?,?,?)';
518                return $this->db->query ($sql, $cardlog);
519        }
520       
521        public function getPaidlog($data)
522        {
523                $us_id = $data['us_id'];
524                $this->db->query ( 'UNLOCK TABLES' );
525                $sql = "SELECT * FROM tblpaidlog where us_id = ? ORDER BY paid_time DESC LIMIT ".$data['start'].", ".$data['perpage']." ";
526                $query = $this->db->query ( $sql, array (
527                                $us_id
528                ) );
529                $row = $query->result_array();
530                return $row;
531        }
532       
533        public function countPaiglogs($us_id)
534        {
535                $this->db->query ( 'UNLOCK TABLES' );
536                $sql="SELECT COUNT(paid_id) AS total FROM tblpaidlog WHERE us_id = ?";
537                $query = $this->db->query ( $sql, array (
538                                $us_id
539                ) );
540                $result = $query->row_array();
541                return $result['total'];
542        }
543       
544        public function checkPassword($src, $us_id, $token, $password)
545        {
546                $data = $this->vservices->actionExecute ( 'getinfo', array (
547                                'src' => $src,
548                                'us_id' => $us_id,
549                                'token' => $token,
550                                'ponly'=>1
551                ), 'user' );
552               
553                parse_str($data);
554                if(md5($password) == $pencrypted) return true; else return false;
555        }
556       
557        public function insertRegisterVipLog($username, $p_code, $isSms=true)
558        {
559                if ($isSms) $source = 'SMS'; else $source = 'Web';
560                $createdTime = date('Y-m-d H:i:s');
561                $this->db->query ( 'UNLOCK TABLES' );
562                $sql = 'INSERT INTO tblregisterpackagelog (username, source, p_code, created_time) VALUES (?,?,?,?)';
563                $query = $this->db->query ( $sql,  array (
564                                'username'=>$username,
565                                'source'=>$source,
566                                'p_code'=>$p_code,
567                                'created_time'=>$createdTime
568                ) );
569        }
570       
571        public function getPackagelog($data)
572        {
573                $username = $data['username'];
574                $us_id = $data['us_id'];
575                $this->db->query ( 'UNLOCK TABLES' );
576                //$sql="SELECT tblregisterpackagelog.source,tblservicepackage.p_name,tblregisterpackagelog.created_time FROM tblregisterpackagelog INNER JOIN tblservicepackage ON tblservicepackage.p_code = tblregisterpackagelog.p_code where username = ? UNION SELECT tblpaidlog.source,tblpaidlog.amount,tblpaidlog.paid_time FROM tblpaidlog where us_id = ? ORDER BY created_time DESC LIMIT ".$data['start'].", ".$data['perpage']."";
577                $sql="SELECT tblregisterpackagelog.source,0 as amount,tblservicepackage.p_name,tblregisterpackagelog.created_time FROM tblregisterpackagelog INNER JOIN tblservicepackage ON tblservicepackage.p_code = tblregisterpackagelog.p_code where username = ? UNION SELECT tblpaidlog.source,tblpaidlog.amount,'Nạp tiền' as name,tblpaidlog.paid_time FROM tblpaidlog where us_id = ? ORDER BY created_time DESC LIMIT ".$data['start'].", ".$data['perpage']."";
578                $query = $this->db->query ( $sql, array ("$username", $us_id) );
579                $row = $query->result_array();
580                return $row;
581        }
582       
583        public function countPackagelogs($username)
584        {
585                $this->db->query ( 'UNLOCK TABLES' );
586                $sql="SELECT COUNT(id) AS total FROM tblregisterpackagelog WHERE username = ?";
587                $query = $this->db->query ( $sql, array (
588                                $username
589                ) );
590                $result = $query->row_array();
591                return $result['total'];
592        }
593       
594        public function getUserById($us_id) {
595                $this->db->query ( 'UNLOCK TABLES' );
596                $this->db->select ( '*' )->from ( 'tbluser' )->where ( 'tbluser.us_id', $us_id );
597                $query = $this->db->get ();
598                if ($query->num_rows () > 0) {
599                        $row = $query->row_array ();
600                        return $row;
601                }
602        }
603       
604        public function isViettel($number) {
605                $prefixViettel = array (
606                                        '96', '97', '98',
607                                        '096', '097', '098', '162', '163', '164', '165', '166', '167', '168', '169',
608                                        '8496', '8497', '8498', '0162', '0163', '0164', '0165', '0166', '0167', '0168', '0169',
609                                        '84162', '84163', '84164', '84165', '84166', '84167', '84168', '84169'
610                );
611                foreach ( $prefixViettel as $value ) {
612                        if (strpos ( $number, $value ) === 0) {
613                                return 1;
614                        }
615                }
616                return 0;
617        }
618       
619}
Note: See TracBrowser for help on using the repository browser.