[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 | {
|
---|
[707] | 17 | $trackingFile = '/srv/www/sbg/log/recharge_card.log';
|
---|
| 18 | error_log ('--START CARD CHARGE--'."\n", 3, $trackingFile);
|
---|
| 19 | error_log ('TIME: '.date('Y-m-d H:i:s')."\n", 3, $trackingFile);
|
---|
| 20 |
|
---|
[520] | 21 | $userID = $this->uri->segment(4);
|
---|
| 22 | $input = $this->input->post();
|
---|
| 23 | $cardSerial = $input['card_serial'];
|
---|
| 24 | $pinCard = $input['pin_card'];
|
---|
[620] | 25 | $isLocked = 0;
|
---|
[520] | 26 |
|
---|
[707] | 27 | error_log ('$cardSerial: '.$cardSerial."\n", 3, $trackingFile);
|
---|
| 28 | error_log ('$cardSerial: '.$pinCard."\n", 3, $trackingFile);
|
---|
| 29 | error_log ('$userID: '.$userID."\n", 3, $trackingFile);
|
---|
| 30 |
|
---|
[620] | 31 | $user = $this->objUserModel->get_user_by_id($userID);
|
---|
| 32 | $lockFilePreFix = $user['cellphone'];
|
---|
| 33 | $lockFilePath = $this->config->item('topup_lock_path');
|
---|
| 34 | $maxReach = $this->config->item('topup_lock_max_reach');
|
---|
| 35 | $timeToUnlock = $this->config->item('topup_unlock_minute');
|
---|
| 36 |
|
---|
[707] | 37 | error_log ('Phone num: '.$user['cellphone']."\n", 3, $trackingFile);
|
---|
| 38 | error_log ('Locked: '.($isLocked ? 'LOCKED':'UNLOCKED')."\n", 3, $trackingFile);
|
---|
| 39 |
|
---|
[627] | 40 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, TRUE);
|
---|
[620] | 41 | $chargCard = _SBG_CARD_PAY_SUCCESS;
|
---|
| 42 | $result = array();
|
---|
| 43 | $result['maxReach'] = $maxReach;
|
---|
| 44 | $result['timeToUnlock'] = $timeToUnlock;
|
---|
| 45 | $result['isLocked'] = $isLocked;
|
---|
| 46 | $result['tmp'] = $maxReach;
|
---|
[520] | 47 |
|
---|
[636] | 48 | //$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!';
|
---|
| 49 | $aryPatterns = array('/:maxReach:/', '/:timeToUnlock:/');
|
---|
| 50 | $lockedMsg = preg_replace($aryPatterns, array($maxReach, $timeToUnlock), lang('_SBG_CHARGING_FROM_CARD_LOCKED_MSG'));
|
---|
| 51 | //$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!';
|
---|
| 52 | $chargErrMsg = lang('_SBG_CHARGING_FROM_CARD_FAIL_MSG');
|
---|
[620] | 53 | $errMsg = '';
|
---|
[695] | 54 | $cardValue = 0;
|
---|
[698] | 55 | $updatedTime = date('Y-m-d H:i:s');
|
---|
| 56 | $status = -1;
|
---|
| 57 |
|
---|
[620] | 58 | if ($isLocked == 0) {
|
---|
| 59 | $aryParams = array(
|
---|
| 60 | 'EWalletID' => $this->config->item('EWalletID'),
|
---|
| 61 | 'CardSerial' => $cardSerial,
|
---|
| 62 | 'PinCard' => $pinCard,
|
---|
| 63 | );
|
---|
| 64 |
|
---|
| 65 | $aryResult = array();
|
---|
[698] | 66 |
|
---|
[620] | 67 | $chargCard = $this->services_model->cardPaidProcess($aryParams, $aryResult);
|
---|
[695] | 68 | $status = $chargCard;
|
---|
[707] | 69 |
|
---|
| 70 | error_log ('CALL TOPUP SERVICE: '.($status ? 'SUCCESS':'NOT SUCCESS')."\n", 3, $trackingFile);
|
---|
| 71 | error_log ('CALL TOPUP SERVICE DATA: '.var_export($aryResult, TRUE)."\n", 3, $trackingFile);
|
---|
[698] | 72 |
|
---|
[620] | 73 | $paidType = 2;
|
---|
| 74 | $amount = $aryResult['TransactionAmount'];
|
---|
[695] | 75 | $cardValue = $amount;
|
---|
[620] | 76 | $paidTime = date('Y-m-d H:i:s');
|
---|
| 77 | $user['acc_balanced'] = $user['acc_balanced'] + $amount;
|
---|
[698] | 78 | $user['updated_time'] = $updatedTime;
|
---|
[695] | 79 | if ($amount > 0){
|
---|
| 80 | $updateData = array('acc_balanced' => $user['acc_balanced'], 'updated_time' => $user['updated_time'] );
|
---|
| 81 | $updated = $this->objUserModel->updateUser($userID, $updateData);
|
---|
[707] | 82 | error_log ('UPDATE ACCOUNT SUCCESS: '.($updated ? 'SUCCESS':'NOT SUCCESS')."\n", 3, $trackingFile);
|
---|
[620] | 83 | }
|
---|
| 84 |
|
---|
| 85 | $result['success'] = $chargCard;
|
---|
| 86 |
|
---|
| 87 | if ($chargCard == _SBG_CARD_PAY_SUCCESS){
|
---|
[636] | 88 | //$result['username'] = $user['cellphone'];
|
---|
[620] | 89 | $result['acc_balanced'] = $user['acc_balanced'];
|
---|
[636] | 90 | //$result['amount'] = $amount;
|
---|
| 91 | $aryPatterns = array('/:amount:/', '/:username:/', '/:acc_balanced:/');
|
---|
| 92 | $result['message'] = preg_replace($aryPatterns, array($amount, $user['cellphone'], $user['acc_balanced']), lang('_SBG_CHARGING_FROM_CARD_SUCCESS_MSG'));
|
---|
[707] | 93 | $paidResult = $this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
|
---|
| 94 | error_log ('INSERT PAID LOG: '.var_export($paidResult, TRUE)."\n", 3, $trackingFile);
|
---|
[620] | 95 | releaseLockFile($lockFilePreFix, $lockFilePath);
|
---|
| 96 | }
|
---|
| 97 | else {
|
---|
[627] | 98 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, FALSE);
|
---|
[698] | 99 | $errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg;
|
---|
[620] | 100 | }
|
---|
| 101 | }else if ($isLocked == 1) {
|
---|
| 102 | $errMsg = $lockedMsg;
|
---|
| 103 | $result['success'] = _SBG_CARD_PAY_FAIL;
|
---|
[698] | 104 | $status = 0;
|
---|
[520] | 105 | }
|
---|
[695] | 106 |
|
---|
[707] | 107 | $cardLogResult = $this->objUserModel->insertCardlog($user['cellphone'],$userID, $status, $pinCard, $cardSerial, $cardValue, $updatedTime);
|
---|
| 108 | error_log ('INSERT CARD LOG: '.var_export($cardLogResult, TRUE)."\n", 3, $trackingFile);
|
---|
| 109 |
|
---|
[695] | 110 | $result['us_id'] = $userID;
|
---|
| 111 | $result['UPDATED_DATA'] = $user;
|
---|
[620] | 112 | $result['errMsg'] = $errMsg;
|
---|
[520] | 113 | echo json_encode($result);
|
---|
[707] | 114 | error_log ('RETURN JSON: '.json_encode($result)."\n", 3, $trackingFile);
|
---|
| 115 | error_log ('--FINISH CARD CHARGE--'."\n", 3, $trackingFile);
|
---|
[520] | 116 | }
|
---|
| 117 | } |
---|