[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');
|
---|
[636] | 11 | $this->load->helper('language');
|
---|
| 12 | $this->lang->load('messages', 'message');
|
---|
[520] | 13 | }
|
---|
| 14 |
|
---|
| 15 | public function recharge_card()
|
---|
| 16 | {
|
---|
| 17 | $userID = $this->uri->segment(4);
|
---|
| 18 | $input = $this->input->post();
|
---|
| 19 | $cardSerial = $input['card_serial'];
|
---|
| 20 | $pinCard = $input['pin_card'];
|
---|
[620] | 21 | $isLocked = 0;
|
---|
[520] | 22 |
|
---|
[620] | 23 | $user = $this->objUserModel->get_user_by_id($userID);
|
---|
| 24 | $lockFilePreFix = $user['cellphone'];
|
---|
| 25 | $lockFilePath = $this->config->item('topup_lock_path');
|
---|
| 26 | $maxReach = $this->config->item('topup_lock_max_reach');
|
---|
| 27 | $timeToUnlock = $this->config->item('topup_unlock_minute');
|
---|
| 28 |
|
---|
[627] | 29 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, TRUE);
|
---|
[620] | 30 | $chargCard = _SBG_CARD_PAY_SUCCESS;
|
---|
| 31 | $result = array();
|
---|
| 32 | $result['maxReach'] = $maxReach;
|
---|
| 33 | $result['timeToUnlock'] = $timeToUnlock;
|
---|
| 34 | $result['isLocked'] = $isLocked;
|
---|
| 35 | $result['tmp'] = $maxReach;
|
---|
[520] | 36 |
|
---|
[636] | 37 | //$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!';
|
---|
| 38 | $aryPatterns = array('/:maxReach:/', '/:timeToUnlock:/');
|
---|
| 39 | $lockedMsg = preg_replace($aryPatterns, array($maxReach, $timeToUnlock), lang('_SBG_CHARGING_FROM_CARD_LOCKED_MSG'));
|
---|
| 40 | //$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!';
|
---|
| 41 | $chargErrMsg = lang('_SBG_CHARGING_FROM_CARD_FAIL_MSG');
|
---|
[620] | 42 | $errMsg = '';
|
---|
| 43 |
|
---|
| 44 | if ($isLocked == 0) {
|
---|
| 45 | $aryParams = array(
|
---|
| 46 | 'EWalletID' => $this->config->item('EWalletID'),
|
---|
| 47 | 'CardSerial' => $cardSerial,
|
---|
| 48 | 'PinCard' => $pinCard,
|
---|
| 49 | );
|
---|
| 50 |
|
---|
| 51 | $aryResult = array();
|
---|
| 52 | $chargCard = $this->services_model->cardPaidProcess($aryParams, $aryResult);
|
---|
| 53 |
|
---|
| 54 | $paidType = 2;
|
---|
| 55 | $amount = $aryResult['TransactionAmount'];
|
---|
| 56 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 57 | $user['acc_balanced'] = $user['acc_balanced'] + $amount;
|
---|
| 58 | $user['updated_time'] = date('Y-m-d H:i:s');
|
---|
| 59 | if ($amount>0){
|
---|
| 60 | $this->objUserModel->updateUser($userID, $user);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | $result['success'] = $chargCard;
|
---|
| 64 |
|
---|
| 65 | if ($chargCard == _SBG_CARD_PAY_SUCCESS){
|
---|
[636] | 66 | //$result['username'] = $user['cellphone'];
|
---|
[620] | 67 | $result['acc_balanced'] = $user['acc_balanced'];
|
---|
[636] | 68 | //$result['amount'] = $amount;
|
---|
| 69 | $aryPatterns = array('/:amount:/', '/:username:/', '/:acc_balanced:/');
|
---|
| 70 | $result['message'] = preg_replace($aryPatterns, array($amount, $user['cellphone'], $user['acc_balanced']), lang('_SBG_CHARGING_FROM_CARD_SUCCESS_MSG'));
|
---|
[620] | 71 | $this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
|
---|
| 72 | releaseLockFile($lockFilePreFix, $lockFilePath);
|
---|
| 73 | }
|
---|
| 74 | else {
|
---|
[627] | 75 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, FALSE);
|
---|
[620] | 76 | $errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg;
|
---|
| 77 | }
|
---|
| 78 | }else if ($isLocked == 1) {
|
---|
| 79 | $errMsg = $lockedMsg;
|
---|
| 80 | $result['success'] = _SBG_CARD_PAY_FAIL;
|
---|
[520] | 81 | }
|
---|
[611] | 82 |
|
---|
[620] | 83 | $result['errMsg'] = $errMsg;
|
---|
[520] | 84 | echo json_encode($result);
|
---|
| 85 | }
|
---|
| 86 | } |
---|