Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

raojiaolong@163.com 2 лет назад
Родитель
Сommit
eace4d6ee1

+ 1 - 1
mhotel/src/com/happy/Model/AdminManager.java

@@ -98,7 +98,7 @@ public class AdminManager {
 	private Integer status;
 
 	/**
-	 * 备注
+	 * 备注\
 	 */
 	private String remark;
 

+ 2 - 2
mhotel/src/com/happy/Model/Booking.java

@@ -8,8 +8,8 @@ public class Booking {
 
   private Integer id;
   private String orderNum; // 订单号
-  private String orderStatus; // 状态,1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
-  private String orderName; // 状态名称,1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
+  private String orderStatus; // 状态,1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
+  private String orderName; // 状态名称,1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
   private String userIdnumber; // 住客身份号
   private String userName;//住客姓名
   private String userPhone;// 住客手机号

+ 1 - 1
mhotel/src/com/happy/Model/weixin/WeiXinUtil.java

@@ -6,7 +6,7 @@ public class WeiXinUtil {
     public static String appid_c = "wxa5cc2178ff34bc8e";
     public static String ip = "171.34.223.11";
     public static String screct_c = "7e6b036298b718da6d1afe4ae5364a1f";
-    public static String key = "密钥设置";
+    public static String key = "v2";
     // 诚欣测试号
     /*public static String appid_c = "wx5fcbd4d313aa4c15";
     public static String screct_c = "a72db0c99cde741eb391af69067aacfa";*/

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

@@ -4,6 +4,6 @@ package com.happy.Until.Enum;
  * 返回数据枚举类型
  */
 public enum B {
-    CODE, MESSAGE,DATA;
+    code, message,data;
 }
 

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

@@ -1,5 +1,5 @@
 package com.happy.Until.Enum;
 
 public enum OrderEnum {
-    间, 晚,房间已满,有空房,微信支付;
+    间, 晚,房间已满,有空房,微信支付,微信退款;
 }

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

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

+ 29 - 27
mhotel/src/com/happy/Until/ResponseUtil.java

@@ -9,7 +9,9 @@ import org.apache.poi.ss.usermodel.Workbook;
 import javax.servlet.http.HttpServletResponse;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class ResponseUtil {
 
@@ -34,16 +36,13 @@ public class ResponseUtil {
 	public static void writeJsonPageData(HttpServletResponse respone, List listPage, int page, int rows, int total) {
 		respone.setContentType("application/json;charset=utf-8");
 
-		JSONObject resultJson = new JSONObject();
 		JSONObject dataJson = new JSONObject();
-		resultJson.put(B.CODE, ResultStatusCode.OK.getMsg());
-		resultJson.put(B.DATA, dataJson);
+		dataJson.put(B.code, ResultStatusCode.OK.getMsg());
 
 		if (listPage == null || listPage.size() == 0) {
 			dataJson.put("rows", "");
 			dataJson.put("total", 0);
 		} else {
-			dataJson.put("code", 200);
 			dataJson.put("rows", rows);
 			// int total = listAll.size();
 			dataJson.put("total", total);// 总记录数
@@ -57,14 +56,14 @@ public class ResponseUtil {
 			dataJson.put("hasNextPage", true);// 有下一页
 			dataJson.put("firstPage", true);// 首页
 			dataJson.put("lastPage", true);// 尾页
-			dataJson.put("listPage", listPage);
+			dataJson.put(B.data, listPage);
 
 		}
 
 		PrintWriter out;
 		try {
 			out = respone.getWriter();
-			out.print(resultJson.toString());
+			out.print(dataJson.toString());
 			out.flush();
 			out.close();
 		} catch (Exception e) {
@@ -75,35 +74,38 @@ public class ResponseUtil {
 	public static void writeJsonIPage(HttpServletResponse respone, IPage iPage) {
 		respone.setContentType("application/json;charset=utf-8");
 
-		JSONObject resultJson = new JSONObject();
 		JSONObject dataJson = new JSONObject();
-		resultJson.put(B.CODE, ResultStatusCode.OK.getStatus());
-		resultJson.put(B.DATA, dataJson);
+		dataJson.put(B.code, ResultStatusCode.OK.getStatus());
+		dataJson.put(B.message, "查询成功");
 		if (iPage.getPageList() == null || iPage.getPageList().size() == 0) {
-			dataJson.put("rows", "");
-			dataJson.put("total", 0);
+//			dataJson.put("rows", "");
+//			dataJson.put("total", 0);
+			dataJson.put(B.data, "");
 		} else {
-			dataJson.put("code", 200);
-			dataJson.put("rows", iPage.getRows());
-			// int total = listAll.size();
-			dataJson.put("total", iPage.getTotal());// 总记录数
-			int totalPage = iPage.getTotal() % iPage.getRows() == 0 ? (iPage.getTotal() / iPage.getRows()) : (iPage.getTotal() / iPage.getRows()) + 1;// 总页数
-			dataJson.put("totalPage", totalPage);
-			dataJson.put("currentPage", iPage.getPage());// 当前页
-			dataJson.put("numPerPage", iPage.getRows());// 每页数
-			dataJson.put("nextPage", totalPage - iPage.getPage() == 0 ? iPage.getPage() : iPage.getPage() + 1);// 下一页
-			dataJson.put("previousPage", iPage.getPage() - 0 == 1 ? iPage.getPage() : iPage.getPage() - 1);// 上一页
-			dataJson.put("hasPreviousPage", true);// 有上一页
-			dataJson.put("hasNextPage", true);// 有下一页
-			dataJson.put("firstPage", true);// 首页
-			dataJson.put("lastPage", true);// 尾页
-			dataJson.put("pageList",iPage.getPageList()); // 分页数据
+			dataJson.put(B.data,iPage); // 分页数据
+//			dataJson.put(B.data,iPage.getPageList()); // 分页数据
+//			Map pageMap = new HashMap();
+//
+//			pageMap.put("rows", iPage.getRows());
+//			// int total = listAll.size();
+//			pageMap.put("total", iPage.getTotal());// 总记录数
+//			int totalPage = iPage.getTotal() % iPage.getRows() == 0 ? (iPage.getTotal() / iPage.getRows()) : (iPage.getTotal() / iPage.getRows()) + 1;// 总页数
+//			pageMap.put("totalPage", totalPage);
+//			pageMap.put("currentPage", iPage.getPage());// 当前页
+//			pageMap.put("numPerPage", iPage.getRows());// 每页数
+//			pageMap.put("nextPage", totalPage - iPage.getPage() == 0 ? iPage.getPage() : iPage.getPage() + 1);// 下一页
+//			pageMap.put("previousPage", iPage.getPage() - 0 == 1 ? iPage.getPage() : iPage.getPage() - 1);// 上一页
+//			pageMap.put("hasPreviousPage", true);// 有上一页
+//			pageMap.put("hasNextPage", true);// 有下一页
+//			pageMap.put("firstPage", true);// 首页
+//			pageMap.put("lastPage", true);// 尾页
+//			dataJson.put("pageData",pageMap);
 		}
 
 		PrintWriter out;
 		try {
 			out = respone.getWriter();
-			out.print(resultJson.toString());
+			out.print(dataJson.toString());
 			out.flush();
 			out.close();
 		} catch (Exception e) {

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

@@ -1,5 +1,6 @@
 package com.happy.action;
 
+import com.happy.Model.AdminManager;
 import com.happy.Model.Booking;
 import com.happy.Model.weixin.PayResult;
 import com.happy.Model.weixin.Users;
@@ -13,8 +14,10 @@ import com.happy.Until.weixin.EndPay;
 import com.happy.Until.weixin.JaxbUtil;
 import com.happy.Until.weixin.PayWxUtil;
 import com.happy.Until.weixin.TongYiReturn;
+import com.happy.common.http.Message;
 import com.happy.common.wx.WxUtil;
 import com.happy.constant.ResultStatusCode;
+import com.happy.service.AdminManagerService;
 import com.happy.service.AppBookService;
 import com.happy.service.BookService;
 import com.happy.service.UserService;
@@ -28,9 +31,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedReader;
 import java.io.PrintWriter;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 订单进去Action请求交互
@@ -46,6 +47,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     public UserService userService;
     @Resource
     public AppBookService appBookService;
+    @Resource
+    public AdminManagerService adminManagerService;
 
     public int page; // 当前页
     public int rows;// 每页显示的行数rows
@@ -140,8 +143,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         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());
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
@@ -153,22 +156,22 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         // 创建订单之前,先验证是否有房间
         String backMessage = appBookService.varificationHouse(houseId, startDate, endDate);
         if (Func.checkNull(backMessage)) {
-            jsonObject.put(B.CODE, ResultStatusCode.CANNTBOOKING.getStatus());
-            jsonObject.put(B.MESSAGE, backMessage);
+            jsonObject.put(B.code, ResultStatusCode.CANNTBOOKING.getStatus());
+            jsonObject.put(B.message, backMessage);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
 
         String mess = appBookService.createOrder(houseId, startDate, endDate, houseOrderNumber, userName, userPhone, userId);
         if (!Func.checkNull(mess)) {
-            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.MESSAGE, mess);
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, mess);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
 
-        jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
+        jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.message, ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
     }
@@ -183,8 +186,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         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());
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
@@ -196,48 +199,284 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         // 创建订单之前,先验证是否有房间
         String backMessage = appBookService.varificationHouse(houseId, startDate, endDate);
         if (Func.checkNull(backMessage)) {
-            jsonObject.put(B.CODE, ResultStatusCode.CANNTBOOKING.getStatus());
-            jsonObject.put(B.MESSAGE, backMessage);
+            jsonObject.put(B.code, ResultStatusCode.CANNTBOOKING.getStatus());
+            jsonObject.put(B.message, backMessage);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
 
         appBookService.reCreateOrder(houseId, startTime, endTime, houseOrderNumber, userName, userPhone, userId);
 
-        jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
+        jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.message, ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
     }
 
     /**
      * bookingId 订单id
+     * open_id
      * 取消订单功能:
      * //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
      *
      * @return
      */
-    public String cancelBooking() {
+    public String cancelBooking() throws Exception {
         if (Func.checkNull(getBookingId()))
             return null;
 
         JSONObject jsonObject = new JSONObject();
 
+        // 取消订单,修改订单的支付状态
         String mess = bookService.cancelBooking(getBookingId());
         if (!Func.checkNull(mess)) {
-            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.MESSAGE, mess);
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, mess);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
 
-        jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
+        Booking booking = bookService.getById(Func.parseInt(this.bookingId));
+        if (booking == null || Func.checkNull(booking.getRefundWay()))
+            return null;
+
+        // 进行判断如果订单是已取消,并且标识字段微信退款,则进入退款流程
+        if (Func.parseStr(PayEnum.SEVEN.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, ResultStatusCode.BAD_REQUEST.getMsg());
+                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, ResultStatusCode.BAD_REQUEST.getMsg());
+                ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.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) {
+                jsonObject.put("code", 507);
+                jsonObject.put("message", "退款失败");
+                ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+                return null;
+            }
+
+            // 设置订单状态为退款中
+            booking.setOrderStatus(Func.parseStr(PayEnum.TEN.getNum()));
+            booking.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+            bookService.updateBooking(booking);  // 退款中
+
+            jsonObject.put("code", 200);
+            jsonObject.put("message", "退款申请已提交,请稍候查询");
+            ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
+            return null;
+        }
+
+        jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.message, ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.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, ResultStatusCode.BAD_REQUEST.getMsg());
+            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, ResultStatusCode.BAD_REQUEST.getMsg());
+            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;
+    }
+
+    /* 退款回调 */
+    public String query_refund() throws Exception {
+
+        // 查询本地数据库中,正在退款中
+        StringBuffer strSqlBook = new StringBuffer();
+        strSqlBook.append(" and order_status = '").append(PayEnum.TEN.getNum()).append("' ");
+        List<Booking> booking = bookService.queryList(strSqlBook.toString());
+        if (booking==null){
+            return null;
+        }
+        WechatUnifiedOrder w = new WechatUnifiedOrder();
+        Map<String, String> params = new HashMap<String, String>();
+        Booking book = new Booking();
+        for (int i = 0; i < booking.size(); i++) {
+            if (booking.get(i) == null)
+                continue;
+            book = booking.get(i);
+            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.setOut_trade_no(book.getOrderNum());
+            w.setTrade_type("JSAPI");
+            params = new HashMap<String, String>();
+            params.put("appid", w.getAppid());
+            params.put("mch_id", w.getMch_id());
+            params.put("out_trade_no", w.getOut_trade_no());
+            params.put("nonce_str", w.getNonce_str());
+            w.setSign(PayWxUtil.getSign(params, WeiXinUtil.key));
+            params.put("sign", w.getSign());
+            String retXml = JaxbUtil.getRequestXml(params);
+            String msg = HttpUtils.post("https://api.mch.weixin.qq.com/pay/refundquery", retXml);
+            if (msg.indexOf("<refund_status_0><![CDATA[SUCCESS]]></refund_status_0>")>0) {
+                // 退款成功,将数据写入本地数据库
+                book.setRefundTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+                book.setRefundAmount(book.getHouseTotalPrice());
+                book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+                bookService.updateBooking(book);
+
+
+                // 发送成功消息给商家和用户
+                AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
+                Users users = userService.queryByUserId(book.getCreateUserid());
+                String sendMsg = "订单:"+ book.getOrderNum() +"已退款成功,请注意查看";
+                // 推给商家
+                Message.send(adminManager.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime());
+                // 推给用户
+                Message.send(users.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime());
+
+            }
+        }
+        String returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
+        HttpServletResponse response = ServletActionContext.getResponse();
+        response.setContentType("text/html;charset=utf-8");
+        PrintWriter out = response.getWriter();
+        out.println(returnMsg);
+        out.flush();
+        out.close();
+
+        return null;
+    }
+
+
+
+    /**
      * bookingId 订单id
      * 删除订单功能(假删除)
      *
@@ -251,14 +490,14 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
         String mess = bookService.delBooking(getBookingId());
         if (!Func.checkNull(mess)) {
-            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.MESSAGE, mess);
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, mess);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
 
-        jsonObject.put(B.CODE, ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.MESSAGE, ResultStatusCode.OK.getMsg());
+        jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.message, ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
     }
@@ -275,8 +514,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     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());
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message, ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
         }
@@ -284,14 +523,14 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         String backMessage = appBookService.varificationHouse(houseId, startTime, endTime);
 
         if (!Func.checkNull(backMessage)) {
-            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.MESSAGE, 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.OK.getStatus());
-        jsonObject.put(B.MESSAGE, OrderEnum.有空房.toString());
+        jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.message, OrderEnum.有空房.toString());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
     }
@@ -307,8 +546,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     public String pay() {
         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, ResultStatusCode.BAD_REQUEST.getMsg());
+            resultjson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            resultjson.put(B.message, ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
             return null;
         }
@@ -316,8 +555,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         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, ResultStatusCode.BAD_REQUEST.getMsg());
+            resultjson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            resultjson.put(B.message, ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
             return null;
         }
@@ -394,13 +633,13 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 booking.setPayWay(OrderEnum.微信支付.toString());
                 bookService.updateBooking(booking);
 
-                resultjson.put(B.CODE, ResultStatusCode.OK.getStatus());
-                resultjson.put(B.MESSAGE, "支付成功");
+                resultjson.put(B.code, ResultStatusCode.OK.getStatus());
+                resultjson.put(B.message, "支付成功");
                 ResponseUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
             }
         } catch (Exception e) {
-            resultjson.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            resultjson.put(B.MESSAGE, e.getMessage());
+            resultjson.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            resultjson.put(B.message, e.getMessage());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
         }
         return null;
@@ -449,7 +688,12 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 return null;
             }
 
-            // 推送消息给商家 TODO
+            AdminManager adminManager = adminManagerService.getById(Func.parseInt(booking.getHotelManagerId()));
+            String sendMsg = "订单:"+ order_num +"已支付,请确认是否接单";
+             // 推送消息给商家 TODO
+            Message.send(adminManager.getOpenid(),booking.getOrderNum(),booking.getUserName(),sendMsg,booking.getCreateTime());
+
+
         } catch (Exception e){
             resultjson.put("message", "支付失败");
             resultjson.put("code", 205);

+ 22 - 9
mhotel/src/com/happy/action/AppHomePageAction.java

@@ -47,6 +47,7 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
 
     public String userCode; // 第一次进来获取用户的code
     public String queryValue; // 首页查寻搜索关键词
+    private String hotel_township; // 所属乡镇
     public Date startTimeQuery; // 查询订房开始时间
     public Date endTimeQuery; // 查询订房结束时间
 
@@ -107,12 +108,13 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
     /**
      * 进入首页,展示民宿数据列表
      * queryValue 查询字段
+     * hotel_townshipId 所属乡镇
      * @return
      */
     public String homePage()
     {
         // 获取民宿列表
-        IPage iPage = appHomePageService.getHotelList(queryValue,page,rows);
+        IPage iPage = appHomePageService.getHotelList(queryValue, hotel_township,page,rows);
         ResponseUtil.writeJsonIPage(ServletActionContext.getResponse(),iPage);
         return null;
     }
@@ -128,8 +130,8 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
         // 如果未赋值,则直接跳出
         if (Func.checkNull(hotelId))
         {
-            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message,ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
             return null;
         }
@@ -140,8 +142,8 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
         Hotel hotel = appHomePageService.getHotelAndHouseByHotelId(hotelId,queryStartTime, queryEndTime);
 
         // 通过时间区间查询房间信息,并带好是否有房标识给前台
-        jsonObject.put(B.CODE,ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.DATA,ResultUtil.ok(hotel));
+        jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.data,ResultUtil.ok(hotel));
         ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
         return null;
     }
@@ -157,16 +159,23 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
         // 如果未赋值,则直接跳出
         if (Func.checkNull(hotelId))
         {
-            jsonObject.put(B.CODE, ResultStatusCode.BAD_REQUEST.getStatus());
-            jsonObject.put(B.MESSAGE,ResultStatusCode.BAD_REQUEST.getMsg());
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message,ResultStatusCode.BAD_REQUEST.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
             return null;
         }
 
         Hotel hotel = hotelService.getById(Func.parseInt(hotelId));
+        if (hotel == null)
+        {
+            jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
+            jsonObject.put(B.message,"无法查询到当前酒店信息");
+            ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
+            return null;
+        }
 
-        jsonObject.put(B.CODE,ResultStatusCode.OK.getStatus());
-        jsonObject.put(B.DATA,ResultUtil.ok(hotel));
+        jsonObject.put(B.code,ResultStatusCode.OK.getStatus());
+        jsonObject.put(B.data,hotel);
         ResponseUtil.writeJson(ServletActionContext.getResponse(),jsonObject.toString());
         return null;
     }
@@ -212,4 +221,8 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
     public void setEndTimeQuery(Date endTimeQuery) {
         this.endTimeQuery = endTimeQuery;
     }
+
+    public void setHotel_township(String hotel_township) {
+        this.hotel_township = hotel_township;
+    }
 }

