Browse Source

订单功能

Administrator 2 years ago
parent
commit
5661e4dd9e

+ 26 - 0
mhotel/src/com/happy/Until/DateUtil.java

@@ -2,6 +2,7 @@ package com.happy.Until;
 
 
 
 
 import java.io.File;
 import java.io.File;
+import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
@@ -391,4 +392,29 @@ public class DateUtil
         }
         }
     }
     }
 
 
+    /**
+     * 获取两个日期之间相差多少天
+     * @param date1
+     * @param date2
+     * @return
+     */
+    public static int getDayDiff(String date1,String date2)
+    {
+        DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
+        Date star = parseDateOnly(date1);
+        Date endDay=parseDateOnly(date2);
+        Date nextDay=star;
+        int i=0;
+        while(nextDay.before(endDay)){//当明天不在结束时间之前是终止循环
+            Calendar cld = Calendar.getInstance();
+            cld.setTime(star);
+            cld.add(Calendar.DATE, 1);
+            star = cld.getTime();
+            //获得下一天日期字符串
+            nextDay = star;
+            i++;
+        }
+        return i;
+    }
+
 }
 }

+ 1 - 0
mhotel/src/com/happy/Until/Enum/B.java

@@ -6,3 +6,4 @@ package com.happy.Until.Enum;
 public enum B {
 public enum B {
     CODE, MESSAGE,DATA;
     CODE, MESSAGE,DATA;
 }
 }
+

+ 5 - 0
mhotel/src/com/happy/Until/Enum/OrderEnum.java

@@ -0,0 +1,5 @@
+package com.happy.Until.Enum;
+
+public enum OrderEnum {
+    间, 晚;
+}

+ 41 - 1
mhotel/src/com/happy/action/AppBookingAction.java

@@ -1,7 +1,16 @@
 package com.happy.action;
 package com.happy.action;
 
 
+import com.happy.Until.Enum.B;
+import com.happy.Until.Func;
+import com.happy.Until.ResponseUtil;
+import com.happy.Until.ResultUtil;
+import com.happy.constant.ResultStatusCode;
+import com.happy.service.AppBookService;
 import com.happy.service.BookService;
 import com.happy.service.BookService;
+import com.happy.service.HotelService;
 import com.opensymphony.xwork2.ActionSupport;
 import com.opensymphony.xwork2.ActionSupport;
+import net.sf.json.JSONObject;
+import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.interceptor.ServletRequestAware;
 import org.apache.struts2.interceptor.ServletRequestAware;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -18,11 +27,21 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
 
     @Resource
     @Resource
     public BookService bookService;
     public BookService bookService;
+    @Resource
+    public AppBookService appBookService;
 
 
     public int page; // 当前页
     public int page; // 当前页
     public int rows;// 每页显示的行数rows
     public int rows;// 每页显示的行数rows
     public Integer id;
     public Integer id;
     public String status;
     public String status;
