Browse Source

订单功能

Administrator 2 years atrás
parent
commit
c7f80fac15

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

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

+ 27 - 2
mhotel/src/com/happy/Until/Enum/PayEnum.java

@@ -2,8 +2,33 @@ package com.happy.Until.Enum;
 
 
 /**
 /**
  * 订单支付九种状态:
  * 订单支付九种状态:
- *     待支付,支付超时,已支付,已取消,已退单,待入住,已入住,已退款,已消费;
+ *     1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
  */
  */
 public enum PayEnum {
 public enum PayEnum {
-    待支付,支付超时,已支付,已取消,已退单,待入住,已入住,已退款,已消费;
+
+    ONE(1,"待支付"),TWO(2,"已支付"),THREE(3,"待入住"),FOUR(4,"已入住"),FIVE(5,"已消费"),SIX(6,"支付超时"),SEVEN(7,"已取消"),EIGHT(8,"已退单"),NINE(9,"已退款");
+
+    private int num;
+    private String payStatus;
+
+    PayEnum(int num, String payStatus) {
+        this.num = num;
+        this.payStatus = payStatus;
+    }
+
+    public int getNum() {
+        return num;
+    }
+
+    public void setNum(int num) {
+        this.num = num;
+    }
+
+    public String getPayStatus() {
+        return payStatus;
+    }
+
+    public void setPayStatus(String payStatus) {
+        this.payStatus = payStatus;
+    }
 }
 }

+ 69 - 10
mhotel/src/com/happy/action/AppBookingAction.java

@@ -97,21 +97,21 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
 
 
 
     /**
     /**
+     * hotelId; // 酒店id
+     * houseId; // 房型id
+     * startTime; // 订房开始时间
+     * endTime;   // 订房结束时间
+     * houseOrderNumber; // 订房数量
+     * userName; // 住客姓名
+     * userPhone; // 住客联系电话
+     * userId; // 下单人id
      * 用户点击订房操作,生成订单
      * 用户点击订房操作,生成订单
      */
      */
     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();
         JSONObject jsonObject = new JSONObject();
-        if (Func.checkNull(hotelId) ||Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
+        if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
                 ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
                 ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
         {
         {
             jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
@@ -120,7 +120,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             return null;
             return null;
         }
         }
 
 
-        appBookService.createOrder(hotelId, houseId, startTime, endTime, houseOrderNumber,userName,userPhone, userId);
+        appBookService.createOrder(houseId, startTime, endTime, houseOrderNumber,userName,userPhone, userId);
 
 
         jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
         jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
         ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
         ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
@@ -128,6 +128,65 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     }
     }
 
 
     /**
     /**
+     * 再次预订
+     * @return
+     */
+    public String reCreateOrder()
+    {
+        // 插入订单数据到表中
+        JSONObject jsonObject = new JSONObject();
+        if (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.reCreateOrder(houseId, startTime, endTime, houseOrderNumber,userName,userPhone, userId);
+        jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
+        ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+        return null;
+    }
+
+
+
+
+    /**
+     *验证是否有房间
+     * houseId,startTime,endTime
+     * @return
+     */
+    public String varificationHouse()
+    {
+        JSONObject jsonObject = new JSONObject();
+        if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime))
+        {
+            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
+            ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+            return null;
+        }
+
+        String backMessage = appBookService.varificationHouse( houseId, startTime, endTime);
+
+        if (!Func.checkNull(backMessage))
+        {
+            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.MESSAGE,backMessage);
+            ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+            return null;
+        }
+
+        jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
+        jsonObject.put(B.MESSAGE,backMessage);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+        return null;
+    }
+
+
+    /**
      * 用户支付操作
      * 用户支付操作
      * @return
      * @return
      */
      */

+ 4 - 2
mhotel/src/com/happy/action/AppMePageAction.java

@@ -114,9 +114,10 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
     }
     }
 
 
     /**
     /**
+     * userId 当前用户id,获取列表
      * 进入我的页面,跳转常用旅客列表
      * 进入我的页面,跳转常用旅客列表
      */
      */