+ 20 - 20
mhotel/src/com/happy/action/AppMePageAction.java

@@ -150,9 +150,9 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
         Users users = userService.queryByUserId(userId);
 
         JSONObject resultJson = new JSONObject();
-        resultJson.put(B.CODE, ResultStatusCode.OK.getStatus());
-        resultJson.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
-        resultJson.put(B.DATA,users);
+        resultJson.put(B.code, ResultStatusCode.OK.getStatus());
+        resultJson.put(B.message,ResultStatusCode.OK.getMsg());
+        resultJson.put(B.data,users);
         ResponseUtil.writeJson(ServletActionContext.getResponse(),resultJson.toString());
 
     }
@@ -172,16 +172,16 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
 //        // 验证手机号码
 //        if ( !Func.checkPhone(contactUserPhone))
 //        {
-//            resultJson.put(B.CODE,ResponseStatusEnum.FAILED.getStatus());
-//            resultJson.put(B.MESSAGE,"请确认手机号码");
+//            resultJson.put(B.code,ResponseStatusEnum.FAILED.getStatus());
+//            resultJson.put(B.message,"请确认手机号码");
 //            ResponseUtil.writeJson(ServletActionContext.getResponse(),resultJson.toString());
 //            return;
 //        }
 //        // 验证身份证
 //        if (!Func.isCard(contactUserIdNum))
 //        {
