[520] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | class Recharge extends MX_Controller
|
---|
| 4 | {
|
---|
| 5 | public function __construct()
|
---|
| 6 | {
|
---|
| 7 | parent::__construct();
|
---|
[620] | 8 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
| 9 | $this->load->helper('lockfile');
|
---|
| 10 | $this->load->model('services_model');
|
---|
[520] | 11 | }
|
---|
| 12 |
|
---|
| 13 | public function recharge_card()
|
---|
| 14 | {
|
---|
| 15 | $userID = $this->uri->segment(4);
|
---|
| 16 | $input = $this->input->post();
|
---|
| 17 | $cardSerial = $input['card_serial'];
|
---|
| 18 | $pinCard = $input['pin_card'];
|
---|
[620] | 19 | $isLocked = 0;
|
---|
[520] | 20 |
|
---|
[620] | 21 | $user = $this->objUserModel->get_user_by_id($userID);
|
---|
| 22 | $lockFilePreFix = $user['cellphone'];
|
---|
| 23 | $lockFilePath = $this->config->item('topup_lock_path');
|
---|
| 24 | $maxReach = $this->config->item('topup_lock_max_reach');
|
---|
| 25 | $timeToUnlock = $this->config->item('topup_unlock_minute');
|
---|
| 26 |
|
---|
[627] | 27 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, TRUE);
|
---|
[620] | 28 | $chargCard = _SBG_CARD_PAY_SUCCESS;
|
---|
| 29 | $result = array();
|
---|
| 30 | $result['maxReach'] = $maxReach;
|
---|
| 31 | $result['timeToUnlock'] = $timeToUnlock;
|
---|
| 32 | $result['isLocked'] = $isLocked;
|
---|
| 33 | $result['tmp'] = $maxReach;
|
---|
[520] | 34 |
|
---|
[620] | 35 | $lockedMsg = 'QuÜ vá» Äã nháºp sai thÃŽng tin thẻ cà o '. $maxReach .' lần liên tiếp.<br />Xin chá» '. $timeToUnlock .' phút sau Äá» thao tác lại!';
|
---|
[625] | 36 | $chargErrMsg = 'Mã thẻ hoặc Serial khÃŽng Äúng hoặc Äã ÄÆ°á»£c sá» dụng. QuÜ vá» vui lòng kiá»m tra lại!';
|
---|
[620] | 37 | $errMsg = '';
|
---|
| 38 |
|
---|
| 39 | if ($isLocked == 0) {
|
---|
| 40 | $aryParams = array(
|
---|
| 41 | 'EWalletID' => $this->config->item('EWalletID'),
|
---|
| 42 | 'CardSerial' => $cardSerial,
|
---|
| 43 | 'PinCard' => $pinCard,
|
---|
| 44 | );
|
---|
| 45 |
|
---|
| 46 | $aryResult = array();
|
---|
| 47 | $chargCard = $this->services_model->cardPaidProcess($aryParams, $aryResult);
|
---|
| 48 |
|
---|
| 49 | $paidType = 2;
|
---|
| 50 | $amount = $aryResult['TransactionAmount'];
|
---|
| 51 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 52 | $user['acc_balanced'] = $user['acc_balanced'] + $amount;
|
---|
| 53 | $user['updated_time'] = date('Y-m-d H:i:s');
|
---|
| 54 | if ($amount>0){
|
---|
| 55 | $this->objUserModel->updateUser($userID, $user);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | $result['success'] = $chargCard;
|
---|
| 59 |
|
---|
| 60 | if ($chargCard == _SBG_CARD_PAY_SUCCESS){
|
---|
| 61 | $result['username'] = $user['cellphone'];
|
---|
| 62 | $result['acc_balanced'] = $user['acc_balanced'];
|
---|
| 63 | $result['amount'] = $amount;
|
---|
| 64 | $this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
|
---|
| 65 | releaseLockFile($lockFilePreFix, $lockFilePath);
|
---|
| 66 | }
|
---|
| 67 | else {
|
---|
[627] | 68 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, FALSE);
|
---|
[620] | 69 | $errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg;
|
---|
| 70 | }
|
---|
| 71 | }else if ($isLocked == 1) {
|
---|
| 72 | $errMsg = $lockedMsg;
|
---|
| 73 | $result['success'] = _SBG_CARD_PAY_FAIL;
|
---|
[520] | 74 | }
|
---|
[611] | 75 |
|
---|
[620] | 76 | $result['errMsg'] = $errMsg;
|
---|
[520] | 77 | echo json_encode($result);
|
---|
| 78 | }
|
---|
| 79 | } |
---|