Administrator 2 gadi atpakaļ
vecāks
revīzija
bbf0508b04
1 mainītis faili ar 197 papildinājumiem un 92 dzēšanām
  1. 197 92
      mhotel/src/com/happy/action/AppBookingAction.java

+ 197 - 92
mhotel/src/com/happy/action/AppBookingAction.java

@@ -259,6 +259,115 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     }
     }
 
 
     /**
     /**
+     * 商家在已支付,待入住时点退单 ,进入退款流程后退单
+     *    在已入住,时点退单,进入退款流程后退款
+     * @return
+     */
+    public String chargeback() throws Exception {
+        if (Func.checkNull(bookingId))
+            return null;
+
+        JSONObject jsonObject = new JSONObject();
+        Booking book = bookService.getById(Func.parseInt(bookingId));
+        Users users = userService.queryByUserId(book.getCreateUserid());
+        if (book == null || users == null)
+            return null;
+
+        //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()));
+            bookService.updateBooking(book);
+            jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
+            jsonObject.put(B.message, ResultStatusCode.OK.getMsg());
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }else if (status == 2 || status == 3)
+        {
+            book.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum())); // 如果在2已支付,3待入住 情况,商家点击取消订单按钮,后台先修改状态为退款中,然后走退款流程
+            book.setRemake(Func.parseStr(PayEnum.EIGHT.getNum()));
+        }else if(status == 4)
+        {
+            book.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum())); // 如果在2已支付,3待入住 情况,商家点击取消订单按钮,后台先修改状态为退款中,然后走退款流程
+            book.setRemake(Func.parseStr(PayEnum.NINE.getNum()));
+        }
+
+        if (book.getPayAccount() > 0)
+        {
+            // 注明如果支付金额大于0,则需要退款: (标识走退款操作)
+            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;
+        }
+
+        return null;
+    }
+
+
+    /**
      * bookingId 订单id
      * bookingId 订单id
      * open_id
      * open_id
      * 取消订单功能: 用户点击
      * 取消订单功能: 用户点击
@@ -267,7 +376,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
      * @return
      * @return
      */
      */
     public String cancelBooking() throws Exception {
     public String cancelBooking() throws Exception {
-        if (Func.checkNull(getBookingId()))
+        if (Func.checkNull(bookingId))
             return null;
             return null;
 
 
         JSONObject jsonObject = new JSONObject();
         JSONObject jsonObject = new JSONObject();
@@ -324,7 +433,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             w.setBody("chuanghai");
             w.setBody("chuanghai");
             w.setMch_id(WeiXinUtil.account);
             w.setMch_id(WeiXinUtil.account);
             w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
             w.setNonce_str(PayWxUtil.getNonceStr());// 随机支付串
-            w.setNotify_url(WeiXinUtil.ip_h + "/appquery_refund.action");// 支付结果回调地址
+            w.setNotify_url(WeiXinUtil.ip_h + "/abkquery_refund.action");// 支付结果回调地址
             w.setOpenid(open_id);
             w.setOpenid(open_id);
             w.setOut_trade_no(booking.getOrderNum());
             w.setOut_trade_no(booking.getOrderNum());
             String refund_order = WxUtil.mchOrderNo();
             String refund_order = WxUtil.mchOrderNo();
@@ -384,90 +493,90 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         return null;
         return null;
     }
     }
 
 