-//            resultJson.put(B.CODE,ResponseStatusEnum.FAILED.getStatus());
-//            resultJson.put(B.MESSAGE,"请确认身份证");
+//            resultJson.put(B.code,ResponseStatusEnum.FAILED.getStatus());
+//            resultJson.put(B.message,"请确认身份证");
 //            ResponseUtil.writeJson(ServletActionContext.getResponse(),resultJson.toString());
 //            return;
 //        }
@@ -189,8 +189,8 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
         users.setCard_number(contactUserIdNum);
         userService.update(users);
 
-        resultJson.put(B.CODE,ResultStatusCode.OK.getStatus());
-        resultJson.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
+        resultJson.put(B.code,ResultStatusCode.OK.getStatus());
+        resultJson.put(B.message,ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(),resultJson.toString());
     }
 
@@ -214,8 +214,8 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
         userService.insert(users);
 
         JSONObject resultJson = new JSONObject();
-        resultJson.put(B.CODE,ResultStatusCode.OK.getStatus());
-        resultJson.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
+        resultJson.put(B.code,ResultStatusCode.OK.getStatus());
+        resultJson.put(B.message,ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(),resultJson.toString());
     }
 
@@ -233,8 +233,8 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
 
         userService.update(users);
         JSONObject resultJson = new JSONObject();
