コード例 #1
0
 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();
 }