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();
|
---|
8 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
9 | $this->load->helper('lockfile');
|
---|
10 | $this->load->model('services_model');
|
---|
11 | $this->load->helper('language');
|
---|
12 | $this->lang->load('messages', 'message');
|
---|
13 | }
|
---|
14 |
|
---|
15 | public function recharge_card()
|
---|
16 | {
|
---|
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 |
|
---|
21 | $userID = $this->uri->segment(4);
|
---|
22 | $input = $this->input->post();
|
---|
23 | $cardSerial = $input['card_serial'];
|
---|
24 | $pinCard = $input['pin_card'];
|
---|
25 | $isLocked = 0;
|
---|
26 |
|
---|
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 |
|
---|
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 |
|
---|
37 | error_log ('Phone num: '.$user['cellphone']."\n", 3, $trackingFile);
|
---|
38 | error_log ('Locked: '.($isLocked ? 'LOCKED':'UNLOCKED')."\n", 3, $trackingFile);
|
---|
39 |
|
---|
40 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, TRUE);
|
---|
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;
|
---|
47 |
|
---|
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');
|
---|
53 | $errMsg = '';
|
---|
54 | $cardValue = 0;
|
---|
55 | $updatedTime = date('Y-m-d H:i:s');
|
---|
56 | $status = -1;
|
---|
57 |
|
---|
58 | if ($isLocked == 0) {
|
---|
59 | $aryParams = array(
|
---|
60 | 'EWalletID' => $this->config->item('EWalletID'),
|
---|
61 | 'CardSerial' => $cardSerial,
|
---|
62 | 'PinCard' => $pinCard,
|
---|
63 | );
|
---|
64 |
|
---|
65 | $aryResult = array();
|
---|
66 |
|
---|
67 | $chargCard = $this->services_model->cardPaidProcess($aryParams, $aryResult);
|
---|
68 | $status = $chargCard;
|
---|
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);
|
---|
72 |
|
---|
73 | $paidType = 2;
|
---|
74 | $amount = $aryResult['TransactionAmount'];
|
---|
75 | $cardValue = $amount;
|
---|
76 | $paidTime = date('Y-m-d H:i:s');
|
---|
77 | $user['acc_balanced'] = $user['acc_balanced'] + $amount;
|
---|
78 | $user['updated_time'] = $updatedTime;
|
---|
79 | if ($amount > 0){
|
---|
80 | $updateData = array('acc_balanced' => $user['acc_balanced'], 'updated_time' => $user['updated_time'] );
|
---|
81 | $updated = $this->objUserModel->updateUser($userID, $updateData);
|
---|
82 | error_log ('UPDATE ACCOUNT SUCCESS: '.($updated ? 'SUCCESS':'NOT SUCCESS')."\n", 3, $trackingFile);
|
---|
83 | }
|
---|
84 |
|
---|
85 | $result['success'] = $chargCard;
|
---|
86 |
|
---|
87 | if ($chargCard == _SBG_CARD_PAY_SUCCESS){
|
---|
88 | //$result['username'] = $user['cellphone'];
|
---|
89 | $result['acc_balanced'] = $user['acc_balanced'];
|
---|
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'));
|
---|
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);
|
---|
95 | releaseLockFile($lockFilePreFix, $lockFilePath);
|
---|
96 | }
|
---|
97 | else {
|
---|
98 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, FALSE);
|
---|
99 | $errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg;
|
---|
100 | }
|
---|
101 | }else if ($isLocked == 1) {
|
---|
102 | $errMsg = $lockedMsg;
|
---|
103 | $result['success'] = _SBG_CARD_PAY_FAIL;
|
---|
104 | $status = 0;
|
---|
105 | }
|
---|
106 |
|
---|
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 |
|
---|
110 | $result['us_id'] = $userID;
|
---|
111 | $result['UPDATED_DATA'] = $user;
|
---|
112 | $result['errMsg'] = $errMsg;
|
---|
113 | echo json_encode($result);
|
---|
114 | error_log ('RETURN JSON: '.json_encode($result)."\n", 3, $trackingFile);
|
---|
115 | error_log ('--FINISH CARD CHARGE--'."\n", 3, $trackingFile);
|
---|
116 | }
|
---|
117 | } |
---|