+    public String hotelId; // 酒店id
+    public String houseId; // 房型id
+    public String startTime; // 订房开始时间
+    public String endTime;   // 订房结束时间
+    public String houseOrderNumber; // 订房数量
+    public String userName; // 住客姓名
+    public String userPhone; // 住客联系电话
+    public String userId; // 下单人id
 
 
     public HttpServletRequest getRequest() {
     public HttpServletRequest getRequest() {
         return request;
         return request;
@@ -83,7 +102,28 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     public String createOrder()
     public String createOrder()
     {
     {
         // 插入订单数据到表中
         // 插入订单数据到表中
-
+//        public String hotelId; // 酒店id
+//        public String houseId; // 房型id
+//        public String startTime; // 订房开始时间
+//        public String endTime;   // 订房结束时间
+//        public String houseOrderNumber; // 订房数量
+//        public String userName; // 住客姓名
+//        public String userPhone; // 住客联系电话
+        //public String userId; // 下单人id
+        JSONObject jsonObject = new JSONObject();
+        if (Func.checkNull(hotelId) ||Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
+                ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
+        {
+            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
+            ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+            return null;
+        }
+
+        appBookService.createOrder(hotelId, houseId, startTime, endTime, houseOrderNumber,userName,userPhone, userId);
+
+        jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
+        ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
         return null;
         return null;
     }
     }
 
 

+ 11 - 5
mhotel/src/com/happy/action/AppHomePageAction.java

@@ -1,6 +1,7 @@
 package com.happy.action;
 package com.happy.action;
 
 
 import com.happy.Model.Hotel;
 import com.happy.Model.Hotel;
+import com.happy.Until.DateUtil;
 import com.happy.Until.Enum.B;
 import com.happy.Until.Enum.B;
 import com.happy.Until.Func;
 import com.happy.Until.Func;
 import com.happy.Until.ResponseUtil;
 import com.happy.Until.ResponseUtil;
@@ -40,12 +41,14 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
 
 
     public Integer id = new Integer(0);
     public Integer id = new Integer(0);
     public String status;
     public String status;
-    private String hotelId; //选择的当前酒店的id
+    public String hotelId; //选择的当前酒店的id
+    public String queryStartTime; // 查询开始时间
+    public String queryEndTime; // 查询结束时间
 
 
     public String userCode; // 第一次进来获取用户的code
     public String userCode; // 第一次进来获取用户的code
     public String queryValue; // 首页查寻搜索关键词
     public String queryValue; // 首页查寻搜索关键词
-    private Date startTimeQuery; // 查询订房开始时间
-    private Date endTimeQuery; // 查询订房结束时间
+    public Date startTimeQuery; // 查询订房开始时间
+    public Date endTimeQuery; // 查询订房结束时间
 
 
     public HttpServletRequest getRequest() {
     public HttpServletRequest getRequest() {
         return request;
         return request;
@@ -134,7 +137,10 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
             return null;
             return null;
         }
         }
 
 
-        Hotel hotel = appHomePageService.getHotelAndHouseByHotelId(hotelId);
+        // 使用天去查"yyyy/MM/dd"
+//        Date startDate = DateUtil.parseDate(queryStartTime,DateUtil.Time_Formatter_Day);
+//        Date endDate = DateUtil.parseDate(queryStartTime,DateUtil.Time_Formatter_Day);
+        Hotel hotel = appHomePageService.getHotelAndHouseByHotelId(hotelId,queryStartTime, queryEndTime);
 
 
         // 通过时间区间查询房间信息,并带好是否有房标识给前台
         // 通过时间区间查询房间信息,并带好是否有房标识给前台
         jsonObject.put(B.DATA,ResultUtil.ok(hotel));
         jsonObject.put(B.DATA,ResultUtil.ok(hotel));
@@ -144,7 +150,7 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
 
 
 
 
     /**
     /**
-     * 通过酒店的id获取到酒店具体信息
+     * 通过酒店的id获取到酒店详细信息
      * @return
      * @return
      */
      */
     public String getHotelInfoByHotelId()
     public String getHotelInfoByHotelId()

+ 1 - 3
mhotel/src/com/happy/action/AppMePageAction.java

@@ -109,9 +109,7 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
         if (!Func.checkNull(userId)){
         if (!Func.checkNull(userId)){
             querySql.append(" and create_userid = '").append(userId).append("' ");
             querySql.append(" and create_userid = '").append(userId).append("' ");
         }
         }
-        int total = bookService.queryBookTotal(querySql.toString()); // 查询表中的总记录数
-        List<Booking> listPage = bookService.queryBookPage(querySql.toString(), page, rows); // 查询分页
-        ResponseUtil.writeJsonPageData(ServletActionContext.getResponse(),listPage,this.page,this.rows,total);
+        ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(),bookService.queryPage(querySql.toString(), page, rows));
         return null;
         return null;
     }
     }
 
 

+ 9 - 9
mhotel/src/com/happy/action/autoAction.java

@@ -52,15 +52,15 @@ public class autoAction extends ActionSupport implements ServletRequestAware {
     }
     }
 
 
     public String refund_room(){
     public String refund_room(){
-        JSONObject resultjson = new JSONObject();
-        List<Booking> list = bookService.queryEnd(TimeExchange.getDate());
-        if (list!=null){
-            for (int i = 0; i < list.size(); i++) {
-//                bookService.update_pay("6", list.get(i).getOrder_num());
-            }
-        }
-        resultjson.put("message", "退房成功");
-        ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
+//        JSONObject resultjson = new JSONObject();
+//        List<Booking> list = bookService.queryEnd(TimeExchange.getDate());
+//        if (list!=null){
+//            for (int i = 0; i < list.size(); i++) {
+////                bookService.update_pay("6", list.get(i).getOrder_num());
+//            }
+//        }
+//        resultjson.put("message", "退房成功");
+//        ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
         return null;
         return null;
     }
     }
 }
 }

