Example #1
0
	public function actionSaveinfo()
	{
		if(isset($_POST['term']))
		{
			//检查参数
			$arr = $this->ajaxCheckParm();
			$code = $arr['route'];
			$orderModel = $this->getOrderByRandCode($code);
			
			if($orderModel->updatetime != 0){
				echo json_encode($arr);
				exit;
			}
			
			
			$now =time();
			//防止重复提交,五秒内只能提交一次
			if(isset(Yii::app()->session['submitrepeat'])&&Yii::app()->session['submitrepeat']>($now-7)){
				$arr['statuCode'] = 302;
				$arr['msg'] = '五秒内,请不要重复提交!';
				echo json_encode($arr);
				exit;
			}else{
				Yii::app()->session['submitrepeat'] = $now;
			}
			
			//验证表单项是否为空
			$verflag = false;
			foreach($_POST['Contacter'] as $key=>$value){
				switch($key)
				{
					case 'name':
						empty($value)&&($verflag = true)?$arr['msg'] = '请填写您的姓!':'';break;
					case 'first':
						empty($value)&&($verflag = true)?$arr['msg'] = '请填写您的名!':'';break;
					case 'moblie':
						empty($value)&&($verflag = true)?$arr['msg'] = '请填写您的手机号码!':'';break;
					case 'email':
						empty($value)&&($verflag = true)?$arr['msg'] = '请填写您的邮箱!':'';break;
					case 'addr':
						empty($value)&&($verflag = true)?$arr['msg'] = '请填写您的地址!':'';break;
				}
			}
			
			if($verflag){
				echo json_encode($arr);
				exit;
			}
			$mid = 0;//Yii::app()->session['myuserid'];判断是否登录//会员ID
			if(isset(Yii::app()->session['myuserid'])){
				$mid = Yii::app()->session['myuserid'];
			}
			//存储联系人
			//过滤参数
			foreach($_POST['Contacter'] as $key=>$value){
				$_POST['Contacter'][$key] = strip_tags($value);
			}
			//判断是否存在该会员关联的联系人,如果存在则跟新,不存在则添加
			$CModel = Contacter::model()->find(array('condition'=>"mid=$mid and mid<>0"));
			if($CModel == null){//未登录
				$CModel = new Contacter;
				//自动注册,添加email,fullname,first,gender,tel,address到会员表
				$registerModel = new Member;
				$registerModel->email = strip_tags($_POST['Contacter']['email']);
				$registerModel->password = md5('123456');
				$registerModel->fullname = strip_tags($_POST['Contacter']['name']);
				$registerModel->first = strip_tags($_POST['Contacter']['first']);
				$registerModel->gender = intval($_POST['Contacter']['gender']);
				$registerModel->tel = intval($_POST['Contacter']['moblie']);
				$registerModel->address = strip_tags($_POST['Contacter']['addr']);
				$registerModel->createtime = $now;
				$registerModel->updatetime = $now;
				$registerModel->flag = 1;
				if($registerModel->save(false)){
					//注册成功,自动登录
					$CModel->mid = $registerModel->id;
					$loginModel = new LoginForm;
					$loginModel->username = $registerModel->email;
					$loginModel->password = '******';
					$loginModel->login();//登录
				}else{
					$CModel->mid = $mid;
				}
			}
			$CModel->name = strip_tags($_POST['Contacter']['name']);
			$CModel->first = strip_tags($_POST['Contacter']['first']);
			$CModel->gender = intval($_POST['Contacter']['gender']);
			$CModel->moblie = strip_tags($_POST['Contacter']['moblie']);
			$CModel->phone = strip_tags($_POST['Contacter']['phone']);
			$CModel->email = strip_tags($_POST['Contacter']['email']);
			$CModel->wechat = strip_tags($_POST['Contacter']['wechat']);
			$CModel->qq = strip_tags($_POST['Contacter']['qq']);
			/* $CModel->whatup = strip_tags($_POST['Contacter']['whatup']); */
			$CModel->addr = strip_tags($_POST['Contacter']['addr']);
			$CModel->createtime = $now;
			if(!$CModel->save(false))
			{
				$arr['statuCode'] = 302;
				$arr['msg'] = '请正确提交表单信息!';
			}else{
				$cid = $CModel->id;//联系人ID
				//将信息添加到订单表
				//$travelModel = Travel::model()->findByPk($tid);

				$orderModel->mid = $mid;
				$orderModel->cid = $cid;//联系人表 contracter 自增ID
				$orderModel->donate = $this->getDonatePrice('donate'.$orderModel->id);
				$orderModel->additionmesg = strip_tags($_POST['addimsg']);
				$orderModel->howway = $_POST['callme'] == 1?strip_tags($_POST['otherway']):strip_tags($_POST['callme']);
				$orderModel->updatetime = $now;

				if(!$orderModel->save(false)){
					$arr['statuCode'] = 302;
					$arr['msg'] = '提交订单不成功,请重试!---订单保存不成功';
				}else{
					$oid = $orderModel->id;
					
					for($i=0;$i<count($_POST['name']);$i++){
						$clientModel = new Client;
						$clientModel->oid = $oid;
						$clientModel->name = strip_tags($_POST['name'][$i]);
						$clientModel->first = strip_tags($_POST['first'][$i]);
						$clientModel->gender = strip_tags($_POST['gender'][$i]);
						$clientModel->national = strip_tags($_POST['national'][$i]);
						$clientModel->dob = strtotime($_POST['dob'][$i]);
						$clientModel->passpost = strip_tags($_POST['passpost'][$i]);
						/* $clientModel->expiration = strtotime($_POST['expiration'][$i]); */
						$clientModel->createtime = $now;
						$clientModel->save();
					}
					
					$additoninfo = $this->additionList($orderModel->tid);
					$addsToken = 'adds'.$orderModel->id;
					$addArr = $this->checkAdditionsStep($addsToken);
					if(empty($addArr)){
						$addArr[1] = array();
					}
					foreach($addArr[1] as $key=>$value){
						if($value > 0){
							$OAModel = new OrderAdditional;
							$OAModel->oid = $oid;
							$aid = $addArr[0][$key];
							$OAModel->name = $additoninfo[$aid]['name'];
							$OAModel->num = $value;
							$OAModel->price = $additoninfo[$aid]['price'];
							$OAModel->createtime = $now;
							$OAModel->save();
						}
					}
					
					//存储保险信息
					$insToken = 'ins'.$orderModel->id;
					$insurancesid = $this->getInsuranceId($insToken);
					if($insurancesid!=0){
						$insuranceArr = $this->getNowInsurance($insurancesid);
						$insModel = new OrderInsurance;
						$insModel->oid = $oid;
						$insModel->name = $insuranceArr['name'];
						$insModel->price = $insuranceArr['price'];
						$insModel->save(false);
					}
					
					//将房间信息存储到订单相应下的房间表中
					$token = 'order'.$orderModel->id;
					$roomArr = $this->checkOrderRoomStep($token);
					$roPriceArr = $this->getHousePrice();
					foreach($roomArr['type'] as $ke=>$val){
						$rModel = new OrderRoom;
						$rModel->oid = $oid;
						$rModel->aduit = $roomArr['aduit'][$ke];
						$rModel->child = $roomArr['child'][$ke];
						$rModel->type = $this->getHouseName($val);
						$arprice = ($roPriceArr[$val][0]) * ($roomArr['aduit'][$ke]);
						$crprice = ($roPriceArr[$val][1]) * ($roomArr['child'][$ke]);
						$rModel->price = $arprice + $crprice;
						$rModel->save(false);
					}
					
					//发送邮件给客户
					if(isset(Yii::app()->session['mysueremail'])){
						$useremail = Yii::app()->session['mysueremail'];
						/* $username = Yii::app()->user->name; */
					}else{
						$useremail = strip_tags($_POST['Contacter']['email']);
						/* $username = strip_tags($_POST['Contacter']['name']); */
					}
					$message = array('email'=>$useremail,'ordernumber'=>$orderModel->trackcode);
					
					$this->sendEmail($useremail,$message);
				}
			}
		 	}else{
				$arr['statuCode'] = 302;
				$arr['msg'] = '合同条款必须同意!';
			}
		echo json_encode($arr);
		exit;
	}