コード例 #1
0
 public function actionAdd($id = 0)
 {
     if (!empty($id)) {
         $Custom = Custom::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Custom->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->customs != '1' || $Custom->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->customs != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Custom = new Custom();
     }
     $contacts = User::getContact();
     if (!empty($_POST)) {
         if (!empty($_POST['Custom']['custom_id'])) {
             $Custom = Custom::model()->findByPk($_POST['Custom']['custom_id']);
         } else {
             $Custom = new Custom();
         }
         $Custom->setAttributes($_POST['Custom'], false);
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
         }
         if (!$Custom->validate()) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($Custom, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($Custom));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Custom->user_id = User::createFakeUser($ContentManager);
                 $Custom->contact_id = $Custom->user_id;
             }
             $Custom->save();
             $Custom->setPacking($Custom->custom_id, $_POST['Custom']['packing_id']);
             $Custom->autosearch();
             echo CJSON::encode(array('status' => '500', 'redirect' => '/customsaddsuccess/' . $Custom->custom_id));
             Yii::app()->end();
         }
     }
     $this->render('add', ['Custom' => $Custom, 'contacts' => $contacts, 'ContentManager' => $ContentManager]);
 }
コード例 #2
0
	public function actionGetForm()
	{
		if(isset($_POST['Custom'])){
			$aduit = intval($_POST['Custom']['aduit']);
			$child = intval($_POST['Custom']['child']);
			if(empty($_POST['Custom']['name'])|| empty($_POST['Custom']['namepy'])|| empty($_POST['Custom']['email'])|| empty($_POST['Custom']['tel'])){
				Yii::app()->user->setFlash('alertmsg','联系人姓名,姓名拼音,电话,邮箱必须填写!');
				$this->redirect($this->createUrl('/custom'));
				exit;
			}
			
			$model = new Custom;
			
			$model->type = strip_tags($_POST['Custom']['type']);
			$model->addr_from = strip_tags($_POST['Custom']['addr_from']);
			$model->addr_to = strip_tags($_POST['Custom']['addr_to']);
			$model->departuretime = strtotime($_POST['Custom']['departuretime']);
			$model->budget = floatval($_POST['Custom']['budget']);
			$model->daynumber = intval($_POST['Custom']['daynumber']);
			$model->aduit = $aduit;
			$model->child = $child;
			$model->language = strip_tags($_POST['Custom']['language']);
			$model->ticket = strip_tags($_POST['Custom']['ticket']);
			$model->cartype = strip_tags($_POST['Custom']['cartype']);
			$model->hotel = strip_tags($_POST['Custom']['hotel']);
			$model->eat = strip_tags($_POST['Custom']['eat']);
			$model->attractions = strip_tags($_POST['Custom']['attractions']);
			$model->shop = strip_tags($_POST['Custom']['shop']);
			$model->meet = strip_tags($_POST['Custom']['meet']);
			$model->gender = strip_tags($_POST['Custom']['gender']);
			$model->name = strip_tags($_POST['Custom']['name']);
			$model->namepy = strip_tags($_POST['Custom']['namepy']);
			$model->tel = strip_tags($_POST['Custom']['tel']);
			$model->qq = strip_tags($_POST['Custom']['qq']);
			$model->email = strip_tags($_POST['Custom']['email']);
			$model->replytime = strip_tags($_POST['Custom']['replytime']);
			$model->prireply = strip_tags($_POST['Custom']['prireply']);
			$model->additionmesg = strip_tags($_POST['Custom']['additionmesg']);
			if($model->save(false)){
				Yii::app()->user->setFlash('alertmsg','提交成功,我们会尽快联系您!');
				$this->redirect($this->createUrl('/custom'));
			}else{
				Yii::app()->user->setFlash('alertmsg','提交失败,请重试!');
				$this->redirect($this->createUrl('/custom'));
			}
			
		}else{
			$this->redirect('index');
		}
		die('没有任何数据!');
	}
