コード例 #1
0
 function sendcouponAction()
 {
     $this->_helper->layout->setLayout("layout_coupon");
     $currentTime = date("Y-m-d H:i:s");
     $endTime = date("Y年m月d日", strtotime("+7 day"));
     $couponId = (int) $this->_request->getParam('uid');
     //$message = $this->getCouponById($couponId);
     //var_dump($_SERVER['HTTP_REFERER']);die;
     $lou = 0;
     if (isset($_SERVER['HTTP_REFERER']) && preg_match('/19lou/', $_SERVER['HTTP_REFERER'])) {
         $lou = 1;
         $_SESSION['19lou'] = 1;
     }
     if (isset($_SESSION['19lou'])) {
         $lou = 1;
     }
     //var_dump($_SESSION);die;
     $this->view->message = array();
     $this->view->coupon = $couponId;
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         if (trim($formData['username']) == '') {
             $this->view->message['username'] = '******';
         }
         if (trim($formData['telephone']) == '') {
             $this->view->message['telephone'] = '手机号码不能为空。';
         }
         if (trim($couponId) == '') {
             $this->view->message['coupon'] = '没有对应的优惠券。';
         }
         $this->view->postData = $formData;
         if (trim($formData['telephone']) != '' && $this->validateSend($formData['telephone'], $couponId, $lou)) {
             $this->view->message['got'] = '已经领取优惠券或同一天固定IP只能领取一份。';
         }
         //print_r($formData);die;
         if (!count($this->view->message)) {
             $newclient = new SMS();
             if ($newclient->ConfNull == "1") {
                 $mobile = $formData['telephone'];
                 $message = $this->getCouponById($couponId);
                 $time = $currentTime;
                 //echo str_replace('{date}',$endTime,$message['content']);die;
                 $apitype = 3;
                 // $apitype 通道选择 0:默认通道; 2:通道2; 3:即时通道;
                 $msg = iconv("UTF-8", "GB2312", str_replace('{date}', $endTime, $message['content']));
                 //				Zend_Debug::dump($msg);
                 $respxml = $newclient->sendSMS($mobile, $msg, $time, $apitype);
                 //print_r($newclient->sendXML);die();
                 $smsSpace = new Zend_Session_Namespace('SMS');
                 $smsSpace->xml = $newclient->sendXML;
                 $smsSpace->respxml = $respxml;
                 $this->view->code = $newclient->getCode();
                 if ($this->view->code == 2000) {
                     $this->view->message['susess'] = "成功领取优惠券.";
                     //add the coupon history
                     $db = Zend_Registry::get('db');
                     $insetSql = $db->prepare("insert into coupon_history(telephone,ip,crdate,cuid) values ('{$formData['telephone']}','{$_SERVER['REMOTE_ADDR']}','{$currentTime}',{$couponId})");
                     $insetSql->execute();
                 } else {
                     $this->view->message['telephone'] = '手机号码可能不正确。';
                 }
             } else {
                 $this->view->message['fail'] = "失败";
                 $this->view->message['noconfig'] = "你还没有配置文件";
             }
         }
     }
 }