public function actionCustomerQuest()
 {
     DynamicCall::GetEdit1stPdf(getCurCusId());
     $customer_questions = $this->loadModel(getCurCusId());
     if (isset($_POST['customer']) && isset($_POST['customer']['ajax'])) {
         $customer_questions['earliest_timedelivery'] = isset($_POST['customer']['earliest_timedelivery']) ? $_POST['customer']['earliest_timedelivery'] : "";
         $customer_questions['more_companies'] = isset($_POST['customer']['more_companies']) ? $_POST['customer']['more_companies'] : "";
         $customer_questions['no_people'] = isset($_POST['customer']['no_people']) ? $_POST['customer']['no_people'] : "";
         $customer_questions['present_carters'] = isset($_POST['customer']['present_carters']) ? $_POST['customer']['present_carters'] : "";
         $customer_questions['company_order'] = isset($_POST['customer']['company_order']) ? $_POST['customer']['company_order'] : "";
         $customer_questions['avg_attend'] = isset($_POST['customer']['avg_attend']) ? $_POST['customer']['avg_attend'] : "";
         $customer_questions['email'] = isset($_POST['customer']['email']) ? $_POST['customer']['email'] : "";
         $customer_questions['linked_in'] = isset($_POST['customer']['linked_in']) ? $_POST['customer']['linked_in'] : "";
         $customer_questions['competitor_id'] = isset($_POST['customer']['competitor_id']) ? $_POST['customer']['competitor_id'] : "";
         if ($customer_questions->save()) {
             $currentCustomerId = getCurCusId();
             if (!Yii::app()->session['edit_1st_pdf']) {
                 $cusApp = CustAppoint::model()->findByAttributes(array('cus_id' => getCurCusId(), 'app_id' => 1));
                 $cusApp->status = 1;
                 $time = time();
                 $cusApp->update_time = date("Y-m-d h:i:s", $time);
                 if ($cusApp->save()) {
                     $cusApp = new CustAppoint();
                     $cusApp->app_id = 2;
                     $cusApp->cus_id = getCurCusId();
                     $cusApp->status = 1;
                     $cusApp->save();
                 }
             }
             unset(Yii::app()->session['sel_prod']);
             $this->UpdateRemote($currentCustomerId);
             //exit;
         }
         echo json_encode(array('success' => 'true'));
         exit;
     }
     $time_range = range(7.3, 19.55, 0.05);
     $dd_time_range = array();
     foreach ($time_range as $range) {
         $decimalPart = (int) substr($range, strrpos($range, '.') + 1);
         if ($decimalPart <= 60) {
             $time = number_format((double) $range, 2, ':', '');
             $dd_time_range[$time] = $time;
         }
     }
     $peopleOnSite = array("0-5" => '0-5', "6-10" => '6-10', "11-20" => '11-20', "21-40" => '21-40', "41-100" => '41-100', "101-150" => '101-150', "151-200" => '151-200', "201-250" => '201-250', "251-300" => '251-300', "300+" => '300+');
     $competitor = JaspersCompetitor::model()->findAll(array("condition" => "competitor_oid = " . getCurCusDet('jaspers_franchise')));
     $email = getCurCusDet('email');
     $this->render('customer_quest', array('customer' => $customer_questions, 'time_range' => $dd_time_range, 'peopleOnSite' => $peopleOnSite, 'competitor' => $competitor, 'email' => $email));
 }
Exemplo n.º 2
0
 function actionDealData($option)
 {
     $actionList = array('franchise' => 'createFranchises', 'comp' => 'createCompanies', 'contact' => 'createContacts', 'competitor' => 'createCompetitor', 'franchiseData' => 'updateFranchiseData');
     if (in_array($option, $actionList)) {
         if ($option == $actionList['franchiseData']) {
             $criteria = new CDbCriteria();
             $criteria->select = 'MAX(comp_id) as comp_id';
             $criteria->condition = 'franchise_id = :franch_id';
             $criteria->params = array(':franch_id' => $this->franchiseId);
             $company = JaspersCompanies::model()->find($criteria);
             $criteria = new CDbCriteria();
             $criteria->select = 'MAX(competitor_oid) as competitor_id';
             $criteria->condition = 'competitor_oid = :franch_id';
             $criteria->params = array(':franch_id' => $this->franchiseId);
             $competitor = JaspersCompetitor::model()->find($criteria);
             $criteria = new CDbCriteria();
             $criteria->select = 'MAX(user_id) as user_id';
             $criteria->condition = 'franchise_id = :franch_id';
             $criteria->params = array(':franch_id' => $this->franchiseId);
             $contact = JaspersContacts::model()->find($criteria);
             $ref = array('contact' => $contact->user_id, 'company' => $company->comp_id, 'competitor' => $competitor->competitor_id, 'franchise_id' => $this->franchiseId);
             $refData = Yii::app()->curl->run('http://mccreative.jaspersonline.co.uk/api/customer/getRefUpdate/', $ref);
             if (!$refData->hasErrors()) {
                 $reference = CJSON::decode($refData->getData());
                 if (isset($reference['companies_data']['data']) && count($reference['companies_data']['data'])) {
                     $builder = Yii::app()->db->schema->commandBuilder;
                     $command = $builder->createMultipleInsertCommand('jaspers_companies', $reference['companies_data']['data']);
                     $command->execute();
                 }
                 if (isset($reference['contact_data']['data']) && count($reference['contact_data']['data'])) {
                     $builder = Yii::app()->db->schema->commandBuilder;
                     $command = $builder->createMultipleInsertCommand('jaspers_contacts', $reference['contact_data']['data']);
                     $command->execute();
                 }
                 if (isset($reference['competitor_data']['data']) && count($reference['competitor_data']['data'])) {
                     $builder = Yii::app()->db->schema->commandBuilder;
                     $command = $builder->createMultipleInsertCommand('jaspers_competitor', $reference['competitor_data']['data']);
                     $command->execute();
                 }
             }
         } else {
             if ($option == $actionList['franchise']) {
                 $franchise = Yii::app()->curl->run('http://dev.jaspersonline.co.uk/info/branchlist.php');
                 if (!$franchise->hasErrors()) {
                     //Yii::app()->db->createCommand()->truncateTable('jaspers_franchise');
                     JaspersFranchise::model()->deleteAll();
                     $franchises = $franchise->getData();
                     $franchises = explode('<br>', $franchises);
                     $insert_det = array();
                     if (count($franchises)) {
                         $index = 0;
                         foreach ($franchises as $franch_det) {
                             $franch_det = explode('-', $franch_det);
                             if (count($franch_det) && isset($franch_det[0]) && !empty($franch_det[0])) {
                                 $franchise_contact_det = Yii::app()->curl->run('http://mccreative.jaspersonline.co.uk/api/customer/getContactDet/' . trim($franch_det[1]));
                                 $frach_cust_data = array('ref' => '', 'city' => '', 'email' => '', 'mobile' => '', 'address' => '', 'facebook' => '', 'telephone' => '', 'twitter' => '');
                                 if (!$franchise_contact_det->hasErrors()) {
                                     $frach_cust_data = CJSON::decode($franchise_contact_det->getData());
                                     $frach_cust_data = $frach_cust_data['data'];
                                 }
                                 $insert_det[$index]['id'] = trim($franch_det[1]);
                                 $insert_det[$index]['franchise_id'] = trim($franch_det[1]);
                                 $insert_det[$index]['ref'] = trim($frach_cust_data['ref']);
                                 $insert_det[$index]['city'] = trim($frach_cust_data['city']);
                                 $insert_det[$index]['email'] = trim($frach_cust_data['email']);
                                 $insert_det[$index]['mobile'] = trim($frach_cust_data['mobile']);
                                 $insert_det[$index]['address'] = trim($frach_cust_data['address']);
                                 $insert_det[$index]['twitter'] = trim($frach_cust_data['twitter']);
                                 $insert_det[$index]['facebook'] = trim($frach_cust_data['facebook']);
                                 $insert_det[$index]['telephone'] = trim($frach_cust_data['telephone']);
                                 $insert_det[$index]['franchise_name'] = trim($franch_det[0]);
                                 $index++;
                             }
                         }
                         $builder = Yii::app()->db->schema->commandBuilder;
                         $command = $builder->createMultipleInsertCommand('jaspers_franchise', $insert_det);
                         $command->execute();
                     }
                 }
             } else {
                 if ($option == $actionList['comp']) {
                     $companies = Yii::app()->curl->run('http://mccreative.jaspersonline.co.uk/api/customer/getCompanyList');
                     if (!$companies->hasErrors()) {
                         Yii::app()->db->createCommand()->truncateTable('jaspers_companies');
                         $companies_data = CJSON::decode($companies->getData());
                         $builder = Yii::app()->db->schema->commandBuilder;
                         $command = $builder->createMultipleInsertCommand('jaspers_companies', $companies_data['data']);
                         $command->execute();
                     }
                 } else {
                     if ($option == $actionList['contact']) {
                         $customerCount = Yii::app()->curl->run('http://mccreative.jaspersonline.co.uk/api/customer/getCustomerCount');
                         if (!$customerCount->hasErrors()) {
                             $customer_data = CJSON::decode($customerCount->getData());
                             if (isset($customer_data['data']['ttl'])) {
                                 $limit = 5000;
                                 $ttls = $customer_data['data']['ttl'];
                                 $loopCount = $ttls / $limit;
                                 $loopCount = ceil($loopCount);
                                 Yii::app()->db->createCommand()->truncateTable('jaspers_contacts');
                                 for ($i = 0; $i < $loopCount; $i++) {
                                     $offset = $i * ($limit - 1);
                                     $customer = Yii::app()->curl->run('http://mccreative.jaspersonline.co.uk/api/customer/getCustomerList/' . $offset . '/' . $limit);
                                     if (!$customer->hasErrors()) {
                                         $customer_data = CJSON::decode($customer->getData());
                                         $builder = Yii::app()->db->schema->commandBuilder;
                                         $command = $builder->createMultipleInsertCommand('jaspers_contacts', $customer_data['data']);
                                         $command->execute();
                                     }
                                 }
                             }
                         }
                     } else {
                         if ($option == $actionList['competitor']) {
                             $competitor = Yii::app()->curl->run('http://mccreative.jaspersonline.co.uk/api/customer/getCompetitor');
                             if (!$competitor->hasErrors()) {
                                 Yii::app()->db->createCommand()->truncateTable('jaspers_competitor');
                                 $competitor_data = CJSON::decode($competitor->getData());
                                 $builder = Yii::app()->db->schema->commandBuilder;
                                 $command = $builder->createMultipleInsertCommand('jaspers_competitor', $competitor_data['data']);
                                 $command->execute();
                             }
                         }
                     }
                 }
             }
         }
     }
 }