コード例 #3
0
 /**
  *  обавить
  * @param int $id
  * @param null $delivery
  * @throws CException
  * @throws CHttpException
  */
 public function actionAdd($id = 0, $delivery = null)
 {
     if (!empty($id)) {
         $Cargo = Cargo::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Cargo->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->cargo != '1' || $Cargo->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $AddressesForm = $Cargo->getAddressForm();
         $CostForm = $Cargo->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->cargo != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Cargo = new Cargo();
         $AddressesForm = new AddressesForm();
         if (isset($delivery)) {
             $product = Product::model()->findByPk($delivery);
             $AddressesForm->from_1_name = $product->getEavAttribute('adres_name');
             $AddressesForm->from_1_address_lat = $product->getEavAttribute('adres_adress_lat');
             $AddressesForm->from_1_address_long = $product->getEavAttribute('adres_adress_long');
             $AddressesForm->from_1_ind = '';
         }
         $CostForm = new CostForm();
     }
     $contacts = User::getContact();
     $Cargo->contact_id = Yii::app()->user->id;
     if (!empty($_POST)) {
         $Cargo->setAttributes($_POST['Cargo'], false);
         $AddressesForm->setAttributes($_POST['AddressesForm'], false);
         if ($Cargo->price_asc == '0') {
             $CostForm->setAttributes($_POST['CostForm'], false);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $AddressesForm->validate();
         $valid = $Cargo->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($Cargo, $AddressesForm, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($Cargo, $AddressesForm, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Cargo->user_id = User::createFakeUser($ContentManager);
                 $Cargo->contact_id = $Cargo->user_id;
             }
             $Cargo->save();
             $_POST['Cargo']['type_transport'] = '';
             if (isset($Cargo->transport_type_id)) {
                 switch ($Cargo->transport_type_id) {
                     case 20:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['sea_transport'];
                         break;
                     case 21:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['zhd_transport'];
                         break;
                     case 22:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['air_transport'];
                         break;
                     case 72:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['river_transport'];
                         break;
                     default:
                         break;
                 }
             }
             $Cargo->setRelations($_POST['Cargo']);
             $Cargo->setAddress($AddressesForm);
             $Cargo->setCost($CostForm);
             $Cargo->autosearch();
             if ($_POST['Cargo']['customs_clearance'] == 1) {
                 if ($_POST['AddressesForm']['from_1_ind'] == 'RU') {
                     $_POST['AddressesForm']['from_1_ind'] = 'RUS';
                 }
                 if ($_POST['AddressesForm']['to_1_ind'] == 'RU') {
                     $_POST['AddressesForm']['to_1_ind'] = 'RUS';
                 }
                 if ($_POST['AddressesForm']['from_1_ind'] == 'CH') {
                     $_POST['AddressesForm']['from_1_ind'] = 'CHE';
                 }
                 if ($_POST['AddressesForm']['to_1_ind'] == 'CH') {
                     $_POST['AddressesForm']['to_1_ind'] = 'CHE';
                 }
                 $from = DictionaryData::model()->findByAttributes(['code' => $_POST['AddressesForm']['from_1_ind']]);
                 $to = DictionaryData::model()->findByAttributes(['code' => $_POST['AddressesForm']['to_1_ind']]);
                 $Custom = new Custom();
                 $Custom->type_id = $_POST['Cargo']['name_id'];
                 $Custom->packing_id = $_POST['Cargo']['packing_id'];
                 $Custom->country_from = isset($from) ? $from->id : 0;
                 $Custom->country_to = isset($to) ? $to->id : 0;
                 $Custom->weight_netto = $_POST['Cargo']['weight'];
                 $Custom->weight_brutto = $_POST['Cargo']['weight'];
                 $Custom->volume = $_POST['Cargo']['volume'];
                 $Custom->date_from = $_POST['Cargo']['when_from'];
                 $Custom->date_to = $_POST['Cargo']['when_to'];
                 $Custom->user_id = Yii::app()->user->id;
                 $Custom->contact_id = $_POST['Cargo']['contact_id'];
                 $Custom->save();
                 $Custom->autosearch();
             }
             if ($_POST['Cargo']['cargo_insurance'] == 1) {
                 $addrId = Yii::app()->db->createCommand()->select('address_id')->from('site_cargo_address u')->where('cargo_id=:cargo_id', array(':cargo_id' => $Cargo->cargo_id))->order('cargo_id ASC')->limit(1)->queryRow();
                 $addr = Address::model()->findByPk($addrId);
                 $Insurance = new Insurance();
                 $Insurance->category_id = 147;
                 $Insurance->address_id = $addr->address_id;
                 $Insurance->description = '';
                 $Insurance->contact_id = $_POST['Cargo']['contact_id'];
                 $Insurance->create = date('Y-m-d H:i:s');
                 $Insurance->user_id = Yii::app()->user->id;
                 $Insurance->date_to = $_POST['Cargo']['when_to'] != '' ? $_POST['Cargo']['when_to'] : '0000-00-00';
                 $Insurance->save();
                 $Insurance->autosearch();
             }
             echo CJSON::encode(array('status' => '500', 'redirect' => '/cargoaddsuccess/' . $Cargo->cargo_id));
             Yii::app()->end();
         }
     }
     $DictionaryData = \DictionaryData::model()->findAll('group_id=3');
     $this->render('add', ['Cargo' => $Cargo, 'addreses' => $AddressesForm, 'CostForm' => $CostForm, 'contacts' => $contacts, 'ContentManager' => $ContentManager, 'DictionaryData' => $DictionaryData]);
 }