1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | if ( ! defined('_SBG_MO_REGISTER')) define('_SBG_MO_REGISTER', 'SUBSCR');
|
---|
4 | if ( ! defined('_SBG_MO_REGISTER_FOR')) define('_SBG_MO_REGISTER_FOR', 'SUBSCR_FOR');
|
---|
5 | if ( ! defined('_SBG_MO_PHONENUM_CHANGE')) define('_SBG_MO_PHONENUM_CHANGE', 'PHONE_CHANGE');
|
---|
6 | if ( ! defined('_SBG_MO_PASSWORD_RECOVERY')) define('_SBG_MO_PASSWORD_RECOVERY', 'PWD_RECOVER');
|
---|
7 | if ( ! defined('_SBG_MO_VIP_REGISTER')) define('_SBG_MO_VIP_REGISTER', 'REG_VIP');
|
---|
8 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT')) define('_SBG_MO_PAY_TO_ACCOUNT', 'PAY');
|
---|
9 | if ( ! defined('_SBG_MO_PAY_TO_ACCOUNT_FOR')) define('_SBG_MO_PAY_TO_ACCOUNT_FOR', 'PAY_FOR');
|
---|
10 | if ( ! defined('_SBG_MO_UNSUBSCRIBE_SERVICE')) define('_SBG_MO_UNSUBSCRIBE_SERVICE', 'UNSUBSCR');
|
---|
11 | if ( ! defined('_SBG_MO_SUPPOR_SERVICE')) define('_SBG_MO_SUPPOR_SERVICE', 'SUPPORT');
|
---|
12 | if ( ! defined('_SBG_MO_SYNTAX_ERR')) define('_SBG_MO_SYNTAX_ERR', 'SYNTAX_ERR');
|
---|
13 |
|
---|
14 | if ( ! defined('_SBG_CARD_PAY_FAIL')) define('_SBG_CARD_PAY_FAIL', -1);
|
---|
15 | if ( ! defined('_SBG_CARD_PAY_SUCCESS')) define('_SBG_CARD_PAY_SUCCESS', 1);
|
---|
16 |
|
---|
17 | if ( ! defined('_SBG_CHARGING_FAIL')) define('_SBG_CHARGING_FAIL', -1);
|
---|
18 | if ( ! defined('_SBG_CHARGING_SUCCESS')) define('_SBG_CHARGING_SUCCESS', 1);
|
---|
19 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_ENOUGH')) define('_SBG_CHARGING_FAIL_NOT_ENOUGH', 401);
|
---|
20 | if ( ! defined('_SBG_CHARGING_FAIL_NOT_VIETTEL')) define('_SBG_CHARGING_FAIL_NOT_VIETTEL', 402);
|
---|
21 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_EXISTED')) define('_SBG_CHARGING_NUMBER_NOT_EXISTED', 403);
|
---|
22 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_AVAILABLE')) define('_SBG_CHARGING_NUMBER_NOT_AVAILABLE', 404);
|
---|
23 | if ( ! defined('_SBG_CHARGING_NUMBER_CHANGED_OWNER')) define('_SBG_CHARGING_NUMBER_CHANGED_OWNER', 405);
|
---|
24 | if ( ! defined('_SBG_CHARGING_FAIL_MORETHAN_LIMIT')) define('_SBG_CHARGING_FAIL_MORETHAN_LIMIT', 406);
|
---|
25 | if ( ! defined('_SBG_CHARGING_GENERAL_ERROR')) define('_SBG_CHARGING_GENERAL_ERROR', 440);
|
---|
26 | if ( ! defined('_SBG_CHARGING_NUMBER_NOT_REGISTED')) define('_SBG_CHARGING_NUMBER_NOT_REGISTED', 501);
|
---|
27 | if ( ! defined('_SBG_CHARGING_MAX_VALUE')) define('_SBG_CHARGING_MAX_VALUE', 50000);
|
---|
28 |
|
---|
29 |
|
---|
30 | if ( ! defined('_SBG_SEND_MT_FAIL')) define('_SBG_SEND_MT_FAIL', -1);
|
---|
31 | if ( ! defined('_SBG_SEND_MT_SUCCESS')) define('_SBG_SEND_MT_SUCCESS', 1);
|
---|
32 | if ( ! defined('_SBG_MT_SEND_NUMBER')) define('_SBG_MT_SEND_NUMBER', '841662860000');
|
---|
33 | if ( ! defined('_SBG_MT_CP_CODE')) define('_SBG_MT_CP_CODE', '601');
|
---|
34 |
|
---|
35 | if ( ! defined('_SBG_SERVICE_COMMAND_CODE')) define('_SBG_SERVICE_COMMAND_CODE', 'SBG');
|
---|
36 | if ( ! defined('_SBG_SERVICE_SERVICEID')) define('_SBG_SERVICE_SERVICEID', '8062');
|
---|
37 |
|
---|
38 | if ( ! defined('_SBG_MO_PROCCESS_ERR')) define('_SBG_MO_PROCCESS_ERR', 0);
|
---|
39 |
|
---|
40 | if ( ! defined('_SBG_GET_COLLABORATOR_FAIL')) define('_SBG_GET_COLLABORATOR_FAIL', -1);
|
---|
41 |
|
---|
42 | Class Services_model extends CI_Model
|
---|
43 | {
|
---|
44 | private $_arySmsMO = array(
|
---|
45 | _SBG_MO_REGISTER => array('pattern' => '/^(SBG)([[:blank:]])(DK)$/'),
|
---|
46 | _SBG_MO_REGISTER_FOR => array('pattern' => '/^(SBG)([[:blank:]])(DK)([[:blank:]])([0-9]{10,11})$/'),
|
---|
47 | //_SBG_MO_PHONENUM_CHANGE => array('pattern' => '/^(SBG)([[:blank:]])(DDT)([[:blank:]])([0-9]{10,11})([[:blank:]])([a-zA-Z0-9]{1,})$/'),
|
---|
48 | _SBG_MO_PASSWORD_RECOVERY => array('pattern' => '/^(SBG)([[:blank:]])(MK)$/'),
|
---|
49 | _SBG_MO_VIP_REGISTER => array('pattern' => '/^(SBG)([[:blank:]])(VIP)([[:blank:]])([a-zA-Z0-9]{1,})$/'),
|
---|
50 | _SBG_MO_PAY_TO_ACCOUNT => array('pattern' => '/^(SBG)([[:blank:]])(NAP)([[:blank:]])([0-9]{3,})$/'),
|
---|
51 | _SBG_MO_PAY_TO_ACCOUNT_FOR => array('pattern' => '/^(SBG)([[:blank:]])(NAP)([[:blank:]])([0-9]{3,})([[:blank:]])([0-9]{10,11})$/'),
|
---|
52 | _SBG_MO_SUPPOR_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HD)$/'),
|
---|
53 | _SBG_MO_UNSUBSCRIBE_SERVICE => array('pattern' => '/^(SBG)([[:blank:]])(HUY)$/')
|
---|
54 | );
|
---|
55 |
|
---|
56 | public function __construct(){
|
---|
57 | parent::__construct();
|
---|
58 | $this->load->helper('language');
|
---|
59 | $this->lang->load('messages', 'message');
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * messageAnalys
|
---|
64 | *
|
---|
65 | * @todo Analysis content of incoming message
|
---|
66 | *
|
---|
67 | * @param String $message - coming SMS
|
---|
68 | * @return multitype:Ambigous <string, multitype> multitype:multitype
|
---|
69 | */
|
---|
70 | public function messageAnalys ($message)
|
---|
71 | {
|
---|
72 | $aryMatched = array();
|
---|
73 | $aryContent = array();
|
---|
74 | $result = FALSE;
|
---|
75 |
|
---|
76 | foreach ($this->_arySmsMO as $case => $pattern)
|
---|
77 | {
|
---|
78 | $result = preg_match($pattern['pattern'], strtoupper(trim($message)));
|
---|
79 | if ((bool)$result) {
|
---|
80 | $aryMatched = explode(' ', trim($message));
|
---|
81 | break;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | $case = (bool)$result ? $case:_SBG_MO_SYNTAX_ERR;
|
---|
86 |
|
---|
87 | foreach($aryMatched as $k => $val) {
|
---|
88 | if ($k > 1) $aryContent[] = $val;
|
---|
89 | }
|
---|
90 |
|
---|
91 | return array('case' => $case, 'content' => $aryContent);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * processMORequest
|
---|
96 | *
|
---|
97 | * @todo process action analysed from messageAnalys
|
---|
98 | *
|
---|
99 | * @param unknown $sentNumber
|
---|
100 | * @param unknown $message
|
---|
101 | * @return string
|
---|
102 | */
|
---|
103 | public function processMORequest ($sentNumber, $message)
|
---|
104 | {
|
---|
105 | $debugMsg = $message."\n";
|
---|
106 |
|
---|
107 | $sentNumber = $this->formatPhoneNumber($sentNumber);
|
---|
108 |
|
---|
109 | $smsReturn = '';
|
---|
110 | $aryMOAnalys = $this->messageAnalys($message);
|
---|
111 | $case = $aryMOAnalys['case'];
|
---|
112 | $aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
|
---|
113 | $this->load->model('frontend/user_model', 'objUserModel');
|
---|
114 | $debugMsg .= $case;
|
---|
115 |
|
---|
116 | switch ($case) {
|
---|
117 | case _SBG_MO_REGISTER:
|
---|
118 | case _SBG_MO_REGISTER_FOR:
|
---|
119 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
120 | if (!preg_match('/^([0-9]{10,11}$)$/', $aryContents[0])) {
|
---|
121 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
122 | break;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | $userName = isset($aryContents[0]) ? $this->formatPhoneNumber($aryContents[0]) : $sentNumber;
|
---|
127 | $collaborator = isset($aryContents[0]) ? $sentNumber:null;
|
---|
128 | $collaboratorMsg = '';
|
---|
129 |
|
---|
130 | $sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
|
---|
131 |
|
---|
132 | if ($case == _SBG_MO_REGISTER_FOR) {
|
---|
133 | $smsReturn = $collaboratorMsg;
|
---|
134 | $arySMS = explode ('|', $sms);
|
---|
135 | if ((int)$arySMS[0] == 1 )
|
---|
136 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | $smsReturn = $sms;
|
---|
140 | }
|
---|
141 |
|
---|
142 | break;
|
---|
143 | case _SBG_MO_PHONENUM_CHANGE:
|
---|
144 | if (!preg_match('/^(09\d{8}|01\d{9})$/', $aryContents[0])) {
|
---|
145 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
146 | break;
|
---|
147 | }
|
---|
148 |
|
---|
149 | $oldPhoneNumber = $this->formatPhoneNumber($aryContents[0]);
|
---|
150 | $password = $aryContents[1];
|
---|
151 | $smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
|
---|
152 |
|
---|
153 | $arySMS = explode('|', $smsReturn);
|
---|
154 | $changeResult = (int)$arySMS[0];
|
---|
155 |
|
---|
156 | $aryPatterns = array('/:sentNumber:/');
|
---|
157 | $sms = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_USER_OLD_PHONENUM_CHANGE_SUCCESS_MSG'));
|
---|
158 | $sendMT = $changeResult == 1 ? $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms) : '';
|
---|
159 | break;
|
---|
160 | case _SBG_MO_PASSWORD_RECOVERY:
|
---|
161 | $smsReturn = $this->objUserModel->changePassword($sentNumber);
|
---|
162 | break;
|
---|
163 | case _SBG_MO_VIP_REGISTER:
|
---|
164 | $packageData = array();
|
---|
165 | $p_code = $aryContents[0];
|
---|
166 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code, $packageData);
|
---|
167 |
|
---|
168 | $arySmsReturn = explode('|', $smsReturn);
|
---|
169 | $result = $arySmsReturn[0];
|
---|
170 |
|
---|
171 | if (trim($arySmsReturn[1]) == trim(lang('_SBG_MO_USER_REGISTER_VIP_FAIL_NOT_ENOUGH_MSG'))) {
|
---|
172 |
|
---|
173 | $amount = $packageData ['p_price'];
|
---|
174 | $count = $amount > $maxCharging ? ceil($amount/ _SBG_CHARGING_MAX_VALUE) : 1;
|
---|
175 | $value = 0;
|
---|
176 | for ($i = 1; $i <= $count; $i++) {
|
---|
177 | $value = $amount > _SBG_CHARGING_MAX_VALUE ? _SBG_CHARGING_MAX_VALUE : $amount;
|
---|
178 | $amount -= $value;
|
---|
179 | $result = $this->chargeRootAccountProcess($sentNumber, $value, $sentNumber.' paid for SBG');
|
---|
180 | }
|
---|
181 |
|
---|
182 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
183 | $amount = $packageData ['p_price'];
|
---|
184 | $this->objUserModel->rechargeAccount($sentNumber, $amount);
|
---|
185 | $smsReturn = $this->objUserModel->registerVip($sentNumber, $p_code, $packageData);
|
---|
186 | $paidTime = date('Y-m-d H:i:s');
|
---|
187 | $this->objUserModel->insertPaidlog($sentNumber, $sentNumber, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
188 | $result = 1;
|
---|
189 | }
|
---|
190 | }
|
---|
191 |
|
---|
192 | if ((int)$result == 1) $this->objUserModel->insertRegisterVipLog($sentNumber, $p_code, true);
|
---|
193 | break;
|
---|
194 |
|
---|
195 | case _SBG_MO_PAY_TO_ACCOUNT:
|
---|
196 | case _SBG_MO_PAY_TO_ACCOUNT_FOR:
|
---|
197 | error_log(date('Y-m-d H:i:s').' -- DATA: '. var_export($aryContents, TRUE).' -- CASE: '. $case . "\n", 3, '/srv/www/sbg/log/pay.log');
|
---|
198 | $userName = isset($aryContents[1]) ? $this->formatPhoneNumber($aryContents[1]) : $sentNumber;
|
---|
199 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR && !preg_match('/^(09\d{8}|01\d{9})$/', $userName)) {
|
---|
200 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_PHONENUM_WRONG_FORMAT_MSG');
|
---|
201 | break;
|
---|
202 | }
|
---|
203 |
|
---|
204 | $amount = $aryContents[0];
|
---|
205 | if (!preg_match('/^[0-9]{3,}$/', $amount)) {
|
---|
206 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_AMOUNT_WRONG_FORMAT_MSG');
|
---|
207 | break;
|
---|
208 | }
|
---|
209 |
|
---|
210 | $result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
|
---|
211 |
|
---|
212 | if ($result == _SBG_CHARGING_SUCCESS) {
|
---|
213 | $smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
|
---|
214 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
215 | $arySmsReturn = explode ('|', $smsReturn);
|
---|
216 | $aryPatterns = array('/:amount:/', '/:sentNumber:/');
|
---|
217 | $smsMT = preg_replace($aryPatterns, array($amount, $sentNumber), lang('_SBG_MO_PAY_TO_ACCOUNT_FOR_MSG'));
|
---|
218 | $sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
|
---|
219 | $smsReturn = $arySmsReturn[0].'|'.preg_replace(array('/:amount:/','/:username:/'), array($amount, $userName), lang('_SBG_MO_PAY_TO_ACCOUNT_FOR_OTHER_SUCCESS_MSG'));
|
---|
220 | }
|
---|
221 | //write to paid log
|
---|
222 | $paidTime = date('Y-m-d H:i:s');
|
---|
223 | $this->objUserModel->insertPaidlog($sentNumber, $userName, _SBG_PAIDTYPE_SMS, $amount, $paidTime);
|
---|
224 | }
|
---|
225 | else if ($result == _SBG_CHARGING_FAIL_NOT_ENOUGH) {
|
---|
226 | $aryPatterns = array ('/:amount:/');
|
---|
227 | $smsReturn = preg_replace($aryPatterns, array($amount), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_MSG'));
|
---|
228 | if ($case == _SBG_MO_PAY_TO_ACCOUNT_FOR) {
|
---|
229 | $aryPatterns = array ('/:amount:/', '/:username:/');
|
---|
230 | $smsReturn = preg_replace($aryPatterns, array($amount, $userName), lang('_SBG_MO_CHARGING_FAIL_NOT_ENOUGH_FOR_MSG'));
|
---|
231 | }
|
---|
232 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn;
|
---|
233 | }
|
---|
234 | else if ($result == _SBG_CHARGING_FAIL_MORETHAN_LIMIT) {
|
---|
235 | $aryPatterns = array ('/:sendid:/');
|
---|
236 | $smsReturn = preg_replace($aryPatterns, array($sentNumber), lang('_SBG_MO_CHARGING_FAIL_MORETHAN_LIMIT_MSG'));
|
---|
237 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.$smsReturn;
|
---|
238 | }else if ($result == _SBG_CHARGING_FAIL_NOT_VIETTEL || $result == _SBG_CHARGING_NUMBER_NOT_EXISTED || $result == _SBG_CHARGING_NUMBER_NOT_AVAILABLE) {
|
---|
239 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_NOT_VIETTEL_MSG');
|
---|
240 | }
|
---|
241 | else {
|
---|
242 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_CHARGING_FAIL_MSG');
|
---|
243 | }
|
---|
244 | break;
|
---|
245 | case _SBG_MO_SUPPOR_SERVICE:
|
---|
246 | $smsReturn = '1|'.lang('_SBG_MO_SUPPORT_MSG');
|
---|
247 | break;
|
---|
248 | case _SBG_MO_UNSUBSCRIBE_SERVICE:
|
---|
249 | case _SBG_MO_SYNTAX_ERR:
|
---|
250 | default:
|
---|
251 | $smsReturn = _SBG_MO_PROCCESS_ERR.'|'.lang('_SBG_MO_SYNTAX_ERR_MSG');
|
---|
252 | break;
|
---|
253 | }
|
---|
254 |
|
---|
255 | return $smsReturn.'|'.$case;
|
---|
256 | }
|
---|
257 |
|
---|
258 |
|
---|
259 | /**
|
---|
260 | * cardPaidProcess
|
---|
261 | *
|
---|
262 | * @todo Call Topup webservice to check and lock prepaid-card
|
---|
263 | * @param Array $aryCardInfo
|
---|
264 | * @param Array $aryTopupResult
|
---|
265 | * @return string
|
---|
266 | */
|
---|
267 | public function cardPaidProcess ($aryCardInfo, &$aryTopupResult = array())
|
---|
268 | {
|
---|
269 | $url = $this->config->item('topup_service_url');
|
---|
270 | $action = 'http://tempuri.org/ITopupService/TopUp';
|
---|
271 | $xml = $this->load->view('topup', $aryCardInfo, true);
|
---|
272 |
|
---|
273 | $client = new nusoap_client($url);
|
---|
274 | $client->useHTTPPersistentConnection();
|
---|
275 | $client->soap_defencoding = 'UTF-8';
|
---|
276 | $client->operation = $action;
|
---|
277 |
|
---|
278 | $result = $client->send($xml, $action);
|
---|
279 |
|
---|
280 | if ($client->fault) {
|
---|
281 | return _SBG_CARD_PAY_FAIL;
|
---|
282 | }
|
---|
283 |
|
---|
284 | $keys = array_keys($result);
|
---|
285 |
|
---|
286 | $aryTopupResult = $result[$keys[0]];
|
---|
287 |
|
---|
288 | $debugMsg = 'Logged time: '. date('Y-m-d H:i:s') ."\n";
|
---|
289 | $debugMsg .= 'Send:'."\n" .$xml ."\n\n";
|
---|
290 | $debugMsg .= 'Result:'."\n". var_export($result, TRUE);
|
---|
291 | write_file('./log/topup_log', $debugMsg);
|
---|
292 |
|
---|
293 | if ($aryTopupResult['Success'] == 'false') {
|
---|
294 | return _SBG_CARD_PAY_FAIL;
|
---|
295 | }
|
---|
296 |
|
---|
297 | return _SBG_CARD_PAY_SUCCESS;
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * chargeRootAccountProcess
|
---|
302 | *
|
---|
303 | * @todo Call charging webservice to charged fee from phone root account
|
---|
304 | * @param String $sentID
|
---|
305 | * @param Integer $amount
|
---|
306 | * @param String $contents
|
---|
307 | * @return string|number
|
---|
308 | */
|
---|
309 | public function chargeRootAccountProcess ($sentID, $amount = 0, $contents = '')
|
---|
310 | {
|
---|
311 | $url = $this->config->item('charging_service_url');
|
---|
312 | $username = $this->config->item('charging_username');
|
---|
313 | $password = $this->config->item('charging_password');
|
---|
314 | $action = 'http://tempuri.org/processCharging';
|
---|
315 |
|
---|
316 | $aryParams = array(
|
---|
317 | 'user' => $username,
|
---|
318 | 'pass' => $password,
|
---|
319 | 'MSISDN' => $sentID,
|
---|
320 | 'Charging' => $amount,
|
---|
321 | 'Contents' => $contents
|
---|
322 | );
|
---|
323 |
|
---|
324 | $xml = $this->load->view('charging', $aryParams, true);
|
---|
325 | $client = new nusoap_client($url);
|
---|
326 | $client->useHTTPPersistentConnection();
|
---|
327 | $client->soap_defencoding = 'UTF-8';
|
---|
328 | $client->operation = $action;
|
---|
329 | $result = $client->send($xml, $action);
|
---|
330 |
|
---|
331 | if ($client->fault) {
|
---|
332 | return _SBG_CHARGING_FAIL;
|
---|
333 | }
|
---|
334 |
|
---|
335 | $aryErrs = array ( _SBG_CHARGING_FAIL_NOT_ENOUGH,
|
---|
336 | _SBG_CHARGING_FAIL_NOT_VIETTEL,
|
---|
337 | _SBG_CHARGING_FAIL_MORETHAN_LIMIT,
|
---|
338 | _SBG_CHARGING_NUMBER_NOT_EXISTED,
|
---|
339 | _SBG_CHARGING_NUMBER_NOT_AVAILABLE,
|
---|
340 | _SBG_CHARGING_NUMBER_CHANGED_OWNER,
|
---|
341 | _SBG_CHARGING_GENERAL_ERROR,
|
---|
342 | _SBG_CHARGING_NUMBER_NOT_REGISTED);
|
---|
343 |
|
---|
344 | if (in_array((int)$result['processChargingResult'], $aryErrs))
|
---|
345 | return (int)$result['processChargingResult'];
|
---|
346 |
|
---|
347 | return _SBG_CHARGING_SUCCESS;
|
---|
348 | }
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * sendMT
|
---|
352 | *
|
---|
353 | * @todo Calling MT webservice to send a SMS to a phone number
|
---|
354 | * @param String $receiverID
|
---|
355 | * @param String $message
|
---|
356 | * @return string
|
---|
357 | */
|
---|
358 | public function sendMT ($receiverID, $message)
|
---|
359 | {
|
---|
360 | $aryMatch = array();
|
---|
361 |
|
---|
362 | if (preg_match('/^(0)([0-9]{9,10})$/', $receiverID, $aryMatch) == 1) {
|
---|
363 | $receiverID = '84'. $aryMatch[2];
|
---|
364 | }
|
---|
365 |
|
---|
366 | $username = $this->config->item('mt_username');
|
---|
367 | $password = $this->config->item('mt_password');
|
---|
368 | $action = 'http://tempuri.org/InsertMT';
|
---|
369 |
|
---|
370 | $aryParams = array(
|
---|
371 | 'User' => $username,
|
---|
372 | 'Pass' => $password,
|
---|
373 | 'CPCode' => _SBG_MT_CP_CODE,
|
---|
374 | 'UserID' => _SBG_MT_SEND_NUMBER,
|
---|
375 | 'RequestID' => '4',
|
---|
376 | 'ReceiverID' => $receiverID,
|
---|
377 | 'ServiceID' => _SBG_SERVICE_SERVICEID,
|
---|
378 | 'CommandCode' => _SBG_SERVICE_COMMAND_CODE,
|
---|
379 | 'ContentType' => '0',
|
---|
380 | 'Info' => $message
|
---|
381 | );
|
---|
382 |
|
---|
383 | $xml = $this->load->view('mt', $aryParams, true);
|
---|
384 | $url = $this->config->item('mt_service_url');
|
---|
385 | $client = new nusoap_client($url);
|
---|
386 | $client->useHTTPPersistentConnection();
|
---|
387 | $client->soap_defencoding = 'UTF-8';
|
---|
388 | $client->operation = $action;
|
---|
389 | $result = $client->send($xml, $action);
|
---|
390 |
|
---|
391 | if ($client->fault || (int)$result['InsertMTResult'] != 1) {
|
---|
392 | return _SBG_SEND_MT_FAIL;
|
---|
393 | }
|
---|
394 |
|
---|
395 | return _SBG_SEND_MT_SUCCESS;
|
---|
396 | }
|
---|
397 |
|
---|
398 | public function getCollaborator ($type = 2, $page = 10, $displaypage = 1) {
|
---|
399 | $action = 'http://tempuri.org/InsertMT';
|
---|
400 | $url = $this->config->item('bccs_service_url');
|
---|
401 | $username = $this->config->item('bccs_username');
|
---|
402 | $password = $this->config->item('bccs_password');
|
---|
403 | $wscode = 'getListShopAndStaftInfo';
|
---|
404 | $aryParams = array(
|
---|
405 | 'user' => $username,
|
---|
406 | 'pass' => $password,
|
---|
407 | 'wscode' => $wscode,
|
---|
408 | 'type' => $type,
|
---|
409 | 'page' => $page,
|
---|
410 | 'displaypage' => $displaypage
|
---|
411 | );
|
---|
412 | $xml = $this->load->view('bscc', $aryParams, true);
|
---|
413 |
|
---|
414 | $client = new nusoap_client($url);
|
---|
415 | $client->useHTTPPersistentConnection();
|
---|
416 | $client->soap_defencoding = 'UTF-8';
|
---|
417 | //$client->soap_defencoding = 'ISO-8859-1';
|
---|
418 |
|
---|
419 | $client->operation = $action;
|
---|
420 | $result = $client->send($xml, $action);
|
---|
421 | if ($client->fault || (int)$result['Result']['error'] != 0) {
|
---|
422 | return _SBG_GET_COLLABORATOR_FAIL;
|
---|
423 | }
|
---|
424 |
|
---|
425 | return $result['Result']['original'];
|
---|
426 | }
|
---|
427 |
|
---|
428 | /**
|
---|
429 | * formatPhoneNumber
|
---|
430 | *
|
---|
431 | * @todo format phone number to prefix 0 or 84
|
---|
432 | * @param String $phoneNumber
|
---|
433 | * @param Integer $direction
|
---|
434 | * @return String
|
---|
435 | */
|
---|
436 | public function formatPhoneNumber ($phoneNumber, $direction = 1) {
|
---|
437 | $aryMatch = array();
|
---|
438 | if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
|
---|
439 | $result = '0'. $aryMatch[2];
|
---|
440 | }
|
---|
441 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
|
---|
442 | $result = $phoneNumber;
|
---|
443 | }
|
---|
444 | else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
|
---|
445 | $result = $phoneNumber;
|
---|
446 | }
|
---|
447 | else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
|
---|
448 | $result = '84'. $aryMatch[2];
|
---|
449 | }
|
---|
450 |
|
---|
451 | return $result;
|
---|
452 | }
|
---|
453 |
|
---|
454 |
|
---|
455 | public function syncCollaborator($data){
|
---|
456 | if ($data){
|
---|
457 | $sql = $this->db->insert_string('tblcollaborator', $data) . ' ON DUPLICATE KEY UPDATE address = "'.$data['address'].'",
|
---|
458 | code = "'.$data['code'].'",
|
---|
459 | district = "'.$data['district'].'",
|
---|
460 | email = "'.$data['email'].'",
|
---|
461 | full_name = "'.$data['full_name'].'",
|
---|
462 | cellphone = "'.$data['cellphone'].'",
|
---|
463 | precinct = "'.$data['precinct'].'",
|
---|
464 | province = "'.$data['province'].'",
|
---|
465 | created_time = "'.$data['created_time'].'",
|
---|
466 | updated_time = "'.$data['updated_time'].'"';
|
---|
467 | $this->db->query($sql);
|
---|
468 | $id = $this->db->insert_id();
|
---|
469 | if ($this->db->affected_rows()){
|
---|
470 | //echo "Collaborator ID: ".$id.". Sync Success !<br/>";
|
---|
471 | $logMsg = date('Y-m-d H:i:s') . " Collaborator ID: ".$id.". Sync Success !\n";
|
---|
472 | write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
473 | }else{
|
---|
474 | //echo "Collaborator ID: ".$id.". Sync fail!. Sql = ".$sql."<br/>";
|
---|
475 | $logMsg = date('Y-m-d H:i:s') . " Collaborator ID: ".$id.". Sync fail!. Sql = ".$sql."\n";
|
---|
476 | write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
477 | }
|
---|
478 | }else {
|
---|
479 | $logMsg = date('Y-m-d H:i:s') . " Data is null \n";
|
---|
480 | write_file('./log/sync_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | public function deleteCollaborator($id){
|
---|
485 | $sql = "DELETE FROM tblcollaborator WHERE id = ". $id;
|
---|
486 | $this->db->query($sql);
|
---|
487 | if ($this->db->affected_rows()){
|
---|
488 | $logMsg = date('Y-m-d H:i:s') . " Collaborator ID: ".$id.". Delete success!\n";
|
---|
489 | write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
490 | }else{
|
---|
491 | $logMsg = date('Y-m-d H:i:s') . " Collaborator ID: ".$id.". Delete fail!. Sql = ".$sql."\n";
|
---|
492 | write_file('./log/delete_collaborator.log', $logMsg, FOPEN_WRITE_CREATE);
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|
496 | public function getAllCollaboratorID(){
|
---|
497 | $sql = "Select id from tblcollaborator";
|
---|
498 | $query = $this->db->query($sql);
|
---|
499 | if ($this->db->affected_rows()){
|
---|
500 | return $query->result();
|
---|
501 | }else
|
---|
502 | {
|
---|
503 | return array();
|
---|
504 | }
|
---|
505 | }
|
---|
506 | } |
---|