Beispiel #1
0
function testSendFormatedMessage()
{
    $msgNo = time() + 1;
    /*
     格式化的打印内容
    */
    $msgInfo = array('memberCode' => MEMBER_CODE, 'charge' => '3000', 'orderNo' => '11111', 'customerName' => '何青', 'customerPhone' => '15037110261', 'customerAddress' => '河南农业大学', 'customerMemo' => '备注', 'msgDetail' => '番茄炒粉@100@2||客家咸香鸡@2000@1', 'deviceNo' => DEVICE_NO, 'msgNo' => $msgNo);
    echo sendFormatedMessage($msgInfo);
    return $msgNo;
}
Beispiel #2
0
function testSendFormatedMessage()
{
    $msgNo = time() + 1;
    /*
     格式化的打印内容
    */
    $msgInfo = array('memberCode' => MEMBER_CODE, 'charge' => '3000', 'customerName' => '刘小姐', 'customerPhone' => '13321332245', 'customerAddress' => '五山华南理工', 'customerMemo' => '请快点送货', 'msgDetail' => '番茄炒粉@1000@1||客家咸香鸡@2000@1', 'deviceNo' => DEVICE_NO, 'msgNo' => $msgNo);
    echo sendFormatedMessage($msgInfo);
    return $msgNo;
}
	public function orderCart(){
		if (isset($_GET['cartIsDining'])&&intval($_GET['cartIsDining'])){
			$cartIsDining=1;
			$this->assign('cartIsDining',1);
		}
		$userinfo_model=M('Userinfo');
		$thisUser=$userinfo_model->where(array('token'=>$this->token,'wecha_id'=>$this->wecha_id))->find();
		$this->assign('thisUser',$thisUser);
		//是否要支付
		$alipay_config_db=M('Alipay_config');
		$alipayConfig=$alipay_config_db->where(array('token'=>$this->token))->find();
		$this->assign('alipayConfig',$alipayConfig);
		//
		if (IS_POST){
			$row=array();
			$carts=$this->_getCart();
			//
			$allCartInfo=$this->calCartInfo($carts);
			$totalFee=$allCartInfo[1];
			//
			$cartsCount=0;
			//
			$isGroupon=0;
			$productids=array();
			foreach ($carts as $k=>$c){
				array_push($productids,$k);
			}
			//把团购、普通购物和餐饮分开
			$normalCart=array();
			$grouponCart=array();
			$diningCart=array();
			$productsByKey=array();
			//
			$orderName='';
			if (count($productids)){
				$products=$this->product_model->where(array('id'=>array('in',$productids)))->select();
				if ($products){
					$t=0;
					foreach ($products as $p){
						$productsByKey[$p['id']]=$p;
						if ($t==0){
							$orderName=$p['name'];
						}
						$t++;
					}
				}
				foreach ($carts as $k=>$c){
					$thisProduct=$productsByKey[$k];
					if ($thisProduct['groupon']==1){
						$grouponCart[$k]=$c;
						$carts[$k]['type']='groupon';
					}else {
						if ($thisProduct['dining']==1){
							$diningCart[$k]=$c;
							$carts[$k]['type']='dining';
						}else {
							$normalCart[$k]=$c;
							$carts[$k]['type']='normal';
						}
					}
					$cartsCount++;
				}
			}
			$orderid=$this->wecha_id.time();
			$row['orderid']=$orderid;
			$orderid=$row['orderid'];
			//
			$row['truename']=$this->_post('truename');
			$row['tel']=$this->_post('tel');
			$row['address']=$this->_post('address');
			
			
			$row['token']=$this->token;
			$row['wecha_id']=$this->wecha_id;
			if (!$row['wecha_id']){
				$row['wecha_id']='null';
			}
			//
			$buytimestamp=$this->_post('buytimestamp');//购买时间
			if ($buytimestamp){
				$row['year']=date('Y',$buytimestamp);
				$row['month']=date('m',$buytimestamp);
				$row['day']=date('d',$buytimestamp);
				$row['hour']=$this->_post('hour');
			}
			$time=time();
			$row['time']=$time;
			//分别加入3类订单
			$orderids=array();//用于存储插入的各类订单id
			$product_cart_model=M('product_cart');
			if ($cartsCount){
				if (count($grouponCart)){
					$calCartInfo=$this->calCartInfo($grouponCart);
					$row['total']=$calCartInfo[0];
					$row['price']=$calCartInfo[1];
					$row['diningtype']=0;
					$row['buytime']='';
					$row['tableid']=0;
					$row['info']=serialize($grouponCart);
					//
					$row['groupon']=1;
					$row['dining']=1;
					$groupon_rt=$product_cart_model->add($row);
					$orderids['groupon']=$groupon_rt;
				}
				if (count($diningCart)){
					$calCartInfo=$this->calCartInfo($diningCart);
					$row['total']=$calCartInfo[0];
					$row['price']=$calCartInfo[1];
					//
					$row['diningtype']=intval($this->_post('diningtype'));
					$row['buytime']=$buytimestamp?$row['month'].'月'.$row['day'].'日'.$row['hour'].'点':'';
					$row['tableid']=intval($this->_post('tableid'));
					$row['info']=serialize($diningCart);
					//
					$row['groupon']=0;
					$row['dining']=1;
					$dining_rt=$product_cart_model->add($row);
					$orderids['dining']=$dining_rt;
				}
				if (count($normalCart)){
					$calCartInfo=$this->calCartInfo($normalCart);
					$row['total']=$calCartInfo[0];
					$row['price']=$calCartInfo[1];
					//
					$row['diningtype']=0;
					$row['buytime']='';
					$row['tableid']=0;
					$row['info']=serialize($normalCart);
					//
					$row['groupon']=0;
					$row['dining']=0;
					$normal_rt=$product_cart_model->add($row);
					$orderids['normal']=$normal_rt;
				}
			}else {
				if (intval($this->_post('tableid'))&&$this->_post('buytimestamp')){//只是预定餐桌
					$row['total']=0;
					$row['price']=0;
					//
					$row['diningtype']=intval($this->_post('diningtype'));
					$row['buytime']=$buytimestamp?$row['month'].'月'.$row['day'].'日'.$row['hour'].'点':'';
					$row['tableid']=intval($this->_post('tableid'));
					$row['info']=serialize($diningCart);
					//
					$row['groupon']=0;
					$row['dining']=1;
					$orderDining_rt=$product_cart_model->add($row);
				}
			}
			//
			if ($normal_rt||$groupon_rt||$dining_rt||$orderDining_rt){
				$product_model=M('product');
				$product_cart_list_model=M('product_cart_list');
				$crow=array();
				if ($cartsCount){
					foreach ($carts as $k=>$c){
						$crow['cartid']=intval($orderids[$c['type']]);
						$crow['productid']=$k;
						$crow['price']=$c['price'];
						$crow['total']=$c['count'];
						$crow['wecha_id']=$row['wecha_id'];
						$crow['token']=$row['token'];
						$crow['time']=$time;
						$product_cart_list_model->add($crow);
						$product_model->where(array('id'=>$k))->setInc('salecount',$c['count']);
					}
				}
				$_SESSION[$this->session_cart_name]='';
				//保存个人信息
				if ($_POST['saveinfo']){
					$userRow=array('tel'=>$row['tel'],'truename'=>$row['truename'],'address'=>$row['address']);
					if ($thisUser){
						$userinfo_model->where(array('id'=>$thisUser['id']))->save($userRow);
					}else {
						$userRow['token']=$this->token;
						$userRow['wecha_id']=$this->wecha_id;
						$userRow['wechaname']='';
						$userRow['qq']=0;
						$userRow['sex']=-1;
						$userRow['age']=0;
						$userRow['birthday']='';
						$userRow['info']='';
						//
						$userRow['total_score']=0;
						$userRow['sign_score']=0;
						$userRow['expend_score']=0;
						$userRow['continuous']=0;
						$userRow['add_expend']=0;
						$userRow['add_expend_time']=0;
						$userRow['live_time']=0;
						$userinfo_model->add($userRow);
					}
				}
				
			}
			

//短信模块
$info=M('Wxuser')->where(array('token'=>$this->token))->find();
$phone=$info['phone'];

$user=$info['smsuser'];//短信平台帐号
$pass=md5($info['smspassword']);//短信平台密码
$smsstatus=$info['smsstatus'];//短信平台状态

$content = $this->sms();

if ($smsstatus == 1) {
    if ($content) {
    	//如果你换了短信,请在这里修改
        $smsrs = file_get_contents('http://api.smsbao.com/sms?u='.$user.'&p='.$pass.'&m='.$phone.'&c='.urlencode($content));
    }
}
// 结束

// 增加 发送邮件

$email=$info['email'];
$emailuser=$info['emailuser'];
$emailpassword=$info['emailpassword'];
$emailstatus=$info['emailstatus'];

if ($emailstatus == 1) {
    if ($content) {
        date_default_timezone_set('PRC');
        require_once 'class.phpmailer.php';
        //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
        $mail = new PHPMailer();
        $body = $content;
        $mail->IsSMTP();
        // telling the class to use SMTP
        $mail->Host = 'smtp.qq.com';
        // SMTP server
        $mail->SMTPDebug = '1';
        // enables SMTP debug information (for testing)
        // 1 = errors and messages
        // 2 = messages only
        $mail->SMTPAuth = true;
        // enable SMTP authentication
        $mail->Host = 'smtp.qq.com';
        // sets the SMTP server
        $mail->Port = 25;
        // set the SMTP port for the GMAIL server
        $mail->Username = $emailuser;
        // SMTP account username
        $mail->Password = $emailpassword;
        // SMTP account password
        $mail->SetFrom($emailuser.'@qq.com', '微信平台');
        $mail->AddReplyTo($emailuser.'@qq.com', '微信平台');
        $mail->Subject = '客户订单';
        $mail->AltBody = '';
        // optional, comment out and test
        $mail->MsgHTML($body);
        $address = $email;
        $mail->AddAddress($address, '商户');
        $emailrs = $mail->Send();

    }
}

// 结束

//增加无线打印
$member_code = $info['member_code'];
$feiyin_key = $info['feiyin_key'];
$device_no = $info['device_no'];
$printstatus = $info['printstatus'];
if ($printstatus == '1') {
	if ($content) {
		//无线打印处理方法
		date_default_timezone_set('PRC');
        require_once 'HttpClient.class.php';
		function sendMessage($msgInfo) {
			//print_r($msgInfo);
			$client = new HttpClient("my.feyin.net","80");
			if(!$client->post('/api/sendMsg',$msgInfo)){ //提交失败
				//return 'faild';
			}else{
				//echo "发送完成!";
				$client->getContent();
				
			}
			//die();
		}
		function sendFormatedMessage($msgInfo,$feiyin_key) {

			$msgInfo['reqTime'] = number_format(1000*time(), 0, '', '');
			$content = $msgInfo['memberCode'].$msgInfo['customerName'].$msgInfo['customerPhone'].$msgInfo['customerAddress'].$msgInfo['customerMemo'].$msgInfo['msgDetail'].$msgInfo['deviceNo'].$msgInfo['msgNo'].$msgInfo['reqTime'].$feiyin_key;

			$msgInfo['securityCode'] = md5($content);
			$msgInfo['mode']=1;
			
			return sendMessage($msgInfo);
		}
		switch ($row['diningtype']){
		case 0:
			$orderType='购物';
			break;
		case 1:
			$orderType='点餐';
			break;
		case 2:
			$orderType='外卖';
			break;
		case 3:
			$orderType='预定餐桌';
			break;
		}
		
		//订餐信息
		$product_diningtable_model=M('product_diningtable');
		if ($row['tableid']) {
			$thisTable=$product_diningtable_model->where(array('id'=>$row['tableid']))->find();
			$row['tableName']=$thisTable['name'];
		}else{
			$row['tableName']='未指定';
		}
		$customerMemo="订单类型:".$orderType." 编号:".$row['orderid']." 桌台:".$row['tableName']." 时间:".date('Y-m-d H:i:s',$row['time']);
		//
		$msgInfo['memberCode'] = $info['member_code'];
		$msgInfo['charge'] = $row['price']*100;
		$msgInfo['customerName'] = $row['truename'];
		$msgInfo['customerPhone'] = $row['tel'];
		$msgInfo['customerAddress'] = $row['address'];
		$msgInfo['customerMemo'] = 	$customerMemo;
		//$msgInfo['customerMemo'] = 	'';
		$msgInfo['msgDetail'] = $this->print_txt();
		$msgInfo['deviceNo'] = $info['device_no'];
		$msgInfo['msgNo'] = time()+1;

		sendFormatedMessage($msgInfo,$info['feiyin_key']);
	}
}
//结束
			
			//不为0则可以进行支付
			if ($alipayConfig['open']!=0){
				$this->redirect(U('Alipay/pay',array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'success'=>1,'price'=>$totalFee,'orderName'=>$orderName,'orderid'=>$orderid)));
			}else {
				$this->redirect(U('Product/my',array('token'=>$_GET['token'],'wecha_id'=>$_GET['wecha_id'],'success'=>1)));
			}
			/*
			if ($alipayConfig['open']==1){
				$this->redirect(U('Alipay/pay',array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'success'=>1,'price'=>$totalFee,'orderName'=>$orderName,'orderid'=>$orderid)));
			}
			if (($alipayConfig['open']==2) || ($alipayConfig['open']==3)){
			$this->redirect(U('Tenpay/pay',array('token'=>$this->token,'wecha_id'=>$this->wecha_id,'success'=>1,'price'=>$totalFee,'orderName'=>$orderName,'orderid'=>$orderid)));}
			if ($alipayConfig['open']==0){
				$this->redirect(U('Product/my',array('token'=>$_GET['token'],'wecha_id'=>$_GET['wecha_id'],'success'=>1)));
			}
			*/
		}else {
			//如果是订餐
			if ($cartIsDining){
				//是否外卖预定等
				$diningConfig =M('Reply_info')->where(array('infotype'=>'Dining','token'=>$this->token))->find();
				$this->assign('diningConfig',$diningConfig);
				//可以预定多少天内的
				$diningConfigDetail=unserialize($diningConfig['config']);
				if (!$diningConfigDetail||!$diningConfigDetail['yudingdays']){
					$days=7;
				}else {
					$days=$diningConfigDetail['yudingdays'];
				}
				$time=time();
				$secondsOfDay=24*60*60;
				$dateTimes=array();
				for ($i=0;$i<$days;$i++){
					array_push($dateTimes,$time+$i*$secondsOfDay);
				}
				$this->assign('dateTimes',$dateTimes);
				//
				$orderHour=date('H',$time);
				$this->assign('orderHour',$orderHour);
				$hours=array();
				for ($i=0;$i<24;$i++){
					array_push($hours,$i);
				}
				$this->assign('hours',$hours);
				//
				$product_diningtable_model=M('Product_diningtable');
				$tables=$product_diningtable_model->where(array('token'=>$_GET['token']))->order('taxis ASC')->select();
				$this->assign('tables',$tables);
			}
			//
			$this->assign('metaTitle','购物车结算');
			$this->display();
		}
	}