+ 15 - 0
mhotel/src/com/happy/service/AppBookService.java

@@ -0,0 +1,15 @@
+package com.happy.service;
+
+import com.happy.Model.Booking;
+import com.happy.dto.IPage;
+
+import java.util.List;
+
+public interface AppBookService {
+
+
+
+    public String createOrder(String hotelId,String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId);
+
+
+}

+ 1 - 1
mhotel/src/com/happy/service/AppHomePageService.java

@@ -28,5 +28,5 @@ public interface AppHomePageService {
      * @param hotelId
      * @param hotelId
      * @return
      * @return
      */
      */
-    public Hotel getHotelAndHouseByHotelId(String hotelId);
+    public Hotel getHotelAndHouseByHotelId(String hotelId, String queryStartTime, String queryEndTime);
 }
 }

+ 89 - 0
mhotel/src/com/happy/service/impl/AppBookImplService.java

@@ -0,0 +1,89 @@
+package com.happy.service.impl;
+
+import com.baidubce.model.User;
+import com.happy.Model.AdminManager;
+import com.happy.Model.Booking;
+import com.happy.Model.Hotel;
+import com.happy.Model.House;
+import com.happy.Model.weixin.Users;
+import com.happy.Until.DateUtil;
+import com.happy.Until.Enum.OrderEnum;
+import com.happy.Until.Func;
+import com.happy.Until.TimeExchange;
+import com.happy.dao.BookDao;
+import com.happy.dto.IPage;
+import com.happy.service.*;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+
+@Service("AppBookService")
+public class AppBookImplService implements AppBookService {
+
+    @Resource
+    public BookService bookService;
+    @Resource
+    public HotelService hotelService;
+    @Resource
+    public HouseService houseService;
+    @Resource
+    public UserService userService;
+    @Resource
+    public AdminManagerService adminManagerService;
+
+    @Override
+    public String createOrder(String hotelId, String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId) {
+        if (Func.checkNull(hotelId) ||Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
+                ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
+            return null;
+
+        Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
+        House house = houseService.getById(Func.parseInt(houseId));
+        Users user = userService.queryByUserId(userId);
+        AdminManager adminManager = adminManagerService.getById(Func.parseInt(userId));
+
+
+        Booking booking = new Booking();
+
+        // 设置民宿信息
+        booking.setHotelName(hotel.getHname());
+        booking.setHotelHposition(hotel.getHposition());
+        booking.setHotelHpositionWens(hotel.getHpositionWens());
+        booking.setHotelManagerId(hotel.getManagerId());
+        booking.setHotelTownship(adminManager.getHotelTownship());
+        booking.setHotelConfig(hotel.getHconfig());
+        booking.setHotelType(hotel.getHtype());
+        booking.setHotelIsCanorder(Func.parseStr(hotel.getIsCanorder()));
+
+        // 设置房型信息
+        booking.setHouseId(Func.parseStr(house.getId()));
+        booking.setHouseName(house.gethName());
+        booking.setHouseConfig(house.gethConfig());
+        booking.setHouseUnitPrice(house.getPrice());
+        booking.setHouseOrderNumber(Func.parseInt(houseOrderNumber));
+        booking.setHouseAreas(house.gethAreas());
+        booking.setHouseRemake(house.getRemark());
+        double totalPrice = Func.parseInt(houseOrderNumber) * house.getPrice();
+        booking.setHouseTotalPrice(totalPrice);
+
+        // 设置住客信息
+        booking.setUserName(userName);
+        booking.setUserPhone(userPhone);
+        booking.setOrderStartTime(DateUtil.parseDateOnly(startTime));
+        booking.setOrderEndTime(DateUtil.parseDateOnly(endTime));
+        int day = DateUtil.getDayDiff(startTime,endTime);
+        String orderLiveTime= day+ OrderEnum.间.toString()+ day +OrderEnum.晚.toString();
+        booking.setOrderLiveTime(orderLiveTime);
+
+        // 订单信息
+        Integer orderNum = TimeExchange.StringToTimestamp(TimeExchange.getDate());// 订单号
+        booking.setOrderNum(Func.parseStr(orderNum));
+        booking.setCreateTime(DateUtil.getCurrentDate());
+        bookService.insertBooking(booking);
+
+
+        return null;
+    }
+}

+ 48 - 5
mhotel/src/com/happy/service/impl/AppHomePageImplService.java

@@ -3,6 +3,7 @@ package com.happy.service.impl;
 import com.happy.Model.Booking;
 import com.happy.Model.Booking;
 import com.happy.Model.Hotel;
 import com.happy.Model.Hotel;
 import com.happy.Model.House;
 import com.happy.Model.House;
+import com.happy.Until.DateUtil;
 import com.happy.Until.Func;
 import com.happy.Until.Func;
 import com.happy.Until.TimeExchange;
 import com.happy.Until.TimeExchange;
 import com.happy.dao.BookDao;
 import com.happy.dao.BookDao;
@@ -15,7 +16,10 @@ import com.happy.service.HouseService;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 @Service("AppHomePageService")
 @Service("AppHomePageService")
 public class AppHomePageImplService implements AppHomePageService {
 public class AppHomePageImplService implements AppHomePageService {
@@ -28,6 +32,8 @@ public class AppHomePageImplService implements AppHomePageService {
     public HouseService houseService;
     public HouseService houseService;
     @Resource
     @Resource
     public HotelService hotelService;
     public HotelService hotelService;
+    @Resource
+    public BookService bookService;
 
 
 
 
     @Override
     @Override
@@ -50,23 +56,60 @@ public class AppHomePageImplService implements AppHomePageService {
     }
     }
 
 
     @Override
     @Override
-    public Hotel getHotelAndHouseByHotelId(String hotelId) {
+    public Hotel getHotelAndHouseByHotelId(String hotelId, String queryStartTime, String queryEndTime) {
         if (Func.checkNull(hotelId))
         if (Func.checkNull(hotelId))
             return new Hotel();
             return new Hotel();
         Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
         Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
         if (Func.checkNull(hotel.getManagerId()))
         if (Func.checkNull(hotel.getManagerId()))
             return hotel;
             return hotel;
 
 
-        hotel.getManagerId();// 需求确定使用商户id关联房型
+        System.out.println(hotel.getManagerId());// 需求确定使用商户id关联房型
         StringBuffer strSql = new StringBuffer();
         StringBuffer strSql = new StringBuffer();
         strSql.append(" and manager_id = '").append(hotel.getManagerId()).append("' ");
         strSql.append(" and manager_id = '").append(hotel.getManagerId()).append("' ");
-        List houseList = houseService.queryList(strSql.toString());
+        List<House> houseList = houseService.queryList(strSql.toString());
+
+//        Map<String, House> houseMap =  new HashMap();
+//        houseList.forEach((House house) ->{
+//            if (house.getId() == 0)
+//                return;
+//            houseMap.put(Func.parseStr(house.getId()),house);
+//        });
+
 
 
         // 判断是否有房间,对每个房型进行标识
         // 判断是否有房间,对每个房型进行标识
-//        hotel.
+        StringBuffer strSqlBook = new StringBuffer();
+        strSqlBook.append(" and hotel_manager_id = '").append(hotel.getManagerId()).append("' ");
+        strSqlBook.append(" and order_start_time >= '").append(queryStartTime).append("' ");
+        strSqlBook.append(" and order_end_time < '").append(queryEndTime).append("' ");
+
+        List<Booking> bookList = bookService.queryList(strSqlBook.toString());
+
+        Map<String, Integer> houseBookingMap =  new HashMap();
+        Integer numberTemp = new Integer(0);
+        for (Booking booking: bookList) {
+            if (Func.checkNull(booking.getHouseId()))
+                continue;
+
+            if (houseBookingMap.containsKey(booking.getHouseId()))
+            {
+                numberTemp = houseBookingMap.get(booking.getHouseId());
+                int i = Func.parseInt(numberTemp) + booking.getHouseOrderNumber();
+                houseBookingMap.put(booking.getHouseId(),i);
+                continue;
+            }
+            houseBookingMap.put(booking.getHouseId(),booking.getHouseOrderNumber());
+        }
+
+        houseList.forEach((House house) ->{
+            if (!houseBookingMap.containsKey(house.getId()))
+                return;
 
 
+            int i = Func.parseInt(house.getNumber()) - Func.parseInt(houseBookingMap.get(house.getId()));
+            house.setRemark(Func.parseStr(i));
+        });
 
 
 
 
-        return null;
+        hotel.setHouseList(houseList);
+        return hotel;
     }
     }
 }
 }