public function actionIndex() { $return = array('error' => 0, 'msg' => ''); if (Yii::app()->request->isPostRequest) { $phone = Formatter::formatPhone($_POST['phone']); if (Formatter::isVinaphoneNumber($phone)) { if (!isset($_COOKIE["verifyWifiEvent"])) { if (isset($_SESSION['countverifyWifiEvent'])) { unset($_SESSION['countverifyWifiEvent']); } $_SESSION['countverifyWifiEvent'] = 1; $_SESSION['phoneverifyWifiEvent'] = $phone; setcookie("verifyWifiEvent", 1, time() + 600); } else { $_SESSION['countverifyWifiEvent']++; if ($_SESSION['countverifyWifiEvent'] > 3) { $return['error'] = 1; $return['msg'] = "Quí khách đã vượt quá số lần xác thực. Vui lòng thử lại sau ít phút."; } } if ($return['error'] == 0) { try { $userVerify = UserVerifyModel::model()->findByAttributes(array('msisdn' => $phone, 'action' => 'register_event83')); if (!empty($userVerify)) { $verifyCode = $userVerify->verify_code; } else { $verifyCode = rand(1000, 9999); $verifyModel = new UserVerifyModel(); $verifyModel->setAttribute('created_time', date("Y-m-d H:i:s")); $verifyModel->setAttribute('msisdn', $phone); $verifyModel->setAttribute('verify_code', $verifyCode); $verifyModel->setAttribute('action', 'register_event83'); $verifyModel->save(); } $sms = new SmsClient(); $content = "Ma xac thuc dang ky tren chacha la: " . $verifyCode; $sms->sentMT("9234", $phone, 0, $content, 0, "", time(), 9234); $this->redirect('/event/register/verifyWifi'); } catch (Exception $exc) { echo $exc->getTraceAsString(); } } } else { $return['error'] = 2; $return['msg'] = "Số điện thoại của bạn không phải là thuê bao Vinaphone!"; } } $this->render('index', array('return' => $return)); }
public function actionSubscribe() { /*if(!isset($_SERVER['SERVER_NAME']) || $_SERVER['SERVER_NAME'] != 'msisdn.chacha.vn'){ $this->redirect('/site/error404'); }*/ $userPhone = Yii::app()->user->getState('msisdn'); $userSub = $this->userSub; //WapUserSubscribeModel::model()->findByAttributes(array('user_phone' => $userPhone, 'status' => UserSubscribeModel::ACTIVE)); $confirm = Yii::app()->request->getParam('confirm', 0); $source = Yii::app()->request->getParam('source', 'buzzcity'); $source = strtoupper($source); $result = null; $userObj = null; if ($confirm == 0) { $write = 1; if (isset($_SESSION[$source])) { // check time giua 2 lan visit co > 15 giay hay ko $latest_time = $_SESSION[$source]; $now = date("Y-m-d H:i:s"); $diff = strtotime($now) - strtotime($latest_time); if (intval($diff) < 15) { $write = 0; } } if ($write == 1) { // log to table log_ads_click $log = new LogAdsClickModel(); $ip = $_SERVER["REMOTE_ADDR"]; $is3G = 0; if (Yii::app()->user->getState('is3G')) { $is3G = 1; } $log->logAdsWap($userPhone, $source, $ip, $is3G); // set session value $_SESSION[$source] = date("Y-m-d H:i:s"); } } $destUrl = Yii::app()->request->getParam('url', Yii::app()->homeUrl); //$destUrl = urldecode($destUrl); if ($userSub) { $this->redirect($destUrl); } $isPromotion = WapUserSubscribeModel::model()->checkPromotion($userPhone); if ($isPromotion) { $confirm = 1; } if ($confirm == 1) { try { $phone = $userPhone; if (!isset($phone) || !Formatter::isVinaphoneNumber($phone)) { $result = new stdClass(); $result->errorCode = 401; $result->message = WapUserSubscribeModel::model()->getCustomMetaData('3G_TEXT'); } else { //anti flood request if (!isset($_SESSION)) { session_start(); } //time_nanosleep(0, 500000000); $token = Yii::app()->request->csrfToken; $ssid = session_id(); $sql = "INSERT INTO user_phone_subscribe_unduplicate(phone,ssid,token,created_time,status)\n\t\t\t\t\tVALUE('{$userPhone}','{$ssid}','{$token}',NOW(),0)\n\t\t\t\t\t"; $connDB = VegaCommonFunctions::getConnectMysql(); $res1 = mysql_query($sql); mysql_close($connDB); if ($res1) { $bmUrl = yii::app()->params['bmConfig']['remote_wsdl']; $client = new SoapClient($bmUrl, array('trace' => 1)); $params = array('phone' => $userPhone, 'package' => 'CHACHAFUN', 'source' => 'wap', 'promotion' => '', 'bundle' => 0, 'smsId' => null, 'note_event' => $source); $result = $client->__soapCall('userRegister', $params); $timeClear = date('Y-m-d H:i:s', time() - 60 * 5); $sql = "DELETE FROM user_phone_subscribe_unduplicate WHERE created_time<='{$timeClear}'"; $res2 = Yii::app()->db->createCommand($sql)->execute(); } else { $log = new KLogger("SUBS_DUPLICATE_EXCEPTION", KLogger::INFO); $log->LogInfo("Ex:" . $userPhone, false); $this->redirect($destUrl); exit; } } if ($result->errorCode == 0 || $result->errorCode == '0') { //$userObj = WapUserSubscribeModel::model()->findByAttributes(array('user_phone' => $userPhone)); if ($isPromotion) { Yii::app()->user->setState('DK_MA_MSG', 'Quý khách có 7 ngày vàng trải nghiệm dịch vụ: Nghe, xem, tải MIỄN PHÍ toàn bộ nội dung và miễn cước data (3G/GPRS~30.000đ/ngày).Tặng kèm gói miễn phí tải nhạc chuông và quà tặng âm nhạc. Để từ chối nhận KM Quý khách soạn HUY CHACHA gửi 9234'); } $this->redirect($destUrl); } } catch (Exception $e) { $log = new KLogger("SUBS_EXCEPTION", KLogger::INFO); $log->LogInfo("Ex:" . $e->getMessage(), false); //Yii::log($e->getMessage(), "error", "exeption.BMException"); $this->redirect($destUrl); exit; } } else { $log = new KLogger("SUBS_NOT_PROMOTION", KLogger::INFO); $log->LogInfo($userPhone, false); } $this->renderPartial("subscribe_adv", array('userObj' => $userObj, 'result' => $result, 'confirm' => $confirm, 'source' => strtolower($source), 'isPromotion' => $isPromotion, 'destUrl' => $destUrl)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PhoneModel(); $message = ""; $errorList = array(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['source_name'], $_POST['group_id'])) { $fileName = _APP_PATH_ . DS . "data" . DS . "tmp" . DS . $_POST['source_name']; $group_id = $_POST['group_id']; //$fileName = "D:\\chacha_cloud\\src\\trunk\chacha\data\\tmp\\20120713170547_phone_list.xls"; try { require_once 'excel_reader2.php'; $data = new Spreadsheet_Excel_Reader($fileName, true, "UTF-8"); // khoi tao doi tuong doc file excel $rowsnum = $data->rowcount($sheet_index = 0); // lay so hang cua sheet $colsnum = $data->colcount($sheet_index = 0); // lay so cot cua sheet for ($i = 2; $i <= $rowsnum; $i++) { // doc tu hang so 2 vi hang 1 la tieu de roi! $phoneNum = $data->val($i, 1); // xuat cot so 1 va cot so 2 tren cung 1 hang // check so dien thoai xem co dung cua Vinaphone ko try { $phoneNum = Formatter::formatPhone($phoneNum); if (Formatter::isVinaphoneNumber($phoneNum)) { $model->phone = "{$phoneNum}"; $model->group_id = $group_id; $model->status = 0; $model->created_time = date("Y-m-d H:i:s"); var_dump($model->phone); try { if ($model->save()) { $message = yii::t('SpamModule', 'Upload thành công'); } else { print_r($model->getErrors()); exit; } } catch (Exception $exc) { echo $exc->getTrace(); } } else { //echo so dien thoai ko dung $errorList[] = $phoneNum; } } catch (Exception $exc) { echo $exc->getMessage(); } } } catch (Exception $exc) { echo $exc->getMessage(); } } $uploadModel = new XUploadForm(); $tmpArr = GroupModel::model()->findAll(); $smsGroup = array(); foreach ($tmpArr as $smsG) { $smsGroup[$smsG->id] = $smsG->name; } $this->render('create', array('model' => $model, 'uploadModel' => $uploadModel, 'message' => $message, 'smsGroup' => $smsGroup, 'errorList' => $errorList)); }
/** * @author tannew * Upload phone numbers to Group */ public function actionUpload() { $message = ""; $errorList = array(); // list of invalid Vinaphone phone $dupList = array(); // list of duplicated phone $subscribeList = array(); // list subscribed phone $arrayVal = array(); $arr_filter = array(); $id = $_POST['group_id']; $source_file = $_POST['source_name']; //ten file excel $arr_filter['register_phone_filter'] = $_POST['register_phone_filter']; //checkbox: Kiem tra nhung so DT da dang ki $arr_filter['exist_group_filter'] = $_POST['exist_group_filter']; //checkbox: Loai bo nhung so DT da thuoc group khac $arr_filter['group_list'] = $_POST['group_list']; // danh sach cac Group muon loai bo cac so DT da thuoc chung $arr_filter['date_filter'] = $_POST['date_filter']; // text: Loc theo ngay $arr_filter['km_filter'] = $_POST['km_filter']; // chi lay nhung so DT dc huong KM de add vao group $group_id = $id; if (isset($source_file, $id)) { $fileName = _APP_PATH_ . DS . "public/admin/data" . DS . "tmp" . DS . $source_file; try { require_once 'excel_reader2.php'; $data = new Spreadsheet_Excel_Reader($fileName, true, "UTF-8"); // khoi tao doi tuong doc file excel $rowsnum = $data->rowcount($sheet_index = 0); // lay so hang cua sheet for ($i = 1; $i <= $rowsnum; $i++) { // doc tu hang so 2 vi hang 1 la tieu de roi! $phoneNum = $data->val($i, 1); // xuat cot so 1 va cot so 2 tren cung 1 hang try { $phoneNum = Formatter::formatMSISDN($phoneNum, "84,0", "84"); if (Formatter::isVinaphoneNumber($phoneNum)) { $created_time = date("Y-m-d H:i:s"); $exist = PhoneModel::model()->exists('group_id = :group_id AND phone= :phone', array(':phone' => $phoneNum, ':group_id' => $id)); if ($exist == false) { try { $arrayVal[] = "('{$phoneNum}',{$group_id},0,'{$created_time}')"; } catch (Exception $exc) { echo $exc->getMessage(); } } else { $dupList[] = $phoneNum; } } else { $errorList[] = $phoneNum; } } catch (Exception $exc) { echo $exc->getMessage(); } } /** * Start insert here: split each 200 phone */ $arrs = array_chunk($arrayVal, 200); foreach ($arrs as $arr) { $vals = implode(",", $arr); $sql = "INSERT INTO spam_sms_phone (`phone`,`group_id`,`status`,`created_time`) VALUES {$vals}"; $command = Yii::app()->db->createCommand($sql); $command->execute(); } } catch (Exception $exc) { echo $exc->getMessage(); } } // delete phone in blacklist $sql = "DELETE spam_sms_phone.* FROM spam_sms_phone INNER JOIN deleted_phone on deleted_phone.phone = spam_sms_phone.phone WHERE spam_sms_phone.group_id = :gid"; $command = Yii::app()->db->createCommand($sql); $command->bindParam(":gid", $group_id); $command->execute(); // Delete phone from spam_sms_reject_phone $sql = "DELETE spam_sms_phone.* FROM spam_sms_phone INNER JOIN spam_sms_reject_phone t2 on t2.phone = spam_sms_phone.phone WHERE spam_sms_phone.group_id = :gid"; $command = Yii::app()->db->createCommand($sql); $command->bindParam(":gid", $group_id); $command->execute(); // C1: delete phone Ko dc huong KM if km_filter = 1 if ($arr_filter['km_filter'] == "1") { $sql = "DELETE spam_sms_phone.* FROM spam_sms_phone INNER JOIN user_subscribe_km on user_subscribe_km.phone = spam_sms_phone.phone WHERE spam_sms_phone.group_id = :gid and (user_subscribe_km.type = 0 OR (user_subscribe_km.type = 1 AND user_subscribe_km.created_time >= date_sub(NOW(), interval 720 hour)))"; $command = Yii::app()->db->createCommand($sql); $command->bindParam(":gid", $group_id); $command->execute(); } // C3: remove all Phone in selected groups if ($arr_filter['exist_group_filter'] == "1") { if (!empty($arr_filter['group_list']) && count($arr_filter['group_list']) > 0) { $listGroup = implode(',', $arr_filter['group_list']); $sql = "DELETE s1.* FROM spam_sms_phone s1 INNER JOIN spam_sms_phone s2 ON s1.phone = s2.phone WHERE s1.group_id = :gid and s2.group_id IN (:listId)"; $command = Yii::app()->db->createCommand($sql); $command->bindParam(":gid", $group_id); $command->bindParam(":listId", $listGroup); $command->execute(); } } // C4: remove all Phone in groups have Cld which has been sent FROM...TO... if ($arr_filter['date_filter'] != "") { // extract Time $filter_time = ""; if (strrpos($arr_filter['date_filter'], "-")) { // example 8/13/2012 - 8/20/2012 $arr_filter['date_filter'] = explode("-", $arr_filter['date_filter']); $fromDate = explode("/", trim($arr_filter['date_filter'][0])); $fromDate = $fromDate[2] . "-" . str_pad($fromDate[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($fromDate[1], 2, '0', STR_PAD_LEFT); $toDate = explode("/", trim($arr_filter['date_filter'][1])); $toDate = $toDate[2] . "-" . str_pad($toDate[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($toDate[1], 2, '0', STR_PAD_LEFT); $filter_time = array('from' => $fromDate . ' 00:00:00', 'to' => $toDate . ' 23:59:59'); } else { // single day 8/16/2012 $time = explode("/", trim($arr_filter['date_filter'])); $time = $time[2] . "-" . str_pad($time[0], 2, '0', STR_PAD_LEFT) . "-" . str_pad($time[1], 2, '0', STR_PAD_LEFT); $filter_time = array('from' => $time . ' 00:00:00', 'to' => $time . ' 23:59:59'); } // Select all groups have Cld which has been sent FROM...TO... $cri = new CDbCriteria(); $cri->select = "group_id"; $cri->addBetweenCondition('send_time', $filter_time['from'], $filter_time['to']); $listGroup = SpamSmsCldModel::model()->findAll($cri); $arrGr = array(); foreach ($listGroup as $group) { $arrGr[] = $group->group_id; } // check if this phone belongs to one of those groups if (!empty($arrGr)) { $listGroup = implode(',', $arrGr); $sql = "DELETE s1.* FROM spam_sms_phone s1 INNER JOIN spam_sms_phone s2 ON s1.phone = s2.phone WHERE s1.group_id = :gid and s2.group_id IN (:listId)"; $command = Yii::app()->db->createCommand($sql); $command->bindParam(":gid", $group_id); $command->bindParam(":listId", $listGroup); $command->execute(); } } // C2: remove Registered phone if ($arr_filter['register_phone_filter'] == "1") { $sql = "DELETE s1.* FROM spam_sms_phone s1 INNER JOIN user_subscribe u ON s1.phone = u.user_phone WHERE u.expired_time >= '" . date("Y-m-d H:i:s") . "' AND user_phone != '84946760402'"; $command = Yii::app()->db->createCommand($sql); $command->execute(); } /* Insert test phones to TEST_GROUP */ $cri = new CDbCriteria(); $cri->select = "phone"; $cri->condition = "group_id = (SELECT id from spam_sms_group WHERE name= 'TEST_GROUP')"; if ($countTestPhone) { $listPhones = PhoneModel::model()->findAll($cri); $testPhones = array(); foreach ($listPhones as $phone) { $phoneNum = $phone->phone; $created_time = date("Y-m-d H:i:s"); $testPhones[] = "('{$phoneNum}',{$id},0,'{$created_time}')"; } $vals = implode(",", $testPhones); $sql = "INSERT INTO spam_sms_phone (`phone`,`group_id`,`status`,`created_time`) VALUES {$vals}"; $command = Yii::app()->db->createCommand($sql); $command->execute(); } /* end Insert test phones */ $phoneList = new PhoneModel(); $phoneList->unsetAttributes(); $phoneList->setAttribute('group_id', $id); Yii::app()->session['phoneList'] = $phoneList; Yii::app()->session['message'] = $message; Yii::app()->session['errorList'] = $errorList; Yii::app()->session['dupList'] = $dupList; Yii::app()->session['subscribeList'] = $subscribeList; $this->redirect(array('view', 'id' => $id)); }
public function actionShare() { $userPhone = yii::app()->user->getState('msisdn'); $isShare = GameEventActivityModel::isShareOnDay($userPhone, date('Y-m-d')); if ($isShare) { $this->redirect('/event/play/thank'); Yii::app()->end(); } $error = 0; $isSend = false; if (Yii::app()->request->isPostRequest) { $isSend = 0; $phoneList = $_POST['phone_list']; if ($phoneList != '') { $phoneArr = explode(',', $phoneList); if ($phoneArr) { foreach ($phoneArr as $key => $value) { $phone = Formatter::formatPhone($value); if (Formatter::isVinaphoneNumber($phone)) { $isSend++; $sms = new SmsClient(); $content = 'DV Chacha - Vinaphone kinh chao Quy Khach. Quy Khach vua duoc thue bao ' . $userPhone . ' moi dua tai trong chuong trinh "Vui cung Chacha - Nhan qua nhu y" voi giai thuong hap dan len toi 20 trieu dong. Chi tiet moi Quy Khach xem tai day http://m.chacha.vn/event'; $sms->sentMT("9234", $phone, 0, $content, 0, "", time(), 9234); } } if ($isSend > 0) { //chia se it nhat duoc 1 so vinaphone $gameActivity = new GameEventActivityModel(); $gameActivity->setAttribute('user_phone', $userPhone); $gameActivity->setAttribute('activity', 'share'); $gameActivity->setAttribute('point', 1); $gameActivity->setAttribute('updated_time', date('Y-m-d H:i:s')); $gameActivity->setAttribute('note', $phoneList, PDO::PARAM_STR); $gameActivity->save(); $this->redirect('/event/play/thank'); } } } else { //ko có sô dt nao $error = 1; } } $this->render('share', array('isShare' => $isShare, 'error' => $error, 'isSend' => $isSend)); }