Example #1
0
 public static function emailHotel($orderid, $orderstatus)
 {
     //1.获取订单信息
     $bookingInfo = Booking::getBookingOrder($orderid);
     $BookingNo = $bookingInfo['BookingNo'];
     //订单编号
     $ContactName = $bookingInfo['contact_name'];
     //1.Customer Information
     $ContactEmail = $bookingInfo['contact_email'];
     $ContactTel = $bookingInfo['contact_tel'];
     $CheckIn = $bookingInfo['checkin'];
     $CheckOut = $bookingInfo['checkout'];
     //2.获取下订单的用户信息
     $userid = $bookingInfo['OrderUserId'];
     $userinfo = Member::getUserInfoById($userid);
     $AgentName = $userinfo['Name'];
     $AgentPhoneNo = $userinfo['Tel'];
     $AgentEmail = $userinfo['Email'];
     //3.获取酒店用户信息
     $hotelid = $bookingInfo['hotel_id'];
     $hoteluserinfo = Member::getUserInfoByHotelId($hotelid);
     $UserName = $hoteluserinfo['Name'];
     $prefFax = $hoteluserinfo['PrefFax'];
     $prefEmail = $hoteluserinfo['PrefEmail'];
     $Fax = $hoteluserinfo['Fax'];
     $to = $hoteluserinfo['Email'];
     $languageid = $hoteluserinfo['LanguageID'];
     $iso = $hoteluserinfo['LanguageShortName'];
     if (!isset($hoteluserinfo['LanguageID'])) {
         $languageid = 4;
     }
     //4.获取酒店信息
     $hotelinfo = HotelDetail::getHotelDescription($hotelid, $iso);
     $HotelName = $hotelinfo['HotelName'];
     $HotelAddress = $hotelinfo['HotelAddress'];
     $HotelContactNo = $hotelinfo['HotelContactNo'];
     $orderroominfo = RoomPlan::getOrderRoomInfo($orderid, $iso);
     $RoomList = '';
     $RoomListFax = '';
     $id = 1;
     foreach ($orderroominfo as $orderroom) {
         $RoomList .= "<table  width='100%' cellspacing='10' style='font-size:12px;'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=2><span style='color:#000000;font-weight:bold;font-zie:14px;'>- Room " . $id . "</span></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=2><span>Room Plan(宿泊プラン):</span> " . $orderroom['RoomPlanName'] . " </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=2><span>Room Type(ルームタイプ):</span> " . $orderroom['RoomTypeName'] . " </td>\t\t\t\t\n\t\t\t\t</tr> \n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=2><span>Guest Name(宿泊者名):</span> " . $orderroom['CustomerName'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td width='30%'><span>Breakfast(朝食):</span> " . $orderroom['Breakfast'] . "</td>\t\t\t\n\t\t\t\t\t<td><span>Dinner(夕食):</span> " . $orderroom['Dinner'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=2><span>Special Request(特別リクエスト):</span> " . $orderroom['Special'] . " </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=2><span>* All Special request are subjects to availability </span></td>\n\t\t\t\t</tr>\n\t\t\t</table>";
         $RoomListFax .= "<table  width=190 >\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td colspan=2 size=11>- Room " . $id . "</td>\n         \t\t\t\t</tr>\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td colspan=2>Room Plan(宿泊プラン): " . $orderroom['RoomPlanName'] . " </td>\n         \t\t\t\t</tr>\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td colspan=2>Room Type(ルームタイプ): " . $orderroom['RoomTypeName'] . " </td>\n         \t\t\t\t</tr>\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td colspan=2>Guest Name(宿泊者名): " . $orderroom['CustomerName'] . "</td>\n         \t\t\t\t</tr>\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td>Breakfast(朝食): " . $orderroom['Breakfast'] . "</td>\n         \t\t\t\t\t<td>Dinner(夕食): " . $orderroom['Dinner'] . "</td>\n         \t\t\t\t</tr>\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td colspan=2>Special Request(特別リクエスト): " . $orderroom['Special'] . " </td>\n         \t\t\t\t</tr>\n         \t\t\t\t<tr>\n         \t\t\t\t\t<td width=5></td><td colspan=2>* All Special request are subjects to availability </td>\n         \t\t\t\t</tr>\n         \t\t\t</table>";
         $id++;
     }
     $RoomString = RoomPlan::getRoomString($orderid, $iso);
     include_once substr(dirname(__FILE__), 0, -8) . '/config/mail.config.php';
     global $from, $message, $subject;
     $search = array('{#BookingNo}', '{#HotelName}', '{#UserName}', '{#HotelAddress}', '{#HotelContactNo}', '{#ContactName}', '{#ContactEmail}', '{#ContactTel}', '{#CheckIn}', '{#CheckOut}', '{#RoomString}', '{#RoomList}', '{#AgentName}', '{#AgentPhoneNo}', '{#AgentEmail}');
     $replace = array($BookingNo, $HotelName, $UserName, $HotelAddress, $HotelContactNo, $ContactName, $ContactEmail, $ContactTel, $CheckIn, $CheckOut, $RoomString, $RoomList, $AgentName, $AgentPhoneNo, $AgentEmail);
     $replaceFax = array($BookingNo, $HotelName, $UserName, $HotelAddress, $HotelContactNo, $ContactName, $ContactEmail, $ContactTel, $CheckIn, $CheckOut, $RoomString, $RoomListFax, $AgentName, $AgentPhoneNo, $AgentEmail);
     $msg = str_replace($search, $replace, $message[10][5][$languageid]);
     // $faxmsg = str_replace($search, $replaceFax, $message[21][5][$languageid]);
     $faxmsg = str_replace($search, $replaceFax, $message[21][5][4]);
     $sub = str_replace('{#BookingNo}', $BookingNo, $subject[$orderstatus][5][$languageid]);
     if ($orderstatus == 7) {
         $msg = str_replace('下記の予約をお願いいたします', '下記の予約のキャンセルをお願いいたします', $msg);
         $faxmsg = str_replace('下記の予約をお願いいたします', '下記の予約のキャンセルをお願いいたします', $faxmsg);
     }
     if ($prefEmail) {
         $headers = "From: {$from}" . "\r\n";
         $headers .= 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-Type: text/html; charset=utf-8' . "\r\n";
         $headers .= 'Bcc: booking@tas-agent.com';
         //echo $sub."<br/><br/><br/>".$msg;
         if ($sub != '' && $msg != '') {
             global $emailTail;
             $msgBody = $msg . $emailTail;
             self::sendEmail($to, $sub, $msg);
             //@mail($to, $sub, $msgBody, $headers);
             $Insertmsg = htmlentities($msg);
             $sql = 'insert into `HT_Mail`(MailTo, MailFrom, SubjectName, Body) value("' . $to . '", "' . $from . '", "' . $sub . '", "' . $Insertmsg . '")';
             Db::getInstance()->ExecuteS($sql);
         }
     }
     if ($prefFax) {
         global $toemail, $faxTail, $faxHead;
         $emailBody = "<p>需要给酒店发送传真.</p>\n\t\t\t\t\t\t<p>传真号为: {$Fax}</p>\n\t\t\t\t\t\t<p>订单状态为: {$orderstatus}</p>";
         $emailBody = "fax";
         $faxsub = $faxHead[$orderstatus];
         $faxsub2 = "<TAS-Agent.com> Booking ID:" . $BookingNo;
         $prefix = time();
         require_once _TAS_TOOL_DIR_ . "/tfpdf/pdffax.inc.php";
         $defFont = 'MyFont';
         $pdf = new PDFTable();
         $pdf->AddFont($defFont, '', 'ARIALUNI.TTF', true);
         $pdf->AddFont($defFont . 'B', '', 'ARIALUNI.TTF', true);
         $pdf->SetMargins(10, 2);
         $pdf->SetDrawColor(0, 0, 0);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetPadding(0);
         $pdf->SetSpacing(0, 0);
         $pdf->AddPage();
         //header
         $pdf->SetFont($defFont, '', 10);
         $pdf->Image(_TAS_THEME_DIR_ . "/img/logo_pdf.png", 140, 15, 60);
         $pdf->htmltable("<table width=190><tr><td size=20 > </td></tr></table>", 1);
         $pdf->Ln(2);
         $pdf->htmltable("<table width=190><tr><td size=14 colspan=2>" . $faxsub . " </td></tr>\n           \t    </table>", 1);
         $pdf->Image(_TAS_THEME_DIR_ . "/img/linep.png", 10, $pdf->y, 190);
         //内容
         $pdf->htmltable($faxmsg);
         //footer
         $pdf->SetY(-30);
         $pdf->Image(_TAS_THEME_DIR_ . "/img/linep.png", 10, $pdf->y, 190);
         $pdf->Ln(1);
         $pdf->Image(_TAS_THEME_DIR_ . "/img/bottom_logo_pdf.png", 12, $pdf->y + 2, 20);
         $pdf->x = 35;
         $pdf->htmltable("<table width=90>\n    \t    <tr><td size=9>TAS Agent / TAS Co.Ltd<br>TEL 03-5565-5850<br>FAX 03-5565-5850<br>booking@tas-agent.com</td></tr>\n    \t    </table>", 0);
         $pdf->htmltable("<table width=190>\n                \t    <tr><td size=9>※TAS Agent はTAS Co.,Ltdが運営しております。 上記予約の内容については直接TASまでご連絡ください。\n                \t    </td></tr></table>", 1);
         $attachment_file = _TAS_ROOT_DIR_ . "/classes/temp/attachment_" . $prefix . ".pdf";
         //$attachment_file=_TAS_ROOT_DIR_."/config/attachment_".$prefix.".pdf";
         $pdf->Output($attachment_file);
         require_once _TAS_TOOL_DIR_ . "/PHPMailer/class.phpmailer.php";
         $mail = new PHPMailer();
         $mail->IsSMTP();
         // telling the class to use SMTP
         $mail->SMTPAuth = true;
         // enable SMTP authentication
         $mail->SMTPSecure = "ssl";
         // sets the prefix to the servier
         $mail->Host = "smtp.gmail.com";
         // sets GMAIL as the SMTP server
         $mail->Port = 465;
         // set the SMTP port for the GMAIL server
         $mail->Username = "******";
         // GMAIL username
         $mail->Password = "******";
         // GMAIL password
         $mail->SetFrom('*****@*****.**', 'fax');
         $mail->AddReplyTo("*****@*****.**", "fax");
         $mail->Subject = $faxsub2;
         $mail->MsgHTML($emailBody);
         $toemail = $Fax . "@efaxsend.com";
         $mail->AddAddress($toemail, $Fax);
         $mail->AddAttachment($attachment_file);
         // attachment
         $mail->Send();
         //发邮件
         if (file_exists($attachment_file)) {
             unlink($attachment_file);
             //删除文件
         }
     }
 }
Example #2
0
 public static function insertNewBooking($booking_info)
 {
     //p($booking_info);
     $new_order_id = $booking_info['order_id'];
     if ($new_order_id == 0) {
         //只是预定
         $booking_info['booking_no'] = '';
     } else {
         //正是插入
         $exist_booking_info = Booking::getBookingOrder($new_order_id);
         if ($exist_booking_info) {
             //如果这个订单ID对应的记录还存在,则说明是在30分钟以内,那么删除旧订单,插入新订单。否则直接返回NULL
             if ($exist_booking_info['OrderStatusId'] != 2) {
                 $sql = "UPDATE HT_RoomStockAndPrice as A right join (\n\t\t\t\t\t\t\t\tSELECT B.`RoomPlanId`, count(B.`RoomPlanId`) as OrderCount \n\t\t\t\t\t\t\t\tFROM HT_Order as A, HT_OrderRoom as B\n\t\t\t\t\t\t\t\tWHERE A.`OrderId` = B.`OrderId`\tand A.`OrderId` = {$new_order_id}\n\t\t\t\t\t\t\t\tGROUP BY B.`RoomPlanId`\n\t\t\t\t\t\t\t) AS B on A.`RoomPlanId` = B.RoomPlanId\n\t\t\t\t\t\tSET A.Amount = greatest(A.Amount + B.OrderCount, 0)\n\t\t\t\t\t\tWHERE A.`ApplyDate` between '{$exist_booking_info['checkin']}' and DATE_SUB('{$exist_booking_info['checkout']}'\t, INTERVAL 1 DAY)";
                 Db::getInstance()->ExecuteS($sql);
             }
             $booking_info['OrderUserId'] = $exist_booking_info['OrderUserId'];
             $booking_info['booking_no'] = Booking::getNextBookingNo();
             //获取一条新的订单编号 TASF开头
         } else {
             return null;
         }
     }
     //删除OrderCustomer中与旧订单相关的信息, 清楚杂项保留新数据的正确性
     $sql = "DELETE FROM A, B USING HT_OrderCustomer as A, HT_OrderRoom as B\n\t\t\t\tWHERE A.`OrderRoomId` = B.`OrderRoomId` AND  B.`OrderId` = {$new_order_id}";
     Db::getInstance()->ExecuteS($sql);
     //检查订单状态是否为confirming
     $roomplan_id_list = array();
     foreach ($booking_info['booked_roomplan_list'] as $booked_roomplan) {
         $roomplan_id_list[] = $booked_roomplan['RoomPlanId'];
     }
     // 获取所预定房间的信息(房间数量信息)
     $sql = "SELECT A.RoomPlanId, min(B.Amount) as MinAmount \n            FROM HT_RoomPlan as A, HT_RoomStockAndPrice as B \n            WHERE A.`RoomPlanId` = B.RoomPlanId  AND A.RoomPlanId in (" . implode(",", $roomplan_id_list) . ")  \n\t\t\t\tAND B.`ApplyDate` between '{$booking_info['checkin']}' and DATE_SUB('{$booking_info['checkout']}', INTERVAL 1 DAY)  \n            GROUP BY B.RoomPlanId";
     $roomplan_minamount_list = array();
     $minamount_list = Db::getInstance()->ExecuteS($sql);
     foreach ($minamount_list as $roomplan_minamount) {
         $roomplan_minamount_list[$roomplan_minamount['RoomPlanId']] = $roomplan_minamount['MinAmount'];
     }
     $order_status = 3;
     //默认为 3:confirmed
     if ($booking_info['paymentMethod'] == 1) {
         //如果是支付,则订单变为 9:waiting for payment
         $order_status = 9;
     }
     foreach ($roomplan_minamount_list as $minamount) {
         //如果这些房间中数量小于1的则表示,这些房间暂时不能入住
         if ($minamount < 1) {
             //将订单状态改为 2:confirming
             $order_status = 2;
             break;
         }
     }
     //将新订单或者是修改的订单 放入订单表中
     $sql = "REPLACE INTO `HT_Order` (`OrderId`, `BookingNo`, `OrderUserId`, `HotelId`, \n\t\t\t`ContactName`, `ContactPhoneNumber`, `ContactEmail`, `ContactHomePage`, \n\t\t\t`OrderStatusId`, `OrderedDate`, `CheckInDate`, `CheckOutDate`, \n\t\t\tTotalPrice, `paymentMethod`,`OrgTotalPrice`)\n\t\tVALUES\n\t\t\t({$booking_info['order_id']}, '{$booking_info['booking_no']}', {$booking_info['OrderUserId']}, {$booking_info['hotel_id']},\n\t\t\t'{$booking_info['contact_name']}', '{$booking_info['contact_tel']}', '{$booking_info['contact_email']}', '{$booking_info['contact_hp']}', \n\t\t\t{$order_status}, '" . date('Y-m-d H:i:s') . "', '{$booking_info['checkin']}', '{$booking_info['checkout']}', \n\t\t\t{$booking_info['TotalPrice']}, '{$booking_info['paymentMethod']}',{$booking_info['OrgTotalPrice']})";
     Db::getInstance()->ExecuteS($sql);
     $new_order_id = Db::getInstance()->Insert_ID();
     //删除OrderCustomer中与新订单相关的信息, 清楚杂项保留新数据的正确性
     $sql = "DELETE FROM A, B USING HT_OrderCustomer as A, HT_OrderRoom as B\n\t\t\t\tWHERE A.`OrderRoomId` = B.`OrderRoomId` AND  B.`OrderId` = {$new_order_id}";
     Db::getInstance()->ExecuteS($sql);
     foreach ($booking_info['booked_roomplan_list'] as $booked_roomplan) {
         $sql = "INSERT INTO `HT_OrderRoom` (`OrderId`, `RoomPlanId`,  \n\t\t\t\t`SpecialRequestNoSmoking`, `SpecialRequestSmoking`,\n\t\t\t\t`SpecialRequestAdjoin`, `SpecialRequestRemark`, \n\t\t\t\t`Price`, `PriceString`,`OrgPrice`)\n\t\t\tVALUES\n\t\t\t\t({$new_order_id}, {$booked_roomplan['RoomPlanId']},  \n\t\t\t\t{$booked_roomplan['req_nonsmoking']}, {$booked_roomplan['req_smoking']}, \n\t\t\t\t{$booked_roomplan['req_adjoin']}, '{$booked_roomplan['req_remark']}',\n\t\t\t\t{$booked_roomplan['Price']}, '{$booked_roomplan['PriceString']}',{$booked_roomplan['OrgPrice']});";
         Db::getInstance()->ExecuteS($sql);
         $new_orderroom_id = Db::getInstance()->Insert_ID();
         //获取OrderRoom表插入的信息,将预定房间房间的用户信息插入OrderCustomer表中
         foreach ($booked_roomplan['customer_info_list'] as $customer_info) {
             $sql = "INSERT INTO `HT_OrderCustomer` (`OrderRoomId`, `CustomerTitle`, CustomerSex, `CustomerFamilyName`,`CustomerGivenName`, `CustomerCountryId`)\n\t\t\t\tVALUES ({$new_orderroom_id}, 'title',{$customer_info['customer_sex']}, '{$customer_info['customer_fnames']}', '{$customer_info['customer_gnames']}',{$customer_info['customer_country']});";
             Db::getInstance()->ExecuteS($sql);
         }
     }
     //查看订单数量是否大于现有值
     $sql = "SELECT B.`RoomPlanId`, count(B.`RoomPlanId`) as OrderCount\n\t\t\t\t\t\tFROM HT_Order as A, HT_OrderRoom as B\n\t\t\t\t\t\tWHERE A.`OrderId` = B.`OrderId`\tand A.`OrderId` = {$new_order_id}\n\t\t\t\t\t\tGROUP BY B.`RoomPlanId`";
     $roomcount_list = Db::getInstance()->ExecuteS($sql);
     foreach ($roomcount_list as $value) {
         $RoomPlanId = $value['RoomPlanId'];
         $OrderCount = $value['OrderCount'];
         if ($roomplan_minamount_list[$RoomPlanId] < $OrderCount) {
             $order_status = 2;
             $sql = "update `HT_Order` set `OrderStatusId` = {$order_status} where `OrderId` = {$new_order_id}";
             Db::getInstance()->ExecuteS($sql);
             break;
         }
     }
     if ($order_status != 2) {
         //更新RoomStockAndPrice中的数量
         $sql = "UPDATE HT_RoomStockAndPrice as A right join (\n\t\t\t\t\t\tSELECT B.`RoomPlanId`, count(B.`RoomPlanId`) as OrderCount\n\t\t\t\t\t\tFROM HT_Order as A, HT_OrderRoom as B\n\t\t\t\t\t\tWHERE A.`OrderId` = B.`OrderId`\tand A.`OrderId` = {$new_order_id}\n\t\t\t\t\t\tGROUP BY B.`RoomPlanId`\n\t\t\t\t\t) AS B on A.`RoomPlanId` = B.RoomPlanId\n\t\t\t\tSET A.Amount = greatest(A.Amount - B.OrderCount, 0)\n\t\t\t\tWHERE A.`ApplyDate` between '{$booking_info['checkin']}' and DATE_SUB('{$booking_info['checkout']}'\t, INTERVAL 1 DAY)";
         Db::getInstance()->ExecuteS($sql);
     }
     return $new_order_id;
 }