Преглед на файлове

Merge remote-tracking branch 'origin/master'

raojiaolong@163.com преди 2 години
родител
ревизия
ba04dfecf7
променени са 1 файла, в които са добавени 88 реда и са изтрити 99 реда
  1. 88 99
      mhotel/src/com/happy/action/AppBookingAction.java

+ 88 - 99
mhotel/src/com/happy/action/AppBookingAction.java

@@ -342,60 +342,60 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
 
         // 取消订单,修改订单的支付状态
         // 取消订单,修改订单的支付状态
         Booking book = bookService.getById(Func.parseInt(bookingId));
         Booking book = bookService.getById(Func.parseInt(bookingId));
-        if (book == null )
-        {
+        if (book == null ) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.message, "未获取到订单信息,请重新查询");
             jsonObject.put(B.message, "未获取到订单信息,请重新查询");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
             return null;
         }
         }
-
-        AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
-
+        // 查询用户信息
+        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;
+        }
+        //是否能取消订单(1是 2否)
+        if (Func.parseInt(book.getHotelIsCanorder()) == 2) {
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, "商家设置不可取消订单,请联系商家");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
         //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
         //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
         int status = Func.parseInt(book.getOrderStatus());
         int status = Func.parseInt(book.getOrderStatus());
-        if (status == PayEnum.待入住.getNum())
-        {
+        if (status == PayEnum.待支付.getNum() || status == PayEnum.支付超时.getNum()) {
             book.setOrderStatus(Func.parseStr(PayEnum.已取消.getNum())); // 如果在1待支付情况,用户点击取消订单按钮,后台直接修改取消订单操作
             book.setOrderStatus(Func.parseStr(PayEnum.已取消.getNum())); // 如果在1待支付情况,用户点击取消订单按钮,后台直接修改取消订单操作
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
             book.setRemake(Func.parseStr(PayEnum.已取消.getPayStatus()));
             book.setRemake(Func.parseStr(PayEnum.已取消.getPayStatus()));
             bookService.updateBooking(book);
             bookService.updateBooking(book);
             jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
             jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
-            jsonObject.put(B.message, "已取消订单");
+            jsonObject.put(B.message, "已取消");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
             return null;
-
-        }else if (status == PayEnum.已支付.getNum() || status == PayEnum.待入住.getNum())
-        {
-            // 如果在2已支付,3待入住 情况,用户点击取消订单按钮,后台先修改状态为退款中,然后走退款流程
-            book.setOrderStatus(Func.parseStr(PayEnum.退款中.getNum()));
-            book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
-            book.setRemake(Func.parseStr(PayEnum.已取消.getPayStatus()));
-            if (book.getPayAccount() > 0)
-            {
-                // 注明如果支付金额大于0,则需要退款: (标识走退款操作)
-                book.setRefundWay(OrderEnum.微信退款.toString());
-            }
         }
         }
-
-        //是否能取消订单(1是 2否)
-        if (Func.parseInt(book.getHotelIsCanorder()) == 2)
-        {
+        if (status == PayEnum.已入住.getNum()) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.message, "商家设置不可取消订单,请联系商家");
+            jsonObject.put(B.message, "已入住,请前往前台办理退款");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
             return null;
         }
         }
-
-        Users users = userService.queryByUserId(book.getCreateUserid()); // 用户信息
-        if (users == null) {
+        if (status == PayEnum.已消费.getNum() || status == PayEnum.已取消.getNum() || status == PayEnum.已退单.getNum() || status == PayEnum.已退款.getNum()) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.message, "未查询到当前用户数据users,请先授权");
+            jsonObject.put(B.message, "订单已完成,不可进行操作");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+        if (status == PayEnum.退款中.getNum()) {
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, "退款中,请勿重复操作");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
             return null;
         }
         }
-
         // 退款操作
         // 退款操作
+        book.setRemake(Func.parseStr(PayEnum.已取消.getPayStatus()));
+        book.setRefundWay(OrderEnum.微信退款.toString());
         jsonObject = refundMethod(book,users.getOpenid());
         jsonObject = refundMethod(book,users.getOpenid());
         jsonObject.put(B.data, book);
         jsonObject.put(B.data, book);
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
@@ -411,81 +411,70 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
      */
      */
     public JSONObject refundMethod(Booking book,String open_id) throws Exception {
     public JSONObject refundMethod(Booking book,String open_id) throws Exception {
         JSONObject  jsonObject  = new JSONObject();
         JSONObject  jsonObject  = new JSONObject();
-        if (book == null || Func.checkNull(open_id))
-        {
+        if (book == null || Func.checkNull(open_id)) {
             jsonObject.put("code", 400);
             jsonObject.put("code", 400);
             jsonObject.put("message", "未传入book和open_id数据---refundMethod");
             jsonObject.put("message", "未传入book和open_id数据---refundMethod");
             return jsonObject;
             return jsonObject;
         }
         }
-
         // 进行判断如果订单是退款中,并且标识字段微信退款,则进入退款流程
         // 进行判断如果订单是退款中,并且标识字段微信退款,则进入退款流程
-        if (Func.parseStr(PayEnum.退款中.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 = 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) {
-                jsonObject.put("code", 507);
-                jsonObject.put("message", "退款失败");
-                ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
-                return null;
-            }
-
-            // 设置订单状态为退款中
-            book.setOrderStatus(Func.parseStr(PayEnum.退款中.getNum()));
-            book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
-            bookService.updateBooking(book);  // 退款中
-
-            // 用户在待支付状态下取消了订单时,写入数据操作
-            bookinglogService.addBooklog("用户在取消了订单,正进入退款流程",book);
-
-            jsonObject.put("code", 200);
-            jsonObject.put("message", "申请已提交,请稍候查询");
-            return jsonObject;
+        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 = 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) {
+            jsonObject.put("code", 507);
+            jsonObject.put("message", "退款失败");
+            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
         }
         }
-
-        jsonObject.put("code", 400);
-        jsonObject.put("message", "提交申请失败");
+        // 设置订单状态为退款中
+        book.setOrderStatus(Func.parseStr(PayEnum.退款中.getNum()));
+        book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+        bookService.updateBooking(book);  // 退款中
+        // 用户在待支付状态下取消了订单时,写入数据操作
+        bookinglogService.addBooklog("用户在取消了订单,正进入退款流程",book);
+        jsonObject.put("code", 200);
+        jsonObject.put("message", "申请已提交,请稍候查询");
         return jsonObject;
         return jsonObject;
     }
     }