-    /**
-     * open_id
-     * bookingId
-     * 微信退款功能
-     */
-    public String refundBooking() throws Exception {
-        JSONObject resultJson = new JSONObject();
-        if (Func.checkNull(this.open_id) || Func.checkNull(this.bookingId)) {
-            resultJson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-            resultJson.put(B.message,  "未传入open_id和bookingId");
-            ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
-            return null;
-        }
-
-        Users users = userService.queryByOpenid(open_id); // 用户信息
-        Booking booking = bookService.getById(Func.parseInt(bookingId)); // 订单信息
-        if (users == null || booking == null) {
-            resultJson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-            resultJson.put(B.message, "未查询到当前用户数据users,请先授权");
-            ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
-            return null;
-        }
-
-        String ip = WeiXinUtil.ip;
-        double money = booking.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 + "/appquery_refund.action");// 支付结果回调地址
-        w.setOpenid(open_id);
-        w.setOut_trade_no(booking.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 = HttpsClient.sendPost2("https://api.mch.weixin.qq.com/secapi/pay/refund", retXml);
-        String msg = HttpUtils.post2("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
-        if (msg.indexOf("FAIL") > -1) {
-            resultJson.put("code", 507);
-            resultJson.put("message", "退款失败");
-            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
-            return null;
-        }
-
-        // 设置订单状态为退款中
-        booking.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
-        booking.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
-        bookService.updateBooking(booking);  // 退款中
-
-        resultJson.put("code", 200);
-        resultJson.put("message", "退款申请已提交,请稍候查询");
-        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
-        return null;
-    }
+//    /**
+//     * open_id
+//     * bookingId
+//     * 微信退款功能
+//     */
+//    public String refundBooking() throws Exception {
+//        JSONObject resultJson = new JSONObject();
+//        if (Func.checkNull(this.open_id) || Func.checkNull(this.bookingId)) {
+//            resultJson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+//            resultJson.put(B.message,  "未传入open_id和bookingId");
+//            ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+//            return null;
+//        }
+//
+//        Users users = userService.queryByOpenid(open_id); // 用户信息
+//        Booking booking = bookService.getById(Func.parseInt(bookingId)); // 订单信息
+//        if (users == null || booking == null) {
+//            resultJson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+//            resultJson.put(B.message, "未查询到当前用户数据users,请先授权");
+//            ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+//            return null;
+//        }
+//
+//        String ip = WeiXinUtil.ip;
+//        double money = booking.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(booking.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 = HttpsClient.sendPost2("https://api.mch.weixin.qq.com/secapi/pay/refund", retXml);
+//        String msg = HttpUtils.post2("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
+//        if (msg.indexOf("FAIL") > -1) {
+//            resultJson.put("code", 507);
+//            resultJson.put("message", "退款失败");
+//            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+//            return null;
+//        }
+//
+//        // 设置订单状态为退款中
+//        booking.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
+//        booking.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+//        bookService.updateBooking(booking);  // 退款中
+//
+//        resultJson.put("code", 200);
+//        resultJson.put("message", "退款申请已提交,请稍候查询");
+//        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+//        return null;
+//    }
 
 
     /* 退款回调 */
     /* 退款回调 */
     public String query_refund() throws Exception {
     public String query_refund() throws Exception {
@@ -508,14 +617,13 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 book.setRefundTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
                 book.setRefundTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
                 book.setRefundAmount(book.getHouseTotalPrice());
                 book.setRefundAmount(book.getHouseTotalPrice());
                 book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
                 book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
-                book.setOrderStatus(Func.parseStr(PayEnum.SEVEN.getNum()));
+                book.setOrderStatus(PayEnum.getValueBykey(Func.parseInt(book.getRemake()))); // 将走微信前的标识,写入回调函数
                 bookService.updateBooking(book);
                 bookService.updateBooking(book);
 
 
-
                 // 发送成功消息给商家和用户
                 // 发送成功消息给商家和用户
                 AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
                 AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
                 Users users = userService.queryByUserId(book.getCreateUserid());
                 Users users = userService.queryByUserId(book.getCreateUserid());
-                String sendMsg = "订单:"+ book.getOrderNum() +"已退款成功,请注意查看";
+                String sendMsg = "订单:"+ book.getOrderNum();
                 // 推给用户
                 // 推给用户
                 Message.send(users.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime());
                 Message.send(users.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime());
 
 
@@ -528,7 +636,6 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 }
                 }
                 Message2.send(adminManager.getOpenid(),book.getOrderNum(),book.getHouseName(),live_end,book.getUserName(),hotelName,Func.parseStr(book.getId()));
                 Message2.send(adminManager.getOpenid(),book.getOrderNum(),book.getHouseName(),live_end,book.getUserName(),hotelName,Func.parseStr(book.getId()));
 
 
-
             }
             }
         }
         }
         String returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
         String returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
@@ -542,8 +649,6 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         return null;
         return null;
     }
     }
 
 
-
-
     /**
     /**
      * bookingId 订单id
      * bookingId 订单id
      * 删除订单功能(假删除)
      * 删除订单功能(假删除)