Ignore:
Timestamp:
Nov 14, 2014 6:01:48 AM (11 years ago)
Author:
dungnv
Message:
 
Location:
pro-violet-viettel/sourcecode/application/modules/frontend/models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/frontend/models/servicepackage_model.php

    r490 r499  
    88        const TOKENPW = 'violet';
    99       
    10         function __construct(){
     10        function __construct()
     11        {
    1112        parent::__construct();
    1213                $this->vservices->setApiUrl($this->config->item('api_url'));
     
    1920        return $this->db->query($sql)->result_array();
    2021    }
     22   
    2123    function getPackage($p_id)
    2224    {
     
    2426        return $this->db->query($sql)->row_array();
    2527    }
     28   
     29    function getPackagePriceByCode ($p_code)
     30    {
     31        $sql='SELECT p_price FROM '. $this->table_name .' WHERE p_code = ?';
     32        $query =  $this->db->query($sql , array($p_code));
     33        $row = $query->row_array();
     34        return $row['p_price'];
     35    }
     36   
     37    function getPackageByCode ($p_code)
     38    {
     39        $sql='SELECT * FROM '. $this->table_name .' WHERE p_code = ?';
     40        $query =  $this->db->query($sql , array($p_code));
     41        $row = $query->row_array();
     42        return $row;
     43    }
    2644       
    2745}
  • pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php

    r498 r499  
    66        const TOKENPW = 'violet';
    77       
    8         function __construct(){
     8        public function __construct(){
    99        parent::__construct();
    1010                $this->vservices->setApiUrl($this->config->item('api_url'));
     
    1212    }
    1313       
    14         function checkLogin ($src, $token, $username, $password)
     14        public function checkLogin ($src, $token, $username, $password)
    1515        {
    1616                $data = $this->vservices->actionExecute('login', array('src' => $src, 'token' => $token, 'username' => $username, 'password' => $password), 'user');
    17                                
     17               
    1818                $arr_users = explode("&", $data);
    1919                $str_status = '';
     
    2222                $usid = '';
    2323                $fullname = '';
     24               
    2425                for ($i=0; $i < count($arr_users); $i++)
    2526                {
     
    6869        }
    6970
    70         function register ($username, $collaborator, &$status)
     71        public function register ($username, $collaborator, &$status='')
    7172        {
    7273                $user = array();
     
    7677                $id = 0;
    7778                $errMsg = '';
    78                 $username = '0'.substr($username, 2, strlen($username));
    7979                $token = md5($username.self::TOKENPW);         
    8080                $phone = $username;
     81               
    8182                if (!is_null($collaborator) || $collaborator != ''){
    82                         if($this->isExistcollaborator($collaborator)){
    83                                 $data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>null, 'phone'=>$username, 'token'=>$token), 'user');
    84                                 parse_str($data);
    85                                 switch((int)$status)
    86                                 {
    87                                         case 0:
    88                                                 $us_id = $id;
    89                                                 $user['created_time'] = date('Y-m-d H:i:s');
    90                                                 $user['us_id'] = $us_id;
    91                                                 $user['cellphone'] = $username;
    92                                                 $user['collaborator'] = $collaborator;
    93                                                 $this->db->insert('tbluser', $user);
    94                                                 $sms = "Chuc mung Qui vi da dang ky thanh cong tai khoan Soan Bai giang Online. Hay dang nhap vao soanbaigiang.smas.vn voi ten truy nhap ".$username.", mat khau ".$password." de su dung.";
    95                                                 $status = 1;
    96                                                 break;
    97                                         case 2:                         
    98                                         case 4:
    99                                                 $sms = "So dien thoai cua Qui vi da duoc dang ky !";
    100                                                 $status = 0;
    101                                                 break;
    102                                         default:
    103                                                 $status = 0;
    104                                                 $sms = $errMsg;
    105                                                 break;
    106                                 }
    107                         }
    108                         else
    109                         {
     83                        if(!$this->isExistcollaborator($collaborator)){
    11084                                $sms = "Khong tim thay cong tac vien nao co so dien thoai [".$collaborator."] tren soanbaigiang.smas.vn!";
    11185                                $status = 0;
    112                         }
    113                 }else
    114                 {
    115                         $data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>null, 'phone'=>$username, 'token'=>$token), 'user');
    116                         parse_str($data);               
    117                         switch((int)$status)
    118                         {
    119                                 case 0:
    120                                         $us_id = $id;
    121                                         $user['created_time'] = date('Y-m-d H:i:s');
    122                                         $user['us_id'] = $us_id;
    123                                         $user['cellphone'] = $username;
    124                                         $this->db->insert('tbluser', $user);
    125                                         $sms = "Chuc mung Qui vi da dang ky thanh cong tai khoan Soan Bai giang Online. Hay dang nhap vao soanbaigiang.smas.vn voi ten truy nhap ".$username.", mat khau ".$password." de su dung.";
    126                                         $status = 1;
    127                                         break;
    128                                 case 2:                         
    129                                 case 4:
    130                                         $sms = "So dien thoai cua Qui vi da duoc dang ky !";
    131                                         $status = 0;
    132                                         break;
    133                                 default:
    134                                         $status = 0;
    135                                         $sms = $errMsg;
    136                                         break;
    137                         }
     86                                return $status.'|'.$sms;
     87                        }
     88                }
     89               
     90                $data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>null, 'phone'=>$username, 'token'=>$token), 'user');
     91                parse_str($data);
     92                switch((int)$status)
     93                {
     94                        case 0:
     95                                $us_id = $id;
     96                                $user['created_time'] = date('Y-m-d H:i:s');
     97                                $user['us_id'] = $us_id;
     98                                $user['cellphone'] = $username;
     99                                if (!is_null($collaborator) || $collaborator != ''){
     100                                        $user['collaborator'] = $collaborator;
     101                                }
     102                                $this->db->query('UNLOCK TABLES');
     103                                $this->db->insert('tbluser', $user);
     104                                $sms = "Chuc mung Qui vi da dang ky thanh cong tai khoan Soan Bai giang Online. Hay dang nhap vao soanbaigiang.smas.vn voi ten truy nhap ".$username.", mat khau ".$password." de su dung.";
     105                                $status = 1;
     106                                break;
     107                        case 2:
     108                        case 4:
     109                                $sms = "So dien thoai cua Qui vi da duoc dang ky!";
     110                                $status = 0;
     111                                break;
     112                        default:
     113                                $status = 0;
     114                                $sms = $errMsg;
     115                                break;
    138116                }
    139117               
     
    141119        }
    142120       
    143         function create_random_password()
    144         {
    145                 $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
     121        public function create_random_password()
     122        {
     123                //$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
     124                $alphabet = "0123456789";
    146125                $pass = array();
    147126                $alphaLength = strlen($alphabet) - 1;
     
    153132        }
    154133       
    155         function get_user_by_id($us_id)
    156         {
     134        public function get_user_by_id($us_id)
     135        {
     136                $this->db->query('UNLOCK TABLES');
    157137                $this->db->select('*')->from('tbluser')->where('us_id', $us_id);
    158138                $query = $this->db->get();
     
    164144        }
    165145       
    166         function get_user_info($src, $token, $us_id)
     146        public function get_user_info($src, $token, $us_id)
    167147        {
    168148                $data = $this->vservices->actionExecute('getinfo', array('src' => $src, 'us_id' => $us_id, 'token'=>$token), 'user');
     
    170150        }
    171151       
    172         function update_user($src, $token, $user, $us_id)
     152        public function update_user($src, $token, $user, $us_id)
    173153        {
    174154                $data = $this->vservices->actionExecute('update', array('src'=>$src, 'token'=>$token, 'us_id'=>$us_id,
     
    180160        }
    181161       
    182         function changeProfile($sentNumber, $username, $password, &$status)
     162        public function changeProfile($sentNumber, $username, $password, &$status='')
    183163        {
    184164                $user = array();
     
    205185                                        break;
    206186                                case 5:
    207                                         $sms = "So dien thoai cá»§a Qui vi chua duoc dang ky !";
     187                                        $sms = "So dien thoai cá»§a Qui vi chua duoc dang ky!";
    208188                                        $status = 0;
    209189                                        break;
     
    219199                }else
    220200                {
    221                         $sms = "So dien thoai cá»§a Qui vi chua duoc dang ky !";
     201                        $sms = "So dien thoai cá»§a Qui vi chua duoc dang ky!";
    222202                        $status = 0;
    223203                }
     
    225205        }
    226206       
    227         function changePassword($username, $password, &$status)
     207        public function changePassword($username, $password, &$status = '')
    228208        {
    229209                $user = array();
     
    255235                                                $sms = "Mat khau moi cua quy vi tren soanbaigiang.smas.vn la [".$pass."]";
    256236                                        }else{
    257                                                 $sms = "Qui vi da doi thanh cong mat khau tren soanbaigiang.smas.vn. ";
     237                                                $sms = "Qui vi da doi thanh cong mat khau tren soanbaigiang.smas.vn.";
    258238                                        }
    259239                                        $status = 1;
    260240                                        break;
    261241                                case 5:
    262                                         $sms = "So dien thoai cá»§a Qui vi chua duoc dang ky !";
     242                                        $sms = "So dien thoai cá»§a Qui vi chua duoc dang ky!";
    263243                                        $status = 0;
    264244                                        break;
     
    271251                else
    272252                {
    273                         $sms = "So dien thoai cá»§a Qui vi da duoc dang ky !";
     253                        $sms = "So dien thoai cá»§a Qui vi da duoc dang ky!";
    274254                        $status = 0;
    275255                }
     
    278258       
    279259       
    280         function checkLicense ($userId)
     260        public function checkLicense ($userId)
    281261        {
    282262                $isNotExpired = false;
    283                 $userInfo = $this->get_user_by_id($userId);             
     263                $userInfo = array();
     264                $userInfo = $this->get_user_by_id($userId);     
     265
    284266                $expireDate = $userInfo['expire_date'];
    285267               
     
    292274        }
    293275       
    294         function registerVip($username, $p_name, &$status)
    295         {
    296                 $user = array();
    297                 $sms = '';
     276        public function registerVip($username, $p_code)
     277        {
     278                $user = array();
     279                $sms = '';
     280               
    298281                $result = $this->get_user_by_cellphone($username);
     282                $package = $this->get_package((int)$p_code);
    299283                if($result){
    300                          $package = $this->get_package($p_name);
    301                         if ($result['acc_balanced']>=$package['p_price'])
     284                       
     285                        if ($result['acc_balanced'] >= $package['p_price'])
    302286                        {
    303287                                $us_id = $result['us_id'];
    304                                 $user['acc_balanced'] = $result['acc_balanced'] - $p_price;
     288                                $user['acc_balanced'] = $result['acc_balanced'] - $package['p_price'];
    305289                                if ($this->checkLicense($us_id)){
    306290                                        $user['expire_date'] = date('Y-m-d', strtotime($result['expire_date'].' + '.$package['p_period'].' month'));
     
    309293                                        $user['expire_date'] = date('Y-m-d', strtotime('now + '.$package['p_period'].' month'));
    310294                                }
    311                                 $user['user_package'] = $p_id;
     295                               
     296                                $user['p_id'] = $package['p_id'];
    312297                                $user['updated_time'] = date('Y-m-d H:i:s');
     298                               
    313299                                $this->updateUser($us_id, $user);
    314300                                $sms = "Chuc mung Qui vi da dang ky su dung Soan Bai giang truc tuyen tren soanbaigiang.smas.vn. Qui vi co the su dung dich vu den 24h00 ngay ".date('d/m/Y', strtotime($user['expire_date']));
     
    327313        }
    328314       
    329         function rechargeAccount($username, $amount, &$status)
     315        public function rechargeAccount($username, $amount)
    330316        {
    331317                $user = array();
     
    338324                        $user['updated_time'] = date('Y-m-d H:i:s');
    339325                        $this->updateUser($us_id, $user);
    340                         $sms = "Qui vi da nap thanh cong [".$amount."] vao tai khoan ".$username." tren soanbaigiang.smas.vn";
     326                        $sms = "Qui vi da nap thanh cong ".$amount."VND vao tai khoan ".$username." tren soanbaigiang.smas.vn";
    341327                        $status = 1;
    342328                }else
    343329                {
    344                         $sms = "Tai khoan [".$username."] chua dang ki tai khoan tren he thong SBG Online soanbaigiang.smas.vn.";
     330                        $sms = "Tai khoan ".$username." chua dang ki tai khoan tren he thong SBG Online soanbaigiang.smas.vn.";
    345331                        $status = 0;
    346332                }
     
    348334        }
    349335       
    350         function get_user_by_cellphone($cellphone)
    351         {
    352                 $this->db->select('*')->from('tbluser')->where('cellphone', $cellphone)->limit(1);
    353                 $result = $this->db->get()->row_array();
    354                 return $result;
    355         }
    356        
    357         function isExistcollaborator($collaborator)
    358         {
     336        public function get_user_by_cellphone($cellphone)
     337        {
     338                $this->db->query('UNLOCK TABLES');
     339                $sql = 'SELECT * FROM tbluser where cellphone = ? LIMIT 0,1';
     340                $query = $this->db->query($sql, array($cellphone));
     341                $row = $query->row_array();
     342                return $row;
     343        }
     344       
     345        public function isExistcollaborator($collaborator)
     346        {
     347                $this->db->query('UNLOCK TABLES');
    359348                $this->db->select('*')->from('tblcollaborator')->where('login_name', $collaborator)->limit(1);
    360349                $result = $this->db->get()->row_array();
     
    362351        }
    363352       
    364         function updateUser($us_id, $data)
    365         {
     353        public function updateUser($us_id, $data)
     354        {
     355                $this->db->query('UNLOCK TABLES');
    366356                $this->db->where('us_id', $us_id);
    367357                $this->db->update('tbluser', $data);
    368358        }
    369359       
    370         function get_package($p_name)
    371         {
    372                 $this->db->select('*')->from('tblservicepackage')->where('p_name', $p_name);
    373                 $query = $this->db->get();
    374                 if($query->num_rows() > 0)
    375                 {
    376                         $row = $query->row_array();
    377                         return $row;
    378                 }
    379         }
    380        
    381         function insertSmslog($sentNumber, $userID, $serviceID, $commandcode, $info, $receiveTime)
    382         {
     360        public function get_package($p_code)
     361        {
     362                $this->db->query('UNLOCK TABLES');
     363                $sql = 'SELECT * FROM tblservicepackage where p_code = ? LIMIT 0,1';
     364                $query = $this->db->query($sql, array($p_code));
     365                $row = $query->row_array();
     366                return $row;
     367        }
     368       
     369        public function insertSmslog($sentNumber, $serviceID, $commandcode, $info, $receiveTime)
     370        {
     371                if (preg_match('/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch) == 1) {
     372                        $sentNumber = '0'. $aryMatch[2];
     373                }
     374               
     375                try {
     376                        $user = $this->get_user_by_cellphone($sentNumber);
     377                }
     378                catch(Exception $e) {
     379                       
     380                }
     381               
    383382                $smslog = array();
    384383                $smslog['sender'] = $sentNumber;
    385                 $smslog['us_id'] = $userID;
     384                $smslog['us_id'] = isset($user['us_id']) ? $user['us_id']:NULL;
    386385                $smslog['service_id'] = $serviceID;
    387386                $smslog['commandcode'] = $commandcode;
    388387                $smslog['info'] = $info;
    389388                $smslog['created_time'] = $receiveTime;
    390                 $this->db->insert('tblsmslog', $smslog);
     389                $this->db->query('UNLOCK TABLES');
     390                $sql = 'INSERT INTO tblsmslog(sender, us_id, service_id, commandcode, info, created_time) VALUES(?,?,?,?,?,?)';
     391                $query = $this->db->query($sql, $smslog);
     392                //$this->db->insert('tblsmslog', $smslog);
    391393        }
    392394}
Note: See TracChangeset for help on using the changeset viewer.