/**
  * 获取邮件
  */
 public function ActionSaveEmail()
 {
     echo explode('在', '27/07/2014 在 18:00')[0];
     exit;
     print_r(explode('在', '27/07/2014 在 18:00'));
     exit;
     $CarrentalEmail = new CarrentalEmail();
     $CarrentalEmail->save_email();
 }
Esempio n. 2
0
 public function save_email()
 {
     $obj = new Email();
     $obj->receiveMail('*****@*****.**', '1234567a', '*****@*****.**', 'pop3.baicheng.com', 'pop3', '110', false);
     // 链接邮箱服务器
     $obj->connect();
     // 获取邮件总数
     $tot = $obj->getTotalMails();
     if ($tot > 0) {
         // 循环获取每一封邮件
         for ($i = $tot; $i > 0; $i--) {
             // 获取邮件头
             $head = $obj->getHeaders($i);
             /****** 根据模板生成正式租车订单xls [S] ******/
             // 租车订单附件 - 模板路径
             $templet_path = CARRENTAL_ORDER_PATH . 'Templet/Templet.xls';
             // 租车订单附件 - 正式路径
             $order_path = CARRENTAL_ORDER_PATH . date('Y-m-d', time()) . '/';
             // 如正式路径不存在则创建
             if (!file_exists($order_path)) {
                 if (!DirectoryFile::dirCreate($order_path)) {
                     exit('创建目录失败!');
                 }
             }
             // 如模板文件存在则复制到正式路径下
             if (file_exists($templet_path)) {
                 // 生成附件名称
                 $attachment_name = 'order_' . time() . '.xls';
                 // 复制租车订单模板至正式目录下
                 $status = @copy($templet_path, $order_path . $attachment_name);
                 if (!$status) {
                     exit('模板文件移动失败!');
                 }
             } else {
                 exit('订单模板文件不存在!');
             }
             // 引入PHPExcel扩展
             Yii::createComponent('application.extensions.excel.PHPExcel');
             // 实例化Excel读取类
             $PHPReader = new PHPExcel_Reader_Excel5();
             // 读取Excel工作表
             $PHPExcel = $PHPReader->load($order_path . $attachment_name);
             $currentSheet = $PHPExcel->getSheet(0);
             // 获取订单邮件内容
             $email_content = $obj->getBody($i);
             // 拆分订单邮件
             $order_id = $this->email_explode('<font style="color: #444444; font-family: Arial, Helvetica, sans-serif; font-size: 16px; text-transform: uppercase; font-weight: bold;">', $email_content);
             // 拆分出订单号
             $car_detail = $this->email_explode('<font style="color: #666666; font-family: Arial, Helvetica, sans-serif; font-size: 12px;">', $email_content);
             // 拆分出车辆信息
             $other_detail = $this->email_explode('<font style="color: #666666; font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px;">', $email_content);
             // 拆分出其它信息 [费用明细 、车行、您的细节、取车、还车、涵盖范围 等...]
             $email_detail = array_merge($order_id, $car_detail, $other_detail);
             // 合并成完整的订单信息
             /*print_r($email_detail);
               exit();*/
             // 写入单元格内容
             $currentSheet->setCellValue('B3', $email_detail[0]);
             // 预定号[reservation number]
             $currentSheet->setCellValue('D3', $email_detail[13]);
             // 确认号码[confirmation number]
             $currentSheet->setCellValue('B5', $email_detail[15]);
             // 租车人姓名[Name]
             $currentSheet->setCellValue('D5', $email_detail[16]);
             // 航班号码[Flight number]
             $currentSheet->setCellValue('B19', $email_detail[11]);
             // 车辆代码[Car Code]
             $currentSheet->setCellValue('D19', $email_detail[2]);
             // 车门数[Doors]
             $currentSheet->setCellValue('D22', $email_detail[3]);
             // 空调[Air Con]
             $currentSheet->setCellValue('D20', $email_detail[1]);
             // 座位数[Car Seats]
             $currentSheet->setCellValue('B9', trim(explode('在', $email_detail[17])[0]));
             // 取车日期
             $currentSheet->setCellValue('B10', trim(explode('在', $email_detail[17])[1]));
             // 取车时间
             $currentSheet->setCellValue('B11', $email_detail[18]);
             // 取车门店[Location]
             $currentSheet->setCellValue('B12', $email_detail[19]);
             // 取车地址[Address]
             $currentSheet->setCellValue('B13', $email_detail[21]);
             // 取车地电话[Tel]
             $currentSheet->setCellValue('D9', trim(explode('在', $email_detail[23])[0]));
             // 还车日期
             $currentSheet->setCellValue('D10', trim(explode('在', $email_detail[23])[1]));
             // 还车时间
             $currentSheet->setCellValue('D11', $email_detail[24]);
             // 还车门店[Location]
             $currentSheet->setCellValue('D12', $email_detail[25]);
             // 还车地址[Address]
             $currentSheet->setCellValue('D13', $email_detail[27]);
             // 还车地电话[Tel]
             $currentSheet->setCellValue('B23', $email_detail[13]);
             // 确认号码[confirmation number]
             // 实例化Excel写入类
             $PHPWriter = new PHPExcel_Writer_Excel5($PHPExcel);
             // 生成订单附件
             $PHPWriter->save(iconv('utf-8', 'gbk', $order_path . $attachment_name));
             echo '<script language="javascript" type="text/javascript">window.top.window.stopUpload(1);</script>';
             /****** 根据模板生成正式租车订单xls [E] ******/
             // 填充模型
             $carrentalemail = new CarrentalEmail();
             $carrentalemail->title = $head;
             $carrentalemail->content = $email_content;
             $carrentalemail->status = 1;
             $carrentalemail->attachment_path = $order_path . $attachment_name;
             $carrentalemail->create_time = date('Y-m-d H:i:s', time());
             // 开启事务
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 // 保存成功则生成租车订单附件并发送
                 if ($carrentalemail->save()) {
                     // 发送邮件
                     $status = Email::sendEmail('*****@*****.**', '租车订单', $carrentalemail->content, 'smtp.baicheng.com', '*****@*****.**', '1234567a', array($order_path . $attachment_name, $attachment_name));
                     // 发送成功后删除邮件
                     if ($status) {
                         //                            $obj->deleteMails($i);
                     } else {
                         throw new Exception('发送邮件失败!');
                     }
                 } else {
                     throw new Exception('邮件数据保存失败!');
                 }
                 $transaction->commit();
                 // 提交事务
             } catch (Exception $e) {
                 $transaction->rollBack();
                 //回滚事务
                 echo $e->getMessage();
             }
         }
     }
     // 关闭链接
     $obj->close_mailbox();
 }