Browse Source

Merge remote-tracking branch 'origin/master'

raojiaolong@163.com 2 years ago
parent
commit
6c1c547965

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

@@ -1,12 +1,14 @@
 package com.happy.Until.Enum;
 
+import com.happy.Until.Func;
+
 /**
  * 订单支付九种状态:
- *     1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
+ *     1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中,11状态异常
  */
 public enum PayEnum {
 
-    ONE(1,"待支付"),TWO(2,"已支付"),THREE(3,"待入住"),FOUR(4,"已入住"),FIVE(5,"已消费"),SIX(6,"支付超时"),SEVEN(7,"已取消"),EIGHT(8,"已退单"),NINE(9,"已退款"),TEN(10,"退款中");
+    ONE(1,"待支付"),TWO(2,"已支付"),THREE(3,"待入住"),FOUR(4,"已入住"),FIVE(5,"已消费"),SIX(6,"支付超时"),SEVEN(7,"已取消"),EIGHT(8,"已退单"),NINE(9,"已退款"),TEN(10,"退款中"),ELEVEN(11,"状态异常");
 
     private int num;
     private String payStatus;
@@ -16,6 +18,25 @@ public enum PayEnum {
         this.payStatus = payStatus;
     }
 
+    /**
+     * 遍历枚举类
+     * @param num
+     * @return
+     */
+    public static String getValueBykey(int num) {
+        try {
+            for (PayEnum type : PayEnum.values()) {
+                if (Func.parseInt(type.getNum()) == num) {
+                    return Func.parseStr(type.getNum());
+                }
+            }
+        } catch (Exception e) {
+            return Func.parseStr(ELEVEN.getNum());
+        }
+        return Func.parseStr(ELEVEN.getNum());
+    }
+
+
     public int getNum() {
         return num;
     }

+ 81 - 104
mhotel/src/com/happy/action/AppBookingAction.java

@@ -150,7 +150,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 Date createTime = DateUtil.parseDate(booking.getCreateTime(),DateUtil.Time_Formatter_Second);
                 // 对订单时间进行累加
                 String lockTime = TimeExchange.TimeRangeM(DateUtil.getFormatPaternDate(createTime),Func.parseInt(booking.getLockTime()));
-                // 当前时间 大于 锁定时间 为true
+                // 当前时间 大于 锁定时间 为true  且支付状态
                 boolean flag = TimeExchange.CompareDate(lockTime, TimeExchange.getDate());
                 if (flag)
                 {
@@ -259,6 +259,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     }
 
     /**
+     * bookingId 订单id
      * 商家在已支付,待入住时点退单 ,进入退款流程后退单
      *    在已入住,时点退单,进入退款流程后退款
      * @return
@@ -300,69 +301,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             book.setRefundWay(OrderEnum.微信退款.toString());
         }
 
-        // 进行判断如果订单是退款中,并且标识字段微信退款,则进入退款流程
-        if (Func.parseStr(PayEnum.TEN.getNum()).equals(book.getOrderStatus()) && OrderEnum.微信退款.toString().equals(book.getRefundWay())) {
-
-            String ip = WeiXinUtil.ip;
-            double money = book.getPayAccount();
-            int a = (int) (money * 100);
-            WechatUnifiedOrder w = new WechatUnifiedOrder();
-            w.setAppid(WeiXinUtil.appid_c);
-            w.setAttach("chuanghai");
-            w.setBody("chuanghai");
-            w.setMch_id(WeiXinUtil.account);
-            w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
-            w.setNotify_url(WeiXinUtil.ip_h + "/abkquery_refund.action");// 支付结果回调地址
-            w.setOpenid(open_id);
-            w.setOut_trade_no(book.getOrderNum());
-            String refund_order = WxUtil.mchOrderNo();
-            w.setOut_refund_no(refund_order);   // 退款单号
-            w.setSpbill_create_ip(ip);
-            w.setTotal_fee(a);
-            w.setRefund_fee(a);   // 退款金额
-            w.setTrade_type("JSAPI");
-            SortedMap<String, String> params = new TreeMap<>();
-            params.put("appid", w.getAppid());
-            params.put("mch_id", w.getMch_id());
-            params.put("nonce_str", w.getNonce_str());
-            params.put("notify_url", w.getNotify_url());
-            params.put("out_refund_no", w.getOut_refund_no());   // 退款单号
-            params.put("out_trade_no", w.getOut_trade_no());
-            params.put("refund_fee",w.getRefund_fee()+"");  // 退款金额
-            params.put("total_fee", w.getTotal_fee() + "");
-
-            w.setSign(PayWxUtil.getSign(params, WeiXinUtil.key));
-            params.put("sign", w.getSign());
-            //String retXml = JaxbUtil.getRequestXml(params);
-            String xml = "<xml>" +
-                    "<appid>" + w.getAppid() + "</appid>" +
-                    "<mch_id>" + w.getMch_id() + "</mch_id>" +
-                    "<nonce_str>" + w.getNonce_str() + "</nonce_str>" +
-                    "<notify_url>" + w.getNotify_url() + "</notify_url>" +
-                    "<out_refund_no>" + w.getOut_refund_no() + "</out_refund_no>" +
-                    "<out_trade_no>" + w.getOut_trade_no() + "</out_trade_no>"	+
-                    "<refund_fee>" + w.getRefund_fee()+"" + "</refund_fee>" +
-                    "<total_fee>" + w.getTotal_fee() + "" + "</total_fee>" +
-                    "<sign>" + w.getSign() + "</sign>"	+
-                    "</xml>";
-            String msg = HttpUtils.post2("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
-            if (msg.indexOf("FAIL") > -1) {
-                jsonObject.put("code", 507);
-                jsonObject.put("message", "退款失败");
-                ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-                return null;
-            }
-
-            // 设置订单状态为退款中
-            book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
-            bookService.updateBooking(book);  // 退款中
-
-            jsonObject.put("code", 200);
-            jsonObject.put("message", "退款申请已提交,请稍候查询");
-            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-            return null;
-        }
-
+        jsonObject = refundMethod(book,users.getOpenid());
+        ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
     }
 
@@ -376,56 +316,95 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
      * @return
      */
     public String cancelBooking() throws Exception {
-        if (Func.checkNull(bookingId))
-            return null;
-
         JSONObject jsonObject = new JSONObject();
+        if (Func.checkNull(this.bookingId)) {
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, "未传入bookingId");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
 
         // 取消订单,修改订单的支付状态
-        String mess = bookService.cancelBooking(bookingId);
-        if (!Func.checkNull(mess)) {
+        Booking book = bookService.getById(Func.parseInt(bookingId));
+        if (book == null )
+        {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.message, mess);
+            jsonObject.put(B.message, "未获取到订单信息,请重新查询");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
 
-        Booking booking = bookService.getById(Func.parseInt(this.bookingId));
-        if (booking == null )
-         {
+        //是否能取消订单(1是 2否)
+        if (Func.parseInt(book.getHotelIsCanorder()) == 2)
+        {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.message, "未获取到订单信息,请重新查询");
+            jsonObject.put(B.message, "商家设置不可取消订单,请联系商家");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
-         }
-        if (Func.checkNull(booking.getRefundWay()) && Func.parseStr(PayEnum.SEVEN.getNum()).equals(booking.getOrderStatus()))
+        }
+
+        AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
+
+        //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
+        int status = Func.parseInt(book.getOrderStatus());
+        if (status == 1)
         {
+            book.setOrderStatus(Func.parseStr(PayEnum.SEVEN.getNum())); // 如果在1待支付情况,用户点击取消订单按钮,后台直接修改取消订单操作
+            book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
+            book.setRemake(Func.parseStr(PayEnum.FIVE.getNum()));
+            bookService.updateBooking(book);
             jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
             jsonObject.put(B.message, "已取消订单");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
+
+        }else if (status == 2 || status == 3)
+        {
+            // 如果在2已支付,3待入住 情况,用户点击取消订单按钮,后台先修改状态为退款中,然后走退款流程
+            book.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
+            book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
+            book.setRemake(Func.parseStr(PayEnum.FIVE.getNum()));
+            if (book.getPayAccount() > 0)
+            {
+                // 注明如果支付金额大于0,则需要退款: (标识走退款操作)
+                book.setRefundWay(OrderEnum.微信退款.toString());
+            }
         }
 
+        Users users = userService.queryByUserId(book.getCreateUserid()); // 用户信息
+        if (users == null) {
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, "未查询到当前用户数据users,请先授权");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
 
-        // 进行判断如果订单是退款中,并且标识字段微信退款,则进入退款流程
-        if (Func.parseStr(PayEnum.TEN.getNum()).equals(booking.getOrderStatus()) && OrderEnum.微信退款.toString().equals(booking.getRefundWay())) {
-            if (Func.checkNull(this.open_id) || Func.checkNull(this.bookingId)) {
-                jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-                jsonObject.put(B.message, "未传入open_id和bookingId");
-                ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-                return null;
-            }
+        jsonObject = refundMethod(book,users.getOpenid());
+        jsonObject.put(B.data, book);
+        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+        return null;
+    }
 
-            Users users = userService.queryByOpenid(open_id); // 用户信息
-            if (users == null || booking == null) {
-                jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-                jsonObject.put(B.message, "未查询到当前用户数据users,请先授权");
-                ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-                return null;
-            }
+    /**
+     * 退款方法
+     * @param book
+     * @param open_id
+     * @return
+     * @throws Exception
+     */
+    public JSONObject refundMethod(Booking book,String open_id) throws Exception {
+        JSONObject  jsonObject  = new JSONObject();
+        if (book == null || Func.checkNull(open_id))
+        {
+            jsonObject.put("code", 400);
+            jsonObject.put("message", "未传入book和open_id数据---refundMethod");
+            return jsonObject;
+        }
 
+        // 进行判断如果订单是退款中,并且标识字段微信退款,则进入退款流程
+        if (Func.parseStr(PayEnum.TEN.getNum()).equals(book.getOrderStatus()) && OrderEnum.微信退款.toString().equals(book.getRefundWay())) {
             String ip = WeiXinUtil.ip;
-            double money = booking.getPayAccount();
+            double money = book.getPayAccount();
             int a = (int) (money * 100);
             WechatUnifiedOrder w = new WechatUnifiedOrder();
             w.setAppid(WeiXinUtil.appid_c);
@@ -435,7 +414,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
             w.setNotify_url(WeiXinUtil.ip_h + "/abkquery_refund.action");// 支付结果回调地址
             w.setOpenid(open_id);
-            w.setOut_trade_no(booking.getOrderNum());
+            w.setOut_trade_no(book.getOrderNum());
             String refund_order = WxUtil.mchOrderNo();
             w.setOut_refund_no(refund_order);   // 退款单号
             w.setSpbill_create_ip(ip);
@@ -476,23 +455,21 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             }
 
             // 设置订单状态为退款中
-            booking.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
-            booking.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
-            bookService.updateBooking(booking);  // 退款中
+            book.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
+            book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+            bookService.updateBooking(book);  // 退款中
 
             jsonObject.put("code", 200);
-            jsonObject.put("message", "退款申请已提交,请稍候查询");
-            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-            return null;
+            jsonObject.put("message", "申请已提交,请稍候查询");
+            return jsonObject;
         }
 
-        jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.message, "取消订单成功");
-        jsonObject.put(B.data, booking);
-        ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-        return null;
+        jsonObject.put("code", 400);
+        jsonObject.put("message", "提交申请失败");
+        return jsonObject;
     }
 
