Changeset 884 for pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
- Timestamp:
- Apr 7, 2015 2:17:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
r883 r884 26 26 if ( ! defined('_SBG_CHARGING_NUMBER_NOT_REGISTED')) define('_SBG_CHARGING_NUMBER_NOT_REGISTED', 501); 27 27 if ( ! defined('_SBG_CHARGING_MAX_VALUE')) define('_SBG_CHARGING_MAX_VALUE', 50000); 28 if ( ! defined('_SBG_CHARGING_MIN_VALUE')) define('_SBG_CHARGING_MIN_VALUE', 5000); 28 29 29 30 … … 40 41 if ( ! defined('_SBG_GET_COLLABORATOR_FAIL')) define('_SBG_GET_COLLABORATOR_FAIL', -1); 41 42 42 Class Services_model extends CI_Model 43 Class Services_model extends CI_Model 43 44 { 44 45 private $_arySmsMO = array( … … 52 53 _SBG_MO_SUPPOR_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HD)$/'), 53 54 _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HUY)$/') 54 ); 55 55 ); 56 56 57 public function __construct(){ 57 58 parent::__construct(); … … 59 60 $this->lang->load('messages', 'message'); 60 61 } 61 62 62 63 /** 63 64 * messageAnalys 64 * 65 * 65 66 * @todo Analysis content of incoming message 66 * 67 * 67 68 * @param String $message - coming SMS 68 69 * @return multitype:Ambigous <string, multitype> multitype:multitype … … 70 71 public function messageAnalys ($message) 71 72 { 72 $aryMatched = array(); 73 $aryMatched = array(); 73 74 $aryContent = array(); 74 75 $result = FALSE; 75 76 76 77 foreach ($this->_arySmsMO as $case => $pattern) 77 78 { … … 82 83 } 83 84 } 84 85 85 86 $case = (bool)$result ? $case:_SBG_MO_SYNTAX_ERR; 86 87 87 88 foreach($aryMatched as $k => $val) { 88 if ($k > 1) $aryContent[] = $val; 89 } 90 89 if ($k > 1) $aryContent[] = $val; 90 } 91 91 92 return array('case' => $case, 'content' => $aryContent); 92 93 } 93 94 94 95 /** 95 96 * processMORequest 96 * 97 * 97 98 * @todo process action analysed from messageAnalys 98 * 99 * 99 100 * @param unknown $sentNumber 100 101 * @param unknown $message 101 102 * @return string 102 103 */ 103 public function processMORequest ($sentNumber, $message, &$mtBody = null) 104 public function processMORequest ($sentNumber, $message, &$mtBody = null) 104 105 { 105 106 $debugMsg = $message."\n"; 106 107 107 108 $sentNumber = $this->formatPhoneNumber($sentNumber); 108 109 109 110 $smsReturn = ''; 110 $aryMOAnalys = $this->messageAnalys($message); 111 $aryMOAnalys = $this->messageAnalys($message); 111 112 $case = $aryMOAnalys['case']; 112 113 $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null; 113 114 $this->load->model('frontend/user_model', 'objUserModel'); 114 115 $debugMsg .= $case; 115 116 116 117 switch ($case) { 117 118 case _SBG_MO_REGISTER: … … 123 124 } 124 125 } 125 126 $userName = isset($aryContents[0]) ? $this->formatPhoneNumber($aryContents[0]) : $sentNumber; 126 127 $userName = isset($aryContents[0]) ? $this->formatPhoneNumber($aryContents[0]) : $sentNumber; 127 128 $collaborator = isset($aryContents[0]) ? $sentNumber:null; 128 129 $collaboratorMsg = ''; 129 130 130 131 $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg); 131 132 132 133 if ($case == _SBG_MO_REGISTER_FOR) { 133 134 $smsReturn = $collaboratorMsg; … … 137 138 $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $mtBody); 138 139 } 139 140 140 141 } 141 142 else { … … 149 150 break; 150 151 } 151 152 152 153 $oldPhoneNumber = $this->formatPhoneNumber($aryContents[0]); 153 154 $password = $aryContents[1]; 154 155 $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password); 155 156 156 157 $arySMS = explode('|', $smsReturn); 157 158 $changeResult = (int)$arySMS[0]; 158 159 159 160 $aryPatterns = array('/:sentNumber:/'); 160 161 $sms = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_USER_OLD_PHONENUM_CHANGE_SUCCESS_MSG')); … … 168 169 $p_code = $aryContents[0]; 169 170 $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code, $packageData); 170 171 171 172 $arySmsReturn = explode('|', $smsReturn); 172 173 $result = $arySmsReturn[0]; … … 179 180 for ($i = 1; $i <= $count; $i++) { 180 181 $value = $amount > _SBG_CHARGING_MAX_VALUE ? _SBG_CHARGING_MAX_VALUE : $amount; 181 $amount -= $value; 182 $amount -= $value; 182 183 $result = $this->chargeRootAccountProcess($sentNumber, $value, $sentNumber.' paid for SBG'); 183 } 184 } 184 185 185 186 if ($result == _SBG_CHARGING_SUCCESS) { … … 199 200 case _SBG_MO_PAY_TO_ACCOUNT_FOR: 200 201 error_log(date('Y-m-d H:i:s').' -- DATA: '. var_export($aryContents, TRUE).' -- CASE: '. $case . "\n", 3, '/srv/www/sbg/log/pay.log'); 202 201 203 $userName = isset($aryContents[1]) ? $this->formatPhoneNumber($aryContents[1]) : $sentNumber; 202 204 if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR && !preg_match('/^(09\d{8}|01\d{9})$/', $userName)) { … … 204 206 break; 205 207 } 206 208 207 209 $amount = $aryContents[0]; 208 210 if (!preg_match('/^[0-9]{3,}$/', $amount)) { … … 210 212 break; 211 213 } 212 214 215 if ((int)$amount < _SBG_CHARGING_MIN_VALUE) { 216 $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_AMOUNT_LESS_THAN_MIN_VALUE_MSG'); 217 break; 218 } 219 213 220 $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG'); 214 221 215 222 if ($result == _SBG_CHARGING_SUCCESS) { 216 223 $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount); … … 228 235 } 229 236 else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) { 230 //$aryPatterns = array ('/:amount:/');231 237 $aryPatterns = array ('/:sentNumber:/'); 232 238 $smsReturn = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_MSG')); 233 /*234 if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {235 $aryPatterns = array ('/:amount:/', '/:username:/');236 $smsReturn = preg_replace($aryPatterns, array($amount, $userName), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_FOR_MSG'));237 }*/238 239 $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn; 239 240 } 240 241 else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) { 241 $aryPatterns = array ('/:sendid:/');242 /* $aryPatterns = array ('/:sendid:/'); 242 243 $smsReturn = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_CHARGING_FAIL_MORETHAN_LIMIT_MSG')); 243 $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn; 244 $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn; */ 245 246 247 248 244 249 }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED || $result == _SBG_CHARGING_NUMBER_NOT_AVAILABLE) { 245 250 $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_NOT_VIETTEL_MSG'); 246 } 251 } 247 252 else { 248 253 $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_MSG'); 249 254 } 250 255 break; 256 251 257 case _SBG_MO_SUPPOR_SERVICE: 252 //$smsReturn = '1|'.lang('_SBG_MO_SUPPORT_MSG');253 258 if ($this->isViettel($sentNumber)){ 254 259 $smsReturn = '1|'.lang('_SBG_MO_SUPPORT_VIETTEL_MSG'); … … 257 262 } 258 263 break; 264 259 265 case _SBG_MO_UNSUBSCRIBE_SERVICE: 260 266 case _SBG_MO_SYNTAX_ERR: … … 263 269 break; 264 270 } 265 271 266 272 $aryTmp = explode('|', $smsReturn); 267 273 $mtBody = $aryTmp[1] . "\n" . $mtBody; 268 274 269 275 return $smsReturn.'|'.$case; 270 276 } 271 272 277 278 273 279 /** 274 280 * cardPaidProcess 275 * 281 * 276 282 * @todo Call Topup webservice to check and lock prepaid-card 277 283 * @param Array $aryCardInfo … … 279 285 * @return string 280 286 */ 281 public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array()) 287 public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array()) 282 288 { 283 289 $url = $this->config->item('topup_service_url'); 284 290 $action = 'http://tempuri.org/ITopupService/TopUp'; 285 291 $xml = $this->load->view('topup', $aryCardInfo, true); 286 292 287 293 $client = new nusoap_client($url); 288 294 $client->useHTTPPersistentConnection(); 289 295 $client->soap_defencoding = 'UTF-8'; 290 296 $client->operation = $action; 291 297 292 298 $result = $client->send($xml, $action); 293 299 294 300 if ($client->fault) { 295 301 return _SBG_CARD_PAY_FAIL; 296 302 } 297 303 298 304 $keys = array_keys($result); 299 305 300 306 $aryTopupResult = $result[$keys[0]]; 301 307 … … 308 314 return _SBG_CARD_PAY_FAIL; 309 315 } 310 316 311 317 return _SBG_CARD_PAY_SUCCESS; 312 318 } 313 319 314 320 /** 315 321 * chargeRootAccountProcess 316 * 322 * 317 323 * @todo Call charging webservice to charged fee from phone root account 318 324 * @param String $sentID … … 321 327 * @return string|number 322 328 */ 323 public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '') 329 public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '') 324 330 { 325 331 $url = $this->config->item('charging_service_url'); 326 332 $username = $this->config->item('charging_username'); 327 333 $password = $this->config->item('charging_password'); 328 $action = 'http://tempuri.org/processCharging'; 329 334 $action = 'http://tempuri.org/processCharging'; 335 330 336 $aryParams = array( 331 337 'user' => $username, … … 345 351 return _SBG_CHARGING_FAIL; 346 352 } 347 348 $aryErrs = array ( _SBG_CHARGING_FAIL_NOT_ENOUGH, 349 _SBG_CHARGING_FAIL_NOT_VIETTEL, 353 354 $aryErrs = array ( _SBG_CHARGING_FAIL_NOT_ENOUGH, 355 _SBG_CHARGING_FAIL_NOT_VIETTEL, 350 356 _SBG_CHARGING_FAIL_MORETHAN_LIMIT, 351 357 _SBG_CHARGING_NUMBER_NOT_EXISTED, … … 354 360 _SBG_CHARGING_GENERAL_ERROR, 355 361 _SBG_CHARGING_NUMBER_NOT_REGISTED); 356 357 if (in_array((int)$result['processChargingResult'], $aryErrs)) 358 return (int)$result['processChargingResult']; 359 362 363 if (in_array((int)$result['processChargingResult'], $aryErrs)) 364 return (int)$result['processChargingResult']; 365 360 366 return _SBG_CHARGING_SUCCESS; 361 367 } 362 368 363 369 /** 364 370 * sendMT 365 * 371 * 366 372 * @todo Calling MT webservice to send a SMS to a phone number 367 373 * @param String $receiverID … … 372 378 { 373 379 $aryMatch = array(); 374 380 375 381 if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) { 376 382 $receiverID = '84'. $aryMatch[2]; 377 383 } 378 384 379 385 $username = $this->config->item('mt_username'); 380 386 $password = $this->config->item('mt_password'); 381 387 $action = 'http://tempuri.org/InsertMT'; 382 388 383 389 $aryParams = array( 384 390 'User' => $username, … … 393 399 'Info' => $message 394 400 ); 395 401 396 402 $xml = $this->load->view('services/mt', $aryParams, true); 397 403 $url = $this->config->item('mt_service_url'); … … 401 407 $client->operation = $action; 402 408 $result = $client->send($xml, $action); 403 409 404 410 if ($client->fault || (int)$result['InsertMTResult'] != 1) { 405 411 return _SBG_SEND_MT_FAIL; 406 412 } 407 413 408 414 return _SBG_SEND_MT_SUCCESS; 409 415 } 410 416 411 417 public function getCollaborator ($type = 2, $page = 10, $displaypage = 1) { 412 418 $action = 'http://tempuri.org/InsertMT'; … … 423 429 'displaypage' => $displaypage 424 430 ); 431 425 432 $xml = $this->load->view('bscc', $aryParams, true); 426 433 427 434 $client = new nusoap_client($url); 428 435 $client->useHTTPPersistentConnection(); 429 436 $client->soap_defencoding = 'UTF-8'; 430 437 $client->decode_utf8 = false; 431 438 432 439 $client->operation = $action; 433 440 $result = $client->send($xml, $action); … … 435 442 return _SBG_GET_COLLABORATOR_FAIL; 436 443 } 437 444 438 445 return $result['Result']['original']; 439 446 } 440 447 441 448 /** 442 449 * formatPhoneNumber 443 * 450 * 444 451 * @todo format phone number to prefix 0 or 84 445 452 * @param String $phoneNumber … … 465 472 $result = '0'. $phoneNumber; 466 473 } 467 474 468 475 return $result; 469 476 } 470 471 477 478 472 479 public function syncCollaborator($data){ 473 480 if ($data){ 474 $sql = $this->db->insert_string('tblcollaborator', $data) . ' ON DUPLICATE KEY UPDATE address = "'.$data['address'].'", 475 code = "'.$data['code'].'", 476 district = "'.$data['district'].'", 477 email = "'.$data['email'].'", 481 $sql = $this->db->insert_string('tblcollaborator', $data) . ' ON DUPLICATE KEY UPDATE address = "'.$data['address'].'", 482 code = "'.$data['code'].'", 483 district = "'.$data['district'].'", 484 email = "'.$data['email'].'", 478 485 full_name = "'.$data['full_name'].'", 479 486 passwd = "'.$data['passwd'].'", 480 cellphone = "'.$data['cellphone'].'", 481 precinct = "'.$data['precinct'].'", 487 cellphone = "'.$data['cellphone'].'", 488 precinct = "'.$data['precinct'].'", 482 489 province = "'.$data['province'].'", 483 490 created_time = "'.$data['created_time'].'", … … 499 506 } 500 507 } 501 508 502 509 public function deleteCollaborator($id){ 503 510 $sql = "DELETE FROM tblcollaborator WHERE id = ". $id; … … 511 518 } 512 519 } 513 520 514 521 public function getAllCollaboratorID(){ 515 522 $sql = "Select id from tblcollaborator"; … … 522 529 } 523 530 } 524 531 525 532 public function isViettel($number) { 526 533 $prefixViettel = array (
Note: See TracChangeset
for help on using the changeset viewer.