public function preProcess()
 {
     if (!Tools::hasFunction('booking_list')) {
         Tools::redirect('index.php');
     }
     if (Tools::getValue("settle") == 1) {
         $this->brandNavi[] = array("name" => "Settlement", "url" => 'booking_list.php?settle=1');
     } else {
         $this->brandNavi[] = array("name" => "Booking List", "url" => $this->php_self);
     }
     if (Tools::isSubmit("change_pay")) {
         $id = (int) Tools::getValue("id");
         $status = (int) Tools::getValue("status");
         Booking::changePayStatus($id, $status);
         if ($status == 2) {
             Booking::changeBookingStatus($id, 10);
             // Successed
             Booking::payment($id, $_POST['money']);
             //给otherPrice值
         }
         exit;
     } else {
         if (Tools::isSubmit("change_status")) {
             $id = (int) Tools::getValue("id");
             $status = (int) Tools::getValue("status");
             $roleid = self::$cookie->RoleID;
             if ($status == 7) {
                 $bookingInfo = Booking::getBookingInfo($id);
                 $checkin = $bookingInfo['checkin'];
                 $nights = $bookingInfo['nights'];
                 $roomplan_list = array();
                 foreach ($bookingInfo['booked_roomplan_list'] as $booked_roomplan_list) {
                     $roomplan_list[] = $booked_roomplan_list['RoomPlanId'];
                 }
                 Stock::updateAmountStock($checkin, $nights, $roomplan_list);
             }
             Booking::changeBookingStatus($id, $status);
             exit;
         }
     }
 }