-        resultJson.put(B.CODE,ResultStatusCode.OK.getStatus());
-        resultJson.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
+        resultJson.put(B.code,ResultStatusCode.OK.getStatus());
+        resultJson.put(B.message,ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(),resultJson.toString());
     }
 
@@ -250,8 +250,8 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
         JSONObject resultJson = new JSONObject();
         userService.del(Func.parseInt(contactId));
 
-        resultJson.put(B.CODE,ResultStatusCode.OK.getStatus());
-        resultJson.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
+        resultJson.put(B.code,ResultStatusCode.OK.getStatus());
+        resultJson.put(B.message,ResultStatusCode.OK.getMsg());
         ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
     }
 
@@ -280,8 +280,8 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
             OPEN_ID = result.getOpenid();
             if (Func.checkNull(OPEN_ID))
             {
-                resultJson.put(B.CODE,ResultStatusCode.BAD_REQUEST.getStatus());
-                resultJson.put(B.MESSAGE,"未获取到OpenId");
+                resultJson.put(B.code,ResultStatusCode.BAD_REQUEST.getStatus());
+                resultJson.put(B.message,"未获取到OpenId");
                 ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             }
 
@@ -303,9 +303,9 @@ public class AppMePageAction extends ActionSupport implements ServletRequestAwar
                 users = userService.queryByOpenid(OPEN_ID);
             }
 
