source: pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php @ 642

Last change on this file since 642 was 636, checked in by namnd, 10 years ago
File size: 3.3 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class 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               
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){
66                                //$result['username'] = $user['cellphone'];
67                                $result['acc_balanced'] = $user['acc_balanced'];
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'));
71                                $this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
72                                releaseLockFile($lockFilePreFix, $lockFilePath);
73                        }
74                        else {
75                                $isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, FALSE);
76                                $errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg;
77                        }
78                }else if ($isLocked == 1) {
79                        $errMsg = $lockedMsg;
80                        $result['success'] = _SBG_CARD_PAY_FAIL;
81                }
82               
83                $result['errMsg'] = $errMsg;
84                echo json_encode($result);
85        }
86}
Note: See TracBrowser for help on using the repository browser.