Пример #2
0
 public function run()
 {
     $logStr = "";
     $logFd = fopen(PAYPAL_IPN_LOG, "a");
     //$booking_info = Booking::getBookingInfoByBN('TASF0000427');
     // p($booking_info);
     fwrite($logFd, "******************************START*****************************************************************\n");
     //echo PAYPAL_IPN_LOG;
     if (array_key_exists("txn_id", $_POST)) {
         $logStr = "Received IPN,  TX ID : " . htmlspecialchars($_POST["txn_id"]);
         fwrite($logFd, strftime("%d %b %Y %H:%M:%S ") . "[IPNListner.php] {$logStr}\n");
     } else {
         $logStr = "IPN Listner recieved an HTTP request with out a Transaction ID.";
         fwrite($logFd, strftime("%d %b %Y %H:%M:%S ") . "[IPNListner.php] {$logStr}\n");
         fclose($logFd);
         exit;
     }
     //从 PayPal 出读取 POST 信息同时添加变量?cmd?
     $req = 'cmd=_notify-validate';
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $req .= "&{$key}={$value}";
     }
     //建议在此将接受到的信息记录到日志文件中以确认是否收到 IPN 信息
     $tmpAr = array_merge($_POST, array("cmd" => "_notify-validate"));
     $postFieldsAr = array();
     foreach ($tmpAr as $name => $value) {
         $postFieldsAr[] = "{$name}={$value}";
     }
     $logStr = "Sending IPN values:\n" . implode("\n", $postFieldsAr);
     fwrite($logFd, strftime("%d %b %Y %H:%M:%S ") . "[IPNListner.php] {$logStr}\n");
     //将信息 POST 回给 PayPal 进行验证
     $ppResponseAr = Utils::PPHttpPost("https://www." . DEFAULT_ENV . ".paypal.com/cgi-bin/webscr", implode("&", $postFieldsAr), false);
     if (!$ppResponseAr["status"]) {
         fwrite($logFd, "--------------------\n");
         $logStr = "IPN Listner recieved an Error:\n";
         if (0 !== $ppResponseAr["error_no"]) {
             $logStr .= "Error " . $ppResponseAr["error_no"] . ": ";
         }
         $logStr .= $ppResponseAr["error_msg"];
         fwrite($logFd, strftime("%d %b %Y %H:%M:%S ") . "[IPNListner.php] {$logStr}\n");
         fclose($logFd);
         exit;
     }
     //将 POST 变量记录在本地变量中
     //该付款明细所有变量可参考:
     //https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
     $item_name = $_POST['item_name'];
     $item_number = $_POST['item_number'];
     $payment_status = $_POST['payment_status'];
     $payment_amount = $_POST['mc_gross'];
     $payment_currency = $_POST['mc_currency'];
     $txn_id = $_POST['txn_id'];
     $receiver_email = $_POST['receiver_email'];
     $payer_email = $_POST['payer_email'];
     //…
     //判断回复 POST 是否创建成功
     fwrite($logFd, "--------------------\n");
     $logStr = "IPN Post Response:\n" . $ppResponseAr["httpResponse"];
     fwrite($logFd, strftime("%d %b %Y %H:%M:%S ") . "[IPNListner.php] {$logStr}\n");
     $res = $ppResponseAr["httpResponse"];
     //已经通过认证
     if (strcmp($res, "VERIFIED") == 0) {
         fwrite($logFd, "----- VERIFIED -----------\n");
         //检查付款状态
         fwrite($logFd, "----- Payment Status:{$payment_status} -----------\n");
         if ($payment_status == "Completed") {
             //检查 txn_id  是否已经处理过
             fwrite($logFd, "-----Check Transaction ID :{$txn_id}-----------\n");
             //检查 receiver_email 是否是您的 PayPal 账户中的 EMAIL 地址
             fwrite($logFd, "-----Check Receiver_email :{$receiver_email}-----------\n");
             if ($receiver_email != DEFAULT_EMAIL_ADDRESS) {
                 fwrite($logFd, "----- Receiver_email Error :{$receiver_email}-----------\n");
             } else {
                 //检查付款金额和货币单位是否正确
                 //todo:$ammount
                 $booking_info = Booking::getBookingInfoByBN($item_name);
                 // fwrite($logFd, "-----Booking Info :-----------\n");
                 //fwrite($logFd, var_dump($booking_info));
                 $ammount = $booking_info['money'];
                 fwrite($logFd, "-----Check Payment Amount :{$payment_amount}-----------\n");
                 fwrite($logFd, "-----Check Payment Currency :{$payment_currency}-----------\n");
                 if ($payment_currency != DEFAULT_PAYMENT_CURRENCY) {
                     fwrite($logFd, "-----Payment Currency Error :{$payment_currency}-----------\n");
                 } elseif ($payment_amount != $ammount) {
                     fwrite($logFd, "-----Payment Error :{$payment_amount}---{$ammount}--------\n");
                 } else {
                     //处理这次付款,包括写数据库
                     fwrite($logFd, "----- changeBookingStatus  -----------\n");
                     Booking::changeBookingStatus($booking_info['order_id'], 4);
                     fwrite($logFd, "----- changePayStatus  -----------\n");
                     Booking::changePayStatus($booking_info['order_id'], 2);
                     fwrite($logFd, "----- payment  -----------\n");
                     Booking::payment($booking_info['order_id'], $payment_amount);
                     //下订单成功,此时需要发送邮件
                     fwrite($logFd, "----- ordermail  -----------\n");
                     Tools::ordermail($booking_info['order_id']);
                     fwrite($logFd, "----- finish  -----------\n");
                 }
             }
         }
     } else {
         if (strcmp($res, "INVALID") == 0) {
             //未通过认证,有可能是编码错误或非法的 POST 信息
             fwrite($logFd, "----- INVALID -----------\n");
         }
     }
     fwrite($logFd, "***********************************END**************************************************************\n");
     fclose($logFd);
 }
 public function process()
 {
     global $cookie;
     if ($_POST["booking"] != 'confirm' && $_POST["booking"] != 'calculate' && $_REQUEST['booking'] != 'view' && $_POST['booking'] != 'payment' && $_POST["booking"] != 'finish' && $_POST["booking"] != 'save') {
         Tools::redirect('index.php');
     }
     if ($_REQUEST['booking'] == 'view') {
         // view page
         if ($_REQUEST['vouch_info'] == 1 || $_REQUEST['savepdf'] == 1) {
             $orderId = $_GET['oid'];
             //获取订单编号
             if ($_REQUEST['savepdf'] == 1) {
                 $booking_info = Booking::getBookingInfo($_GET['oid'], "en");
             } else {
                 $booking_info = Booking::getBookingInfo($_GET['oid']);
             }
             $booking_info['agent_info'] = new Member($booking_info['OrderUserId']);
             // make string of  "Total No or rooms"
             $_rooms = array();
             foreach ($booking_info['booked_roomplan_list'] as $roomplan) {
                 if ($_rooms[$roomplan[RoomPlanId]]) {
                     $_rooms[$roomplan[RoomPlanId]]['count']++;
                 } else {
                     $_rooms[$roomplan[RoomPlanId]]['count'] = 1;
                     $_rooms[$roomplan[RoomPlanId]]['name'] = $roomplan[RoomPlanName];
                 }
             }
             $_roomsString = "";
             foreach ($_rooms as $_room) {
                 if ($_roomsString != "") {
                     $_roomsString .= "& ";
                 }
                 $_roomsString .= $_room['count'] . " " . $_room['name'];
             }
             $booking_info['roomString'] = $_roomsString;
             if ($_REQUEST['savepdf'] == 1) {
                 $this->printPDF($booking_info);
                 exit;
             } else {
                 self::$smarty->assign("booking_info", $booking_info);
             }
         }
         // move the engine to preprocess function
         /*
         			$booking_info = Booking::getBookingInfo ( $_GET ['oid'] );
         			if (! $booking_info)
         				Tools::redirect ( 'index.php' );
         			if ($_REQUEST ['payment'])
         				self::$smarty->assign ( "payment", $_REQUEST ['payment'] );
         			self::$smarty->assign ( "method", 'view' );
         */
     } else {
         // other(build booking info from post variable for edit, confirm, finish)
         $booking_info = Booking::buildBookingInfoFromPost(self::$cookie->CompanyID);
         self::$smarty->assign("method", 'order');
         self::$smarty->assign("booking_info", $booking_info);
         foreach ($booking_info['booked_roomplan_list'] as $bi) {
             //echo $bi['Check_0'];
             if ($bi['Check_0'] == '0') {
                 $error['message'] = "満室のためご希望の日程には変更できません";
                 self::$smarty->assign("error", $error);
                 self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
                 exit;
             }
         }
         //p($booking_info['booked_roomplan_list']);
     }
     if ($_POST["booking"] == 'calculate') {
         $checkin = $_POST['checkin'];
         //获取checkin的值
         $checkout = $_POST['checkout'];
         //获取checkout的值
         //获取roomPlanId
         $ids = $_POST['ids'];
         $rpid_list = array();
         foreach ($ids as $id) {
             $rpid_list[] = $_POST['roomplan_ids_' . $id];
         }
         //计算房间数量是否满足条件,如果有一条不满足则发出错误报告
         $roomplan_list = RoomPlan::getRoomPlanListForBooking($rpid_list, $checkin, $checkout);
         $plan_list = array();
         foreach ($roomplan_list as $record) {
             $plan_list[$record['RoomPlanId']] = $record;
         }
         //查看是否有房间不满足条件
         $isOk = true;
         foreach ($rpid_list as $rpid) {
             if (empty($plan_list[$rpid])) {
                 $isOk = false;
                 break;
             }
         }
         if (!$isOk) {
             $error['message'] = "There is not any room as requested";
             self::$smarty->assign("error", $error);
             self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
             exit;
         }
         self::$smarty->assign("countries", Tools::getCountries());
         self::$smarty->assign("method", 'edit');
     }
     //添加修改的情况
     if ($_POST["booking"] == 'save') {
         if ($booking_info['order_id'] == 0) {
             //如果订单ID没有,则报错
             $error['message'] = "订单编号不存在";
             self::$smarty->assign("error", $error);
             self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
             exit;
         }
         $checkin = $_POST['checkin'];
         //获取checkin的值
         $checkout = $_POST['checkout'];
         //获取checkout的值
         //获取roomPlanId
         $ids = $_POST['ids'];
         $rpid_list = array();
         foreach ($ids as $id) {
             $rpid_list[] = $_POST['roomplan_ids_' . $id];
         }
         //计算房间数量是否满足条件,如果有一条不满足则发出错误报告
         $roomplan_list = RoomPlan::getRoomPlanListForBooking($rpid_list, $checkin, $checkout);
         $plan_list = array();
         foreach ($roomplan_list as $record) {
             $plan_list[$record['RoomPlanId']] = $record;
         }
         //查看是否有房间不满足条件
         $isOk = true;
         foreach ($rpid_list as $rpid) {
             if (empty($plan_list[$rpid])) {
                 $isOk = false;
                 break;
             }
         }
         if (!$isOk) {
             $error['message'] = "There is not any room as requested";
             self::$smarty->assign("error", $error);
             self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
             exit;
         }
         $booking_info['paymentMethod'] = Member::getPaymentMethod(self::$cookie->CompanyID);
         //获取支付方式,是前支付还是后支付
         $order_id = Booking::modifyBooking($booking_info);
         if (empty($order_id)) {
             $error['message'] = "修改失败, 您修订的房间信息不存在。";
             self::$smarty->assign("error", $error);
             self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
         } else {
             //下订单成功,此时需要发送邮件
             Tools::ordermail($order_id);
             Tools::emailHotel($order_id, 11);
             Tools::redirect('booking_list.php');
         }
         exit;
     }
     if ($_POST["booking"] == 'finish') {
         //  $_POST ["booking"] == 'save'
         if ($booking_info['order_id'] == 0) {
             $booking_info['OrderUserId'] = self::$cookie->UserID;
         }
         //获取用户ID
         $booking_info['paymentMethod'] = Member::getPaymentMethod(self::$cookie->CompanyID);
         $order_id = Booking::insertNewBooking($booking_info);
         if ($order_id) {
             $booking_info = Booking::getBookingInfo($order_id);
             //下订单成功,此时需要发送邮件
             Tools::ordermail($order_id);
             Tools::emailHotel($order_id, 10);
         } else {
             $error['message'] = "Booking has time out!";
             self::$smarty->assign("error", $error);
             self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
             exit;
         }
         //$booking_info = Booking::getBookingInfo ( $order_id );
         self::$smarty->assign("booking_info", $booking_info);
         //if ($_POST ["booking"] == 'save')
         //	Tools::redirect ( 'booking_list.php' );
     }
     if ($_POST['booking'] == 'payment') {
         //支付接口调用
         $url = "http://localhost/payment.php";
         //支付站点网址
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_exec($ch);
         //$content =
         $response = curl_getinfo($ch);
         curl_close($ch);
         if ($response['http_code'] == 200) {
             //判断是否支付成功,此处只是模拟使用
             Booking::changeBookingStatus($booking_info['order_id'], 4);
             Booking::changePayStatus($booking_info['order_id'], 2);
             Booking::payment($booking_info['order_id'], $_POST['money']);
             //下订单成功,此时需要发送邮件
             Tools::ordermail($order_id);
         } else {
             //模拟支付失败的情况
             $error = array();
             $error['message'] = 'sorroy charge fail';
             self::$smarty->assign("error", $error);
             self::$smarty->display(_TAS_THEME_DIR_ . 'error_redirect.tpl');
             exit;
         }
     }
     parent::process();
 }