-    public void getUserContact()
+    public void getUserContactList()
     {
     {
 //        String userId = "15461"; // 用户id
 //        String userId = "15461"; // 用户id
         // 通过用户id查询所有订单列表数据
         // 通过用户id查询所有订单列表数据
@@ -135,8 +136,9 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
 
 
     /**
     /**
      * 用户点击设置按钮,获取数据
      * 用户点击设置按钮,获取数据
+     * 通过用户id查询用户信息
      */
      */
-    public void queryUsers()
+    public void queryUsersById()
     {
     {
         if (Func.checkNull(userId))
         if (Func.checkNull(userId))
             return;
             return;

+ 36 - 2
mhotel/src/com/happy/service/AppBookService.java

@@ -8,8 +8,42 @@ import java.util.List;
 public interface AppBookService {
 public interface AppBookService {
 
 
 
 
-
-    public String createOrder(String hotelId,String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId);
+    /**
+     * 创建订单信息
+     * @param houseId
+     * @param startTime
+     * @param endTime
+     * @param houseOrderNumber
+     * @param userName
+     * @param userPhone
+     * @param userId
+     * @return
+     */
+    public String createOrder(String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId);
+
+
+    /**
+     * 再次预订订单信息
+     * @param houseId
+     * @param startTime
+     * @param endTime
+     * @param houseOrderNumber
+     * @param userName
+     * @param userPhone
+     * @param userId
+     * @return
+     */
+    public String reCreateOrder(String houseId,String startTime,String endTime,String houseOrderNumber,String userName,String userPhone, String userId);
+
+    /**
+     * 验证单个房间是否
+     * @param houseId
+     * @param startTime
+     * @param endTime
+
+     * @return
+     */
+    public String varificationHouse(String houseId, String startTime, String endTime) ;
 
 
 
 
 }
 }

+ 101 - 3
mhotel/src/com/happy/service/impl/AppBookImplService.java

@@ -8,6 +8,7 @@ import com.happy.Model.House;
 import com.happy.Model.weixin.Users;
 import com.happy.Model.weixin.Users;
 import com.happy.Until.DateUtil;
 import com.happy.Until.DateUtil;
 import com.happy.Until.Enum.OrderEnum;
 import com.happy.Until.Enum.OrderEnum;
+import com.happy.Until.Enum.PayEnum;
 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;
@@ -16,7 +17,9 @@ import com.happy.service.*;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 
 
 @Service("AppBookService")
 @Service("AppBookService")
@@ -34,13 +37,15 @@ public class AppBookImplService implements AppBookService {
     public AdminManagerService adminManagerService;
     public AdminManagerService adminManagerService;
 
 
     @Override
     @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)
+    public String createOrder(String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId) {
+        if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
                 ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
                 ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
             return null;
             return null;
 
 
-        Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
         House house = houseService.getById(Func.parseInt(houseId));
         House house = houseService.getById(Func.parseInt(houseId));
+        StringBuilder s1 = new StringBuilder("");
+        s1.append(" and manager_id = '").append(house.getManagerId()).append("'");
+        Hotel hotel = hotelService.getOen(s1.toString());
         Users user = userService.queryByUserId(userId);
         Users user = userService.queryByUserId(userId);
         AdminManager adminManager = adminManagerService.getById(Func.parseInt(userId));
         AdminManager adminManager = adminManagerService.getById(Func.parseInt(userId));
 
 
@@ -80,10 +85,103 @@ public class AppBookImplService implements AppBookService {
         // 订单信息
         // 订单信息
         Integer orderNum = TimeExchange.StringToTimestamp(TimeExchange.getDate());// 订单号
         Integer orderNum = TimeExchange.StringToTimestamp(TimeExchange.getDate());// 订单号
         booking.setOrderNum(Func.parseStr(orderNum));
         booking.setOrderNum(Func.parseStr(orderNum));
+        booking.setOrderStatus(Func.parseStr(PayEnum.ONE.getNum())); // 1待支付状态
         booking.setCreateTime(DateUtil.getFormatPaternDate(DateUtil.getCurrentDate()));
         booking.setCreateTime(DateUtil.getFormatPaternDate(DateUtil.getCurrentDate()));
         bookService.insertBooking(booking);
         bookService.insertBooking(booking);
 
 
 
 
         return null;
         return null;
     }
     }
+
+    @Override
+    public String reCreateOrder(String houseId, String startTime, String endTime, String houseOrderNumber, String userName, String userPhone, String userId) {
+        if (Func.checkNull(houseId) ||Func.checkNull(startTime) ||Func.checkNull(endTime)
+                ||Func.checkNull(houseOrderNumber) ||Func.checkNull(userName) ||Func.checkNull(userPhone) ||Func.checkNull(userId))
+            return null;
+
+        House house = houseService.getById(Func.parseInt(houseId));
+        StringBuilder s1 = new StringBuilder("");
+        s1.append(" and manager_id = '").append(house.getManagerId()).append("'");
+        Hotel hotel = hotelService.getOen(s1.toString());
+        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(startTime);
+        booking.setOrderEndTime(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.setOrderStatus(Func.parseStr(PayEnum.ONE.getNum())); // 待支付状态
+        booking.setCreateTime(DateUtil.getFormatPaternDate(DateUtil.getCurrentDate()));
+        bookService.insertBooking(booking);
+
+
+        return null;
+    }
+
+    @Override
+    public String varificationHouse(String houseId, String startTime, String endTime) {
+
+        House house = houseService.getById(Func.parseInt(houseId));
+
+        // 判断是否有房间,对每个房型进行标识
+        StringBuffer strSqlBook = new StringBuffer();
+        strSqlBook.append(" and house_id = '").append(house.getId()).append("' ");
+        strSqlBook.append(" and hotel_manager_id = '").append(house.getManagerId()).append("' ");
+        strSqlBook.append(" and order_start_time >= '").append(startTime).append("' ");
+        strSqlBook.append(" and order_end_time < '").append(endTime).append("' ");
+
+        //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
+        strSqlBook.append(" and order_status = '").append(PayEnum.ONE.getNum()).append("' ");
+        strSqlBook.append(" or order_status = '").append(PayEnum.TWO.getNum()).append("' ");
+        strSqlBook.append(" or order_status = '").append(PayEnum.THREE.getNum()).append("' ");
+        strSqlBook.append(" or order_status = '").append(PayEnum.FOUR.getNum()).append("' ");
+
+
+
+        List<Booking> bookList = bookService.queryList(strSqlBook.toString());
+
+        int totalNum = 0;
+        for (Booking booking: bookList) {
+            if (Func.checkNull(booking.getHouseId()))
+                continue;
+
+            totalNum += booking.getHouseOrderNumber();
+        }
+
+        if (totalNum >= house.getNumber())
+            return OrderEnum.房间已满.toString();
+        return null;
+    }
 }
 }