+
 //    /**
 //     * open_id
 //     * bookingId

+ 2 - 1
mhotel/src/com/happy/dao/impl/HotelImplDao.java

@@ -140,10 +140,11 @@ public class HotelImplDao implements HotelDao {
     @Override
     public List<Hotel> queryPagePrice(String sqlx, int page, int rows) {
         int start = (page - 1) * rows;// 每页的起始下标
-        String sql = "SELECT a.*,b.min_price,c.hotel_township , d.hotel_township_name FROM `hotel` a " +
+        String sql = "SELECT a.*,b.min_price,c.hotel_township , d.hotel_township_name , e.h_type_name FROM `hotel` a " +
                 "left join (select manager_id,min(price) min_price from house group by manager_id) b on a.manager_id = b.manager_id " +
                 "left join (select manager_id,hotel_township hotel_township from admin_manager group by manager_id) c on a.manager_id = c.manager_id " +
                 "LEFT JOIN (  SELECT  id,name as hotel_township_name  FROM  hotel_dict GROUP BY  id) d ON d.id = c.hotel_township " +
+                "LEFT JOIN (  SELECT  id,name as h_type_name  FROM  hotel_dict GROUP BY  id) e ON e.id = a.htype      " +
                 " WHERE status=1 "+sqlx+" ORDER BY id DESC limit :start,:rows ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("start", start);

+ 2 - 8
mhotel/src/com/happy/service/impl/BookImplService.java

@@ -101,6 +101,7 @@ public class BookImplService implements BookService {
         {
             book.setOrderStatus(Func.parseStr(PayEnum.SEVEN.getNum())); // 如果在1待支付情况,用户点击取消订单按钮,后台直接修改取消订单操作
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
+            book.setRemake(Func.parseStr(PayEnum.FIVE.getNum()));
             bookDao.updateBooking(book);
 
             return null;
@@ -108,6 +109,7 @@ public class BookImplService implements BookService {
         {
             book.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum())); // 如果在2已支付,3待入住 情况,用户点击取消订单按钮,后台先修改状态为退款中,然后走退款流程
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
+            book.setRemake(Func.parseStr(PayEnum.FIVE.getNum()));
             if (book.getPayAccount() > 0)
             {
                 // 注明如果支付金额大于0,则需要退款: (标识走退款操作)
@@ -115,14 +117,6 @@ public class BookImplService implements BookService {
             }
             bookDao.updateBooking(book);
 
-            // 推送消息给商家
-            String sendMsg = "订单:"+ book.getOrderNum() +"已取消";
-            if (!Func.checkPhone(book.getOrderStartTime()) && !Func.checkPhone(book.getOrderEndTime())  && !Func.checkNull(book.getHotelName()) && !Func.checkNull(book.getUserName()))
-            {
-                String live_end = book.getOrderStartTime().substring(0,10)  +"~"+  book.getOrderEndTime().substring(0,10);
-                Message2.send(adminManager.getOpenid(),book.getOrderNum(),book.getHouseName(),live_end,book.getUserName(), book.getHotelName(),book.getHouseId());
-            }
-
             return null;
         }
         return "当前状态下,不可取消订单";