Index: pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php	(revision 611)
+++ pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php	(revision 620)
@@ -6,4 +6,7 @@
 	{
 		parent::__construct();
+		$this->load->model('frontend/user_model', 'objUserModel');
+		$this->load->helper('lockfile');
+		$this->load->model('services_model');
 	}
 	
@@ -14,36 +17,62 @@
 		$cardSerial = $input['card_serial'];
 		$pinCard = $input['pin_card'];
-		$aryParams = array(
-			'EWalletID' => $this->config->item('EWalletID'),
-			'CardSerial' => $cardSerial,
-			'PinCard' => $pinCard,
-		);
-		
-		$this->load->model('services_model');
-		$aryResult = array();
-		$data = $this->services_model->cardPaidProcess($aryParams,  $aryResult);
-		$this->load->model('frontend/user_model', 'objUserModel');
-		$paidType = 2;
-		$amount = $aryResult['TransactionAmount'];
-		$paidTime = date('Y-m-d H:i:s');
+		$isLocked = 0;
 		
 		$user = $this->objUserModel->get_user_by_id($userID);
-		$user['acc_balanced'] = $user['acc_balanced'] + $amount;
-		$user['updated_time'] = date('Y-m-d H:i:s');
-		if ($amount>0){
-			$this->objUserModel->updateUser($userID, $user);
+		$lockFilePreFix = $user['cellphone'];
+		$lockFilePath = $this->config->item('topup_lock_path');
+		$maxReach = $this->config->item('topup_lock_max_reach');
+		$timeToUnlock = $this->config->item('topup_unlock_minute');
+
+		$isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, 1);
+		$chargCard = _SBG_CARD_PAY_SUCCESS;
+		$result = array();
+		$result['maxReach'] = $maxReach;
+		$result['timeToUnlock'] = $timeToUnlock;
+		$result['isLocked'] = $isLocked;
+		$result['tmp'] = $maxReach;
+		
+		$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!';
+		$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!';
+		$errMsg = '';
+		
+		if ($isLocked == 0) {
+			$aryParams = array(
+					'EWalletID' => $this->config->item('EWalletID'),
+					'CardSerial' => $cardSerial,
+					'PinCard' => $pinCard,
+			);
+			
+			$aryResult = array();
+			$chargCard = $this->services_model->cardPaidProcess($aryParams,  $aryResult);
+			
+			$paidType = 2;
+			$amount = $aryResult['TransactionAmount'];
+			$paidTime = date('Y-m-d H:i:s');
+			$user['acc_balanced'] = $user['acc_balanced'] + $amount;
+			$user['updated_time'] = date('Y-m-d H:i:s');
+			if ($amount>0){
+				$this->objUserModel->updateUser($userID, $user);
+			}
+			
+			$result['success'] = $chargCard;
+			
+			if ($chargCard == _SBG_CARD_PAY_SUCCESS){
+				$result['username'] = $user['cellphone'];
+				$result['acc_balanced'] = $user['acc_balanced'];
+				$result['amount'] = $amount;
+				$this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
+				releaseLockFile($lockFilePreFix, $lockFilePath);
+			}
+			else {
+				$isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath);
+				$errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg; 
+			}
+		}else if ($isLocked == 1) {
+			$errMsg = $lockedMsg; 
+			$result['success'] = _SBG_CARD_PAY_FAIL;
 		}
 		
-		$result = array();
-		if ($data == 1){
-			$result['success'] = 1;
-			$result['username'] = $user['cellphone'];
-			$result['acc_balanced'] = $user['acc_balanced'];
-			$result['amount'] = $amount;
-			$this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
-		}else
-		{
-			$result['success'] = 0;
-		}
+		$result['errMsg'] = $errMsg;
 		echo json_encode($result);
 	}