-            resultJson.put(B.CODE,ResultStatusCode.OK.getStatus());
-            resultJson.put(B.MESSAGE,ResultStatusCode.OK.getMsg());
-            resultJson.put(B.DATA,users);
+            resultJson.put(B.code,ResultStatusCode.OK.getStatus());
+            resultJson.put(B.message,ResultStatusCode.OK.getMsg());
+            resultJson.put(B.data,users);
             ResponseUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return ;
     }

+ 106 - 12
mhotel/src/com/happy/action/appAction.java

@@ -136,12 +136,39 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         this.password = password;
     }
 
-    // 获取code 微信支付第一步 通过code换取网页授权access_token
+    // 查询是否绑定
+    public String getUser(){
+        JSONObject resultJson = new JSONObject();
+        if (code==null){
+            resultJson.put("message", "参数不能为空");
+            resultJson.put("code", 205);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        CodeEntity codeEntity = appService.getCodeInfo(code);
+        Admin admin = appService.queryByOpenid(codeEntity.getOpenid());
+        if (admin==null){
+            resultJson.put("message", "未绑定信息");
+            resultJson.put("code", 205);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        resultJson.put("message", "返回成功");
+        resultJson.put("code", 200);
+        resultJson.put("data", admin);
+        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+        return null;
+    }
+
+    // 开始绑定
     public String code() throws IOException {
         JSONObject resultJson = new JSONObject();
         if (code==null || admin_name==null || password==null){
             resultJson.put("message", "参数不能为空");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
@@ -149,14 +176,15 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         if (login==null){
             resultJson.put("message", "账户或密码错误");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
         CodeEntity codeEntity = appService.getCodeInfo(code);
         Admin admin = appService.queryByNameAndOpenid(admin_name,codeEntity.getOpenid());
         if (admin!=null){
-            resultJson.put("message", "已绑定");
-            resultJson.put("code", 200);
+            resultJson.put("message", "该账户绑定,请勿重复绑定");
+            resultJson.put("code", 205);
             resultJson.put("data",admin);
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
@@ -173,25 +201,44 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         return null;
     }
 
-    public String getUser(){
+    // 解绑
+    public String uncode(){
         JSONObject resultJson = new JSONObject();
-        if (code==null){
+        if (code==null || admin_name==null || password==null){
             resultJson.put("message", "参数不能为空");
             resultJson.put("code", 205);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        Admin login = appService.login(admin_name,password);
+        if (login==null){
+            resultJson.put("message", "账户或密码错误");
+            resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
         CodeEntity codeEntity = appService.getCodeInfo(code);
-        Admin admin = appService.queryByOpenid(codeEntity.getOpenid());
+        Admin admin = appService.queryByNameAndOpenid(admin_name,codeEntity.getOpenid());
         if (admin==null){
-            resultJson.put("message", "未绑定信息");
+            resultJson.put("message", "输入信息与当前绑定账户不匹配");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
-        resultJson.put("message", "返回成功");
-        resultJson.put("code", 200);
-        resultJson.put("data", admin);
+        int m = appService.updateOpenidNull(codeEntity.getOpenid());
+        if (m>0){
+            resultJson.put("message", "解绑成功");
+            resultJson.put("code", 200);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        resultJson.put("message", "解绑失败");
+        resultJson.put("code", 205);
+        resultJson.put("data","");
         ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
         return null;
     }
@@ -202,6 +249,7 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         if (code==null){
             resultJson.put("message", "参数不能为空");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
@@ -210,6 +258,7 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         if (admin==null){
             resultJson.put("message", "未绑定信息");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
@@ -225,6 +274,7 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         if (code==null || admin_name==null || password==null){
             resultJson.put("message", "参数不能为空");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
@@ -232,20 +282,22 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         if (login==null){
             resultJson.put("message", "账户或密码错误");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
         if (login.getLevel().equals("2")){
             resultJson.put("message", "管理员无权限绑定");
             resultJson.put("code", 205);
+            resultJson.put("data","");
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
         }
         CodeEntity codeEntity = appService.getCodeInfo(code);
         AdminManager admin = appService.queryMaByNameAndOpenid(admin_name,codeEntity.getOpenid());
         if (admin!=null){
-            resultJson.put("message", "已绑定");
-            resultJson.put("code", 200);
+            resultJson.put("message",  "该账户绑定,请勿重复绑定");
+            resultJson.put("code", 205);
             resultJson.put("data",admin);
             ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
             return null;
@@ -262,4 +314,46 @@ public class appAction extends ActionSupport implements ServletRequestAware {
         }
         return null;
     }
+
+    public String uncode_ma(){
+        JSONObject resultJson = new JSONObject();
+        if (code==null || admin_name==null || password==null){
+            resultJson.put("message", "参数不能为空");
+            resultJson.put("code", 205);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        AdminManager login = appService.login_ma(admin_name,password);
+        if (login==null){
+            resultJson.put("message", "账户或密码错误");
+            resultJson.put("code", 205);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        CodeEntity codeEntity = appService.getCodeInfo(code);
+        AdminManager admin = appService.queryMaByNameAndOpenid(admin_name,codeEntity.getOpenid());
+        if (admin==null){
+            resultJson.put("message", "输入信息与当前绑定账户不匹配");
+            resultJson.put("code", 205);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        int m = appService.updateMaOpenidNull(codeEntity.getOpenid());
+        if (m>0){
+            resultJson.put("message", "解绑成功");
+            resultJson.put("code", 200);
+            resultJson.put("data","");
+            ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+            return null;
+        }
+        resultJson.put("message", "解绑失败");
+        resultJson.put("code", 205);
+        resultJson.put("data","");
+        ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
+        return null;
+    }
+
 }

+ 4 - 0
mhotel/src/com/happy/dao/AppDao.java

@@ -16,6 +16,8 @@ public interface AppDao {
 
     public int updateOpenid(String openid,String admin_name);
 
+    public int updateOpenidNull(String openid);
+
     /**********************
      * ********商户绑定**********
      * ********************/
@@ -27,4 +29,6 @@ public interface AppDao {
 
     public int updateMaOpenid(String openid,String admin_name);
 
+    public int updateMaOpenidNull(String openid);
+
 }

+ 2 - 0
mhotel/src/com/happy/dao/HotelDao.java

@@ -44,6 +44,8 @@ public interface HotelDao {
     List<Hotel> queryPage(String sqlx, int page, int rows);
 
 
+    int queryTotalPrice(String sqlx);
+
     /**
      * 描述:获取总条数
      * @param sqlx

+ 29 - 0
mhotel/src/com/happy/dao/impl/AppImplDao.java

@@ -80,6 +80,20 @@ public class AppImplDao implements AppDao {
         return num;
     }
 
+    public int updateOpenidNull(String openid){
+        String sql = "update `admin` set openid=null where openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
     /**********************
      * ********商户绑定**********
      * ********************/
@@ -135,4 +149,19 @@ public class AppImplDao implements AppDao {
         }
         return num;
     }
+
+    public int updateMaOpenidNull(String openid){
+        String sql = "update `admin_manager` set openid=null where openid=:openid ";
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        sps.addValue("openid",openid);
+        int num = 0;
+        try{
+            num = namedParameterJdbcTemplate.update(sql, sps);
+        }
+        catch(Exception e){
+            e.printStackTrace();
+        }
+        return num;
+    }
+
 }

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

@@ -133,7 +133,10 @@ 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 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 WHERE status=1 "+sqlx+" ORDER BY id DESC limit :start,:rows ";
+        String sql = "SELECT a.*,b.min_price,c.hotel_township 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 " +
+                " WHERE status=1 "+sqlx+" ORDER BY id DESC limit :start,:rows ";
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("start", start);
         sps.addValue("rows", rows);
@@ -142,6 +145,17 @@ public class HotelImplDao implements HotelDao {
         if (list != null && list.size() > 0) return list;
         return null;
     }
+    @Override
+    public int queryTotalPrice(String sqlx) {
+        String sql = "SELECT count(*) 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 " +
+                "where status=1 "+sqlx;
+
+        MapSqlParameterSource sps = new MapSqlParameterSource();
+        return namedParameterJdbcTemplate.queryForInt(sql, sps);
+    }
+
 
 
     @Override

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

@@ -19,7 +19,7 @@ public interface AppHomePageService {
      * @param rows
      * @return
      */
-    public IPage getHotelList(String queryValue, int page, int rows);
+    public IPage getHotelList(String queryValue,String hotel_township, int page, int rows);
 
     public int getHotelTotal(String queryValue);
 

+ 5 - 0
mhotel/src/com/happy/service/AppService.java

@@ -19,6 +19,8 @@ public interface AppService {
 
     public int updateOpenid(String openid,String admin_name);
 
+    public int updateOpenidNull(String openid);
+
     /**********************
      * ********商户绑定**********
      * ********************/
@@ -29,4 +31,7 @@ public interface AppService {
     public AdminManager queryMaByNameAndOpenid(String admin_name,String openid);
 
     public int updateMaOpenid(String openid,String admin_name);
+
+    public int updateMaOpenidNull(String openid);
+
 }

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

@@ -79,7 +79,7 @@ public interface BookService {
      * @param bookingId
      * @return
      */
-    String cancelBooking(String bookingId);
+    String cancelBooking(String bookingId) throws Exception;
 
     /**
      * 删除订单(假删除)

+ 4 - 1
mhotel/src/com/happy/service/impl/AppHomePageImplService.java

@@ -37,12 +37,15 @@ public class AppHomePageImplService implements AppHomePageService {
 
 
     @Override
-    public IPage<Hotel> getHotelList(String queryValue, int page, int rows) {
+    public IPage<Hotel> getHotelList(String queryValue,String hotel_township, int page, int rows) {
         IPage<Hotel> iPage = new IPage();
         StringBuilder strSql = new StringBuilder("");
         if (!Func.checkNull(queryValue)){
             strSql.append(" and hname like '%").append(queryValue).append("%' ");
         }
+        if (!Func.checkNull(hotel_township)){
+            strSql.append(" and c.hotel_township = '").append(hotel_township).append("' ");
+        }
 
         return hotelService.queryPagePrice(strSql.toString(),page,rows);
     }

+ 8 - 0
mhotel/src/com/happy/service/impl/AppImplService.java

@@ -56,6 +56,10 @@ public class AppImplService implements AppService {
         return appDao.updateOpenid(openid, admin_name);
     }
 
+    public int updateOpenidNull(String openid){
+        return appDao.updateOpenidNull(openid);
+    }
+
     /**********************
      * ********商户绑定**********
      * ********************/
@@ -75,4 +79,8 @@ public class AppImplService implements AppService {
         return appDao.updateMaOpenid(openid, admin_name);
     }
 
+    public int updateMaOpenidNull(String openid){
+        return appDao.updateMaOpenidNull(openid);
+    }
+
 }

+ 23 - 4
mhotel/src/com/happy/service/impl/BookImplService.java

@@ -1,12 +1,16 @@
 package com.happy.service.impl;
 
+import com.happy.Model.AdminManager;
 import com.happy.Model.Booking;
 import com.happy.Until.DateUtil;
+import com.happy.Until.Enum.OrderEnum;
 import com.happy.Until.Enum.PayEnum;
 import com.happy.Until.Func;
+import com.happy.common.http.Message;
 import com.happy.dao.BookDao;
 import com.happy.dto.BookTypeEto;
 import com.happy.dto.IPage;
+import com.happy.service.AdminManagerService;
 import com.happy.service.BookService;
 import org.springframework.stereotype.Service;
 
@@ -20,6 +24,8 @@ public class BookImplService implements BookService {
 
     @Resource
     public BookDao bookDao;
+    @Resource
+    public AdminManagerService adminManagerService;
 
     @Override
     public int insertBooking(Booking book) {
@@ -77,7 +83,7 @@ public class BookImplService implements BookService {
     }
 
     @Override
-    public String cancelBooking(String bookingId) {
+    public String cancelBooking(String bookingId) throws Exception {
         if (Func.checkNull(bookingId))
             return "未传入订单id";
 
@@ -86,20 +92,33 @@ public class BookImplService implements BookService {
         if (Func.parseInt(book.getHotelIsCanorder()) == 2)
             return "商家设置不可取消订单,请联系商家";
 
-        //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款
+        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()));
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
             bookDao.updateBooking(book);
+
+
+            String sendMsg = "订单:"+ book.getOrderNum() +"已取消";
+            // 推送消息给用户
+            Message.send(adminManager.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime());
+
             return null;
-        }else if (status == 2 || status == 3)
+        }else if (status == 2)
         {
             book.setOrderStatus(Func.parseStr(PayEnum.SEVEN.getNum()));
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
+            // 注明需要退款:
+            book.setPayWay(OrderEnum.微信退款.toString());
             bookDao.updateBooking(book);
-            // TODO 退款操作
+            // 走退款操作
+
+            String sendMsg = "订单:"+ book.getOrderNum() +"已取消";
+            // 推送消息给用户
+            Message.send(adminManager.getOpenid(),book.getOrderNum(),book.getUserName(),sendMsg,book.getCreateTime());
             return null;
         }
         return "不可取消订单";

+ 1 - 1
mhotel/src/com/happy/service/impl/HotelImplService.java

@@ -52,7 +52,7 @@ public class HotelImplService implements HotelService {
     public IPage<Hotel> queryPagePrice(String sqlx, int page, int rows) {
         IPage<Hotel> iPage = new IPage();
         List<Hotel> hotelList = hotelDao.queryPagePrice(sqlx,page,rows);
-        int total = hotelDao.queryTotal(sqlx);
+        int total = hotelDao.queryTotalPrice(sqlx);
         iPage.setPageList(hotelList);
         iPage.setPage(page);
         iPage.setTotalPage( (int)Math.ceil((double)total/rows));