Project Restatement:
PROBLEM : HOTEL RESERVATION A hotel chain operating in Miami wishes to offer room reservation services over the internet. They have three hotels in Miami: Lakewood, Bridgewood and Ridgewood. Each hotel has separate weekday and weekend (Saturday and Sunday) rates. There are special rates for rewards customer as a part of loyalty program. Each hotel has a rated assigned to it.
- Lakewood with a rating of 3 has weekday rates as 110$ for regular customer and 80$ for rewards customer. The weekend rates are 90$ for regular customer and 80$ for a rewards customer.
- Bridgewood with a rating of 4 has weekday rates as 160$ for regular customer and 110$ for rewards customer. The weekend rates are 60$ for regular customer and 50$ for a rewards customer.
- Ridgewood with a rating of 5 has weekday rates as 220$ for regular customer and 100$ for rewards customer. The weekend rates are 150$ for regular customer and 40$ for a rewards customer.
Write a program to help an online customer find the cheapest hotel. The input to the program will be a range of dates for a regular or rewards customer. The output should be the cheapest available hotel. In case of a tie, the hotel with highest rating should be returned.
Project ideas and features
Data facilitates maintenance
For a real-life project, the star rating and price of a hotel cannot be fixed. In order to better maintain the hotel and price information and facilitate the system's later revision, the extremely guest decides to use the database management data.In view of the requirements of this item, when the project was implemented, only the WEB interface of the customer querying the hotel information was written. For managers, the star rating, name, and price of the hotel may be modified in the database. This project is not implemented to benefit the administrator. Management interface.
Platform is easy to expand
Although the project uses PHP to implement functions, and the client's query operation is implemented on the WEB platform, the extremely guest specifically deploys a code to generate JSON data packages on the server, which is conducive to extending related functions to JAVA/C/C++ and other platforms.Note: Since no privacy information is involved, the HTTP value transmission method is tentatively set to GET. Of course, the principle of the post method is roughly the same.
Building a Interface Using the Bootstrap Front End Library
In order to realize the appearance of interface and interface as soon as possible, this project uses the open source WEB front end library: Bootstrap
Project file structure
Common code
Class hotelOrder: hotel booking arrangement class, constructor incoming start time, end time, customer type code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
<?php /** * Hotel order arrangement class, constructor incoming start time, end time, customer type code * Return the best option for ordering via getCheapest(), traversal of the days of weekends and workdays during the specified day via a private method such as CountOfWeekend_WeekDay() */ Class hotelOrder { Private $startDate; Private $endDate; Private $customertype; Function hotelOrder($istartDate, $iendDate, $icustomertype)//constructor { $this -> startDate = $istartDate;//start time $this -> endDate = $iendDate;//end time $this -> customertype = $icustomertype;//customer type code, 0: normal customer; 1:rewards customer } Function getChoices() { // $CheapestHotelName = "null"; Require ('../db_connect.php'); $string = "select * from HOTEL_RESERVATION "; $str = @mysqli_query($software_db, $string); While ($row = mysqli_fetch_array($str, MYSQLI_ASSOC)) { $countsOfDay=$this->CountOfWeekend_WeekDay(); If($this->customertype==0){//Ordinary customer $totalPrice['name']=$row['name']; $totalPrice['price']=$countsOfDay['Weekend']*$row['rates_for_regular_In_weekend'] +$countsOfDay['WeekDay']*$row['rates_for_regular_In_weekday']; $totalPrice['rating']=$row['rating']; $choice[]=$totalPrice; }elseif($this->customertype==1){//rewards customers $totalPrice['name']=$row['name']; $totalPrice['price']=$countsOfDay['Weekend']*$row['rates_for_rewards_In_weekend'] +$countsOfDay['WeekDay']*$row['rates_for_rewards_In_weekday']; $totalPrice['rating']=$row['rating']; $choice[]=$totalPrice; } } //echo $countsOfDay['Weekend']." ".$countsOfDay['WeekDay']; // $json = json_encode($choice); // return $json; Return $choice; } Function getCheapest() { $choices=$this->getChoices(); $prices = array(); $ratings = array(); Foreach ($choices as $choice){ $prices[]=$choice['price']; $ratings[]=$choice['rating']; } Array_multisort($prices, SORT_ASC, $ratings, SORT_ASC, $choices); Return $choices; } /** * Judgment date is not a weekend */ Private function isWeekend($date) { Date_default_timezone_set('PRC'); $w = intval(date('w', strtotime($date))); If ($w === 0 || $w === 6) { Return true; } else Return false; } /** * Get the number of days of weekends and working days in a specified time period */ Private function CountOfWeekend_WeekDay() { $count['Weekend']=0; $count['WeekDay']=0; Date_default_timezone_set('PRC'); For ($start = strtotime($this ->startDate); $start <strtotime($this ->endDate)+86400; $start += 86400) //This traverses the date, so it increases 86400 seconds each time { //echo $start.' '; $w = intval(date('w', $start)); If ($w === 0 || $w === 6) { $count['Weekend']++; } Else $count['WeekDay']++; } Return $count; } } ?> |
Web interface code:
Query home page index.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<html> <head> <meta name='viewport' content='width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;' /> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/> <link rel="stylesheet" type="text/css" href="css/common.css"/> <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script src="js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script> <script src="js/login.js" type="text/javascript" charset="utf-8"></script> <title>Hotel Reservation-powered by Wang Baiyuan</title> </head> <body> <div class="container"> <div class="jumbotron"> <h1>Hotel Booking Inquiry System</h1> </div> <h2 class="form-signin-heading">Enter the start-end date of your stay</h2> <form class="form-signin" action="result.php" method="get"> <div class="panel panel-default"> <div class="panel-body"> <div class="checkbox"> <label for="startDate">Start Date:</label> <input id="startDate" type="date" name="startDate" value="2015-07-26"/> <label for="endDate">End date:</label> <input id="endDate" type="date" name="endDate" value="2015-08-01"/> </div> </div> <div class="input-group"> <span class="input-group-addon"> <input type="radio" value="0" checked="true" name="type" aria-label="..."/>regular customer </span> <span class="input-group-addon"> <input type="radio" value="1" name="type" aria-label="..."/>rewards customer </span> </span> </div><!-- /input-group --> <button class="btn btn-lg btn-primary btn-block" type="submit">query</button> </div> </form> </div> </body> </html> |
Query result page:
Result.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<?php Header("Content-Type:text/html;charset=utf-8"); //require_once('../db_connect.php'); Include_once ("hotelOrder.php"); //$str = file_get_contents("php://input"); //$arr=array(); //parse_str($str,$arr); $startDate = $_GET['startDate']; $endDate = $_GET['endDate']; $customertype = $_GET['type']; $hotelorder = new hotelOrder($startDate, $endDate, $customertype); //echo json_encode($hotelorder->getChoices()); //echo json_encode($hotelorder->getCheapest()); $choices = $hotelorder -> getCheapest(); ?> <html> <head> <meta name='viewport' content='width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;' /> <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/> <link rel="stylesheet" type="text/css" href="css/common.css"/> <script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script src="js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script> <script src="js/login.js" type="text/javascript" charset="utf-8"></script> <title> Hotel Reservation Search Results - powered by 王柏元 </title> </head> <body> <div class="container"> <div class="jumbotron"> <h1>Hotel Reservation Search Results</h1> <p><a href="./" role="button">Back</a></p> </div> <div class="panel panel-default"> <!-- Default panel contents --> <div class="panel-heading">Priority from high to low</div> <!-- Table --> <table class="table"> <thead><tr><th>Hotel Name</th> <th>Total Price</th> <th>Hotel Level</th></tr> </thead> <?php Foreach ($choices as $choice){ Echo "<tr><td>".$choice['name']."</td><td>".$choice['price']."</td><td>".$choice[' Rating']."</td></tr>"; } ?> </table> </div> </div> </body> </html> |
- Demo URL: http://wangbaiyuan.cn/others/hotel_reservation/index.php
- Demo screenshot:
JSON output code that can be extended to other platforms
JsonCheapestHotel.php:
1 2 3 4 5 6 7 8 9 |
<?php Header("Content-Type:text/html;charset=utf-8"); Include_once ("hotelOrder.php"); $startDate=$_GET['startDate']; $endDate=$_GET['endDate']; $customertype=$_GET['type']; $hotelorder=new hotelOrder($startDate,$endDate,$customertype); Echo json_encode($hotelorder->getCheapest()); ?> |
- Output Example: [{"name":"Lakewood","price":720,"rating":"3"},{"name":"Ridgewood","price":780,"rating":"5" },{"name":"Bridgewood","price":870,"rating":"4"}]
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/php-hotel-query-web-sql-json-api-2.html
No Comment