示例#1
0
 public function actionCreate()
 {
     $model = new Store();
     if ($_POST['Store']) {
         $accessKey = Yii::app()->params['qiniu']['accessKey'];
         $secretKey = Yii::app()->params['qiniu']['secretKey'];
         $auth = new Auth($accessKey, $secretKey);
         $bucket = 'urtime1';
         $token = $auth->uploadToken($bucket);
         $uploadMgr = new UploadManager();
         //上传logo
         if ($_FILES['image']['name'] != null) {
             $images = array($_FILES['image']);
             $images = $this->setImageInformation($images, $token, $uploadMgr);
             if ($images) {
                 $_POST['Store']['image'] = $images[0];
             }
             unset($_FILES['image']);
         }
         //上传营业执照
         if ($_FILES['bussiness_license1']['name'] != null || $_FILES['bussiness_license2']['name'] != null) {
             $images = array($_FILES['bussiness_license1'], $_FILES['bussiness_license2']);
             $images = $this->setImageInformation($images, $token, $uploadMgr);
             if ($images) {
                 // $images_str = implode(',',$images);
                 $_POST['Store']['bussiness_license'] = json_encode($images);
                 //$images_str;
             }
             unset($_FILES['bussiness_license1']);
             unset($_FILES['bussiness_license2']);
         }
         //上传介绍图片
         if ($_FILES['upImage']['name'] != null) {
             $images = $this->setImageInformation($_FILES, $token, $uploadMgr);
             if ($images) {
                 //$images_str = implode(',',$images);
                 $_POST['Store']['images_str'] = json_encode($images);
                 //$images_str;
             }
         }
         $model->attributes = $_POST['Store'];
         if ($model->validate() && $model->save()) {
             //$this->redirect('site/index');
             Yii::app()->user->setFlash('create', '成功', '失败');
             // Yii::app()->end();
             $this->redirect(array('/store/view'));
         }
     }
     $managers = Managers::model()->loadStaffAllModel();
     $this->render('create', ['model' => $model, 'managers' => $managers]);
 }
示例#2
0
 public function actionCreateStore()
 {
     $model = new Store();
     if (isset($_POST['Store'])) {
         //		print_r($_POST);
         //		print_r($model->attributes);
         //		exit;
         $model->attributes = $_POST['Store'];
         $model->domain = 'shop' . time() . '.' . F::sg('site', 'shopDomain');
         $model->theme = 'default';
         if ($model->validate()) {
             if ($model->save()) {
                 $this->redirect('http://' . $model->domain);
             }
         } else {
             print_r($model->errors);
         }
     }
 }
示例#3
0
 private function import()
 {
     $db = new PDO(Yii::app()->params['db']['connectionString'], Yii::app()->params['db']['username'], Yii::app()->params['db']['password'], array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING));
     $resultRows = $db->query('SELECT * FROM raw_import WHERE id > ' . $this->lastRowProcessed . ' LIMIT ' . $this->rowsToProcess);
     $suppressionCount = 0;
     echo "\n\n" . 'Pointer is at ' . $this->lastRowProcessed . "\n\n";
     while ($data = $resultRows->fetch(PDO::FETCH_ASSOC)) {
         $StoreView = null;
         $DupeMatch = null;
         $CodeMatch = null;
         $Store2Contact = null;
         //20532
         // 1 yes 0 no 2 unknown
         $contact_email = 2;
         //unkown
         $contact_post = 2;
         $contact_sms = 2;
         $organisation_id = null;
         // create base Store instance.
         $StoreView = new Store();
         $data['CCR_Client_URN'] = $this->emptyToNull($data['CCR_Client_URN']);
         if (is_null($data['CCR_Client_URN'])) {
             // no URN no insert
             continue;
         }
         $StoreView['origin_unique_id'] = trim($data['CCR_Client_URN']);
         $StoreView['csv_file_uuid'] = $data['Cleaning_UUID'];
         $StoreView['date_imported'] = date('Y-m-d H:i:s');
         //Get organisation id
         switch ($data['CCR_Organisation']) {
             case 'Example 1':
                 $organisation_id = 1;
                 switch ($data['CCR_Email_Allow']) {
                     case 'Allow':
                         $contact_email = 1;
                         break;
                     case 'Do Not Allow':
                         $contact_email = 0;
                         break;
                 }
                 break;
             default:
                 break;
         }
         $StoreView['contact_email'] = $contact_email;
         $StoreView['contact_sms'] = $contact_sms;
         $StoreView['contact_post'] = $contact_post;
         $StoreView['origin_organisation_id'] = $organisation_id;
         $StoreView['salutation'] = $this->emptyToNull($data['CCR_Title']);
         $StoreView['first_name'] = $this->emptyToNull($data['CCR_Forename']);
         $StoreView['last_name'] = $this->emptyToNull($data['CCR_Surname']);
         if (!is_null($StoreView['last_name'])) {
             $StoreView['last_name'] = rtrim(mcrypt_decrypt($this->cipher, $this->key3, base64_decode($StoreView['last_name']), $this->mode, $this->iv));
         }
         $StoreView['address_line_1'] = $this->emptyToNull($data['CCR_Address1']);
         if (!is_null($StoreView['address_line_1'])) {
             $StoreView['address_line_1'] = rtrim(mcrypt_decrypt($this->cipher, $this->key2, base64_decode($StoreView['address_line_1']), $this->mode, $this->iv));
         }
         $StoreView['address_line_2'] = $this->emptyToNull($data['CCR_Address2']);
         $StoreView['address_line_3'] = $this->emptyToNull($data['CCR_Address3']);
         $StoreView['address_line_4'] = $this->emptyToNull($data['CCR_Address4']);
         $StoreView['address_town'] = $this->emptyToNull($data['CCR_Town']);
         $data['CCR_Postcode'] = trim($data['CCR_Postcode']);
         if ($this->isPostcode($data['CCR_Postcode'])) {
             $StoreView['address_postcode'] = $data['CCR_Postcode'];
         } else {
             $StoreView['address_postcode'] = null;
         }
         $StoreView['address_county'] = $this->emptyToNull($data['CCR_County']);
         // phone and mobile
         //regex to to see if provided phone number is mobile
         $phone1 = intval(rtrim(mcrypt_decrypt($this->cipher, $this->key4, base64_decode($data['CCR_Phone1']), $this->mode, $this->iv)));
         $phone2 = intval(rtrim(mcrypt_decrypt($this->cipher, $this->key5, base64_decode($data['CCR_Phone2']), $this->mode, $this->iv)));
         if ($phone1 && $phone2) {
             if ($this->isMobile($phone1)) {
                 $StoreView['mobile'] = $phone1;
                 $StoreView['phone'] = $phone2;
             }
             if ($this->isMobile($phone2)) {
                 $StoreView['mobile'] = $phone2;
                 $StoreView['phone'] = $phone1;
             }
         } else {
             if ($phone1) {
                 if ($this->isMobile($phone1)) {
                     $StoreView['mobile'] = $phone1;
                 } else {
                     $StoreView['phone'] = $phone1;
                 }
             } else {
                 if ($phone2) {
                     if ($this->isMobile($phone2)) {
                         $StoreView['mobile'] = $phone2;
                     } else {
                         $StoreView['phone'] = $phone2;
                     }
                 }
             }
         }
         // end phone and mobile
         // email
         $StoreView->email = $data['CCR_Email'];
         if (!is_null($StoreView->email)) {
             $StoreView->email = rtrim(mcrypt_decrypt($this->cipher, $this->key1, base64_decode($StoreView['email']), $this->mode, $this->iv));
         }
         if (!is_null($StoreView['email']) && !filter_var($StoreView->email, FILTER_VALIDATE_EMAIL)) {
             $StoreView->email = null;
         }
         // end email
         // Save the contact in the store
         if (!$StoreView->validate()) {
             print '$StoreView->errors:' . "\n";
             print_r($StoreView->errors);
         } else {
             $this->totalImported++;
             //in dupe set
             $data['CCR_Ind_Set'] = (int) trim($data['CCR_Ind_Set']);
             /*
             if(this row has (int)CCR_Ind_Set > 0){
             	
             	select existing 1+ duplicates
             
             	if(this row (int)CCR_Ind_Set matches a ccr_duplicate_id with the same organisation_id){
             	
             		// mega dupe
             		if( existing record has 'Yes' for CCR_Ind_Dupe1 ){
             	
             			insert and expire this row
             		}
             		else
             		{
             			expire existing
             			insert this row
             		}
             	}
             	else
             	{
             		// no other rows in same org
             		insert this row
             	}
             }
             else
             {
             	// not a duplicate
             }
             */
             // is this the ccr dupe favoured row?
             $StoreView['ccr_ind_dupe1'] = trim($data['CCR_Ind_Dupe1']) === 'Yes' ? 1 : 0;
             // If CCR has detected a duplicate...
             if ($data['CCR_Ind_Set'] > 0) {
                 $this->totalDupes++;
                 $StoreView->ccr_duplicate_id = $data['CCR_Ind_Set'];
                 //print "CCR_Ind_Set > 0\n";
                 //first of all, let see if the dupe has the same origin id as a previous in the database
                 $DupeMatches = Store::model()->with(array('store2contact'))->findAllByAttributes(array('ccr_duplicate_id' => $data['CCR_Ind_Set'], 'date_expired' => null), array('index' => 'origin_organisation_id'));
                 // print ('starting new loop with dupes');
                 if (sizeof($DupeMatches)) {
                     // print "size DupeMatches > 0\n";
                     $Store2Contact = null;
                     // print_r(array_keys($DupeMatches));
                     // print "\nDupeMatch orgs: " . $organisation_id . "\n";
                     if (array_key_exists((int) $organisation_id, $DupeMatches)) {
                         // we have a match from the same organisation
                         // print "org exists in dupes data\n";
                         //not do in the correct order, needs to be done with CCR_Ind_Set
                         //we need to expire the match and update the warehouse record
                         //we the new one
                         //echo 'DupeMatch';
                         if ($DupeMatches[$organisation_id]->ccr_ind_dupe1) {
                             // print "Alread have trusted row, expire row\n";
                             // already have a trusted row. Expire and insert this one.
                             $StoreView->date_expired = date('Y-m-d H:i:s');
                             $StoreView->ccr_ind_dupe1 = 0;
                             // just in case.
                         } else {
                             // print "Update store row\n";
                             // update store row
                             $DupeMatches[$organisation_id]->date_expired = date('Y-m-d H:i:s');
                             $DupeMatches[$organisation_id]->save();
                             // update any suppression list rows to not have warehouse or store_id. They're old and expired.
                             SuppressionList::model()->deleteAll('store2contact_id = ' . (int) $DupeMatches[$organisation_id]->store2contact->id);
                             // clone the contact_warehouse_id and ind set. Gets saved below.
                             $Store2Contact = $DupeMatches[$organisation_id]->store2contact;
                             // print 'Store2Contact=';
                             // print_r ($Store2Contact->attributes);
                             $Store2Contact->contact_warehouse_id = $DupeMatches[$organisation_id]->store2contact->contact_warehouse_id;
                         }
                     } else {
                         // print "org does not exist in dupes data\n";
                         //is it not a dupe match but someone else has the same dupe id?
                         //if so, lets find their Warehouse ID and then add as a new row
                         $LastDuplicate = end($DupeMatches);
                         $Store2Contact = new Store2Contact();
                         $Store2Contact->contact_warehouse_id = $LastDuplicate->store2contact->contact_warehouse_id;
                     }
                     // the save for dupes is here
                     if (!$StoreView->save()) {
                         print_r($StoreView->errors);
                     }
                     // if we have a store2contact save it here
                     if (!is_null($Store2Contact)) {
                         //update store_id to new one
                         $Store2Contact->store_id = $StoreView->id;
                         $Store2Contact->origin_unique_id = $data['CCR_Client_URN'];
                         $Store2Contact->origin_id = $organisation_id;
                         // print 'saving a (dupe style) store2contact ' . $Store2Contact->id . "\n";
                         if (!$Store2Contact->save()) {
                             print_r($Store2Contact->errors);
                         }
                     }
                     // currently required below.
                     //unset($Store2Contact);
                 }
             }
             // when not a duplicate or there is no other dupe stored yet
             if ($data['CCR_Ind_Set'] == 0 || !sizeof($DupeMatches)) {
                 // save for when no duplicates
                 if (!$StoreView->save()) {
                     print_r($StoreView->errors);
                 }
                 $Warehouse = new Warehouse();
                 if (!$Warehouse->save()) {
                     print_r($Warehouse->errors);
                 }
                 // Create a new Store2Contact row
                 $Store2Contact = new Store2Contact();
                 $Store2Contact->store_id = $StoreView->id;
                 $Store2Contact->contact_warehouse_id = $Warehouse->id;
                 $Store2Contact->origin_unique_id = $data['CCR_Client_URN'];
                 $Store2Contact->origin_id = $organisation_id;
                 if (!$Store2Contact->save()) {
                     print_r($Store2Contact->errors);
                 }
             }
             // Check for non-contactable by email, and add to the supression list
             if ($StoreView->contact_email == 0) {
                 if (!is_null($Store2Contact) && (int) $Store2Contact->id) {
                     $Suppression = new SuppressionList();
                     $Suppression->type = SuppressionList::TYPE_UNSUBSCRIBE;
                     // always save the store id against this row
                     $Suppression->store_id = $StoreView->id;
                     // we have a store2contact row for this person. Add to suppression data.
                     $Suppression->store2contact_id = $Store2Contact->id;
                     //We don't need the warehouse id
                     //$Suppression->warehouse_id = $Store2Contact->contact_warehouse_id;
                     $Suppression->date = date('Y-m-d H:i:s');
                     if ($Suppression->save()) {
                         $suppressionCount++;
                     }
                 }
             }
         }
         unset($data);
         unset($StoreView);
         unset($Store2Contact);
         unset($DupeMatch);
         unset($CodeMatch);
         $this->lastRowProcessed++;
         if (!($this->lastRowProcessed % 100)) {
             $this->completedToNow = $this->lastRowProcessed;
             $timeTotal = microtime(true) - $this->time_start;
             $timeForThis100 = $timeTotal - $this->timeTakenSoFar;
             $this->timeTakenSoFar = $timeTotal;
             $speed = round(1 / $timeForThis100 * 100, 3);
             $currentExecutionTime = round($timeTotal / 60, 2);
             echo $this->lastRowProcessed / 1000 . 'k done in ' . $currentExecutionTime . ' mins. ' . $speed . '  rows/s                    ' . "\r";
         }
     }
     print "\n\n" . $suppressionCount . ' contacts were added to suppression list - not contactable by email' . "\n\n";
 }