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 | $userID = $this->uri->segment(4);
|
---|
18 | $input = $this->input->post();
|
---|
19 | $cardSerial = $input['card_serial'];
|
---|
20 | $pinCard = $input['pin_card'];
|
---|
21 | $isLocked = 0;
|
---|
22 |
|
---|
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 |
|
---|
29 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, TRUE);
|
---|
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;
|
---|
36 |
|
---|
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');
|
---|
42 | $errMsg = '';
|
---|
43 | $cardValue = 0;
|
---|
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 | //$aryResult['TransactionAmount'] = 10000;
|
---|
53 | $chargCard = $this->services_model->cardPaidProcess($aryParams, $aryResult);
|
---|
54 | //$chargCard = _SBG_CARD_PAY_SUCCESS;
|
---|
55 | $status = $chargCard;
|
---|
56 | $paidType = 2;
|
---|
57 | $amount = $aryResult['TransactionAmount'];
|
---|
58 | $cardValue = $amount;
|
---|
59 | $paidTime = date('Y-m-d H:i:s');
|
---|
60 | $user['acc_balanced'] = $user['acc_balanced'] + $amount;
|
---|
61 | $user['updated_time'] = date('Y-m-d H:i:s');
|
---|
62 | if ($amount > 0){
|
---|
63 | $updateData = array('acc_balanced' => $user['acc_balanced'], 'updated_time' => $user['updated_time'] );
|
---|
64 | $updated = $this->objUserModel->updateUser($userID, $updateData);
|
---|
65 | }
|
---|
66 |
|
---|
67 | $result['success'] = $chargCard;
|
---|
68 |
|
---|
69 | if ($chargCard == _SBG_CARD_PAY_SUCCESS){
|
---|
70 | //$result['username'] = $user['cellphone'];
|
---|
71 | $result['acc_balanced'] = $user['acc_balanced'];
|
---|
72 | //$result['amount'] = $amount;
|
---|
73 | $aryPatterns = array('/:amount:/', '/:username:/', '/:acc_balanced:/');
|
---|
74 | $result['message'] = preg_replace($aryPatterns, array($amount, $user['cellphone'], $user['acc_balanced']), lang('_SBG_CHARGING_FROM_CARD_SUCCESS_MSG'));
|
---|
75 | $this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
|
---|
76 | releaseLockFile($lockFilePreFix, $lockFilePath);
|
---|
77 | }
|
---|
78 | else {
|
---|
79 | $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, FALSE);
|
---|
80 | $errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg;
|
---|
81 | $status = 0;
|
---|
82 | }
|
---|
83 | }else if ($isLocked == 1) {
|
---|
84 | $errMsg = $lockedMsg;
|
---|
85 | $result['success'] = _SBG_CARD_PAY_FAIL;
|
---|
86 | $status = -1;
|
---|
87 | }
|
---|
88 |
|
---|
89 | $this->objUserModel->insertCardlog($user['cellphone'],$userID, $status, $pinCard, $cardSerial, $cardValue, $user['updated_time']);
|
---|
90 |
|
---|
91 | $result['us_id'] = $userID;
|
---|
92 | $result['UPDATED_DATA'] = $user;
|
---|
93 | $result['errMsg'] = $errMsg;
|
---|
94 | echo json_encode($result);
|
---|
95 | }
|
---|
96 | } |
---|