一.页面显示我的所有订单
1.在order页面中
//javascript代码,在点击登录支付宝重新付款按钮时会打开一个新的页面显示信息,同时原页面会返回到初始页面 <script type="text/javascript"> function openLink(outTradeNo){ alipayForm.target = "newWindow"; var win = window.open("replayOrder?outTradeNo=" + outTradeNo, "newWindow"); //打开新的页面 win.focus(); window.location.href="initGoods"; //原页面的返回页面 } </script> <div class="table-responsive"> <table class="table table-bordered table-order-t"> <thead> <tr> <th class="wp50">商品</th> <th class="wp10">实付(元)</th> <th class="wp15">订单状态</th> </tr> </thead> </table> <form name="alipayForm" th:object="${alipayForm}" action="replayOrder" method="get"> <table class="table table-bordered table-order" th:each="order,status:${orderList}"> <thead> <tr > <th colspan = "5"> <div class="cf f12 orderT"> <p class="fl">交易时间:<span class="time" th:text="${order.updateTime}"></span>订单号:<span th:text="${order.outTradeNo}"></span></p> <p class="fr"><a th:href="@{deleteOrder(outTradeNo=${order.outTradeNo})}" class="ico-del"></a></p> //删除按钮 </div> </th> </tr> </thead> <tbody> <tr> <td class="wp50"> <h4><span th:text="${order.subject}">商品</span></h4> </td> <td class="wp10">¥<span th:text="${order.price}"></span></td> <td class="wp15"> <div th:if="${#strings.isEmpty(order.isPaid)}"> //如果isPaid为空时则显示未付款 <span>未付款</span> <input type="button" th:onclick="${#strings.concat('openLink(''').concat(order.outTradeNo).concat(''')')}" class="button" th:value="登录支付宝重新付款" /> //重新付款按钮 </div> <div th:if="${#bools.isTrue(order.isPaid)}"> 如果isPaid为true时则显示已付款 <span>已付款</span> </div> </td> </tr> </tbody> </table> </form> </div>
2.在controller中新添加一个机能
@RequestMapping(value = "order", method = RequestMethod.GET) public String order(Model model, AlipayForm alipayForm, HttpSession session, Device device) { GoodsForm goodsForm=new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); log.info("我的订单"); CartForm cartForm = new CartForm(); model.addAttribute("cartForm", cartForm); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) { return "redirect:/initGuestLogin"; } cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("orderList", cartService.searchOrderList(cartForm)); if(device.isNormal()) { return "shop/order"; } else { return "mobile/alipay/replayAlipayConfirm"; } }
3.在service中添加searchOrderList()方法
public List<AlipayForm> searchOrderList(CartForm frm, Integer index) { List<AlipayForm> result = queryDao.executeForObjectList("Cart.selectAlipayHistoryList", frm); return result; }
4.在sql中添加selectAlipayHistoryList查询语句
<select id="selectAlipayHistoryList" parameterClass="cn.agriculture.web.form.CartForm" resultClass="cn.agriculture.web.form.AlipayForm"> SELECT out_trade_no as outTradeNo, subject as subject, price as price, body as body, show_url as showUrl, receive_name as receiveName, receive_address as receiveAddress, receive_zip as receiveZip, receive_phone as receivePhone, receive_mobile as receiveMobile, guest_id as guestId, update_time as updateTime, update_user as updateUser, is_paid as isPaid FROM alipay_history WHERE commodity_id is null AND guest_id = #guestId# ORDER BY update_time DESC </select>
二.删除订单的实现
1.页面中添加删除按钮的链接
2.在controller中添加deleteOreder机能
@RequestMapping(value = "deleteOrder", method = RequestMethod.GET) public String deleteOrder(Model model, AlipayForm alipayForm, HttpSession session, Device device) { GoodsForm goodsForm=new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); log.info("删除我的订单"); CartForm cartForm = new CartForm(); model.addAttribute("cartForm", cartForm); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) { return "redirect:/initGuestLogin"; } cartForm.setGuestId(uvo.getGuestId()); cartService.deleteOrder(alipayForm); //删除的方法 model.addAttribute("cartList", cartService.searchCartList(cartForm)); model.addAttribute("orderList", cartService.searchOrderList(cartForm, 0)); if(device.isNormal()) { return "shop/order"; } else { return "mobile/alipay/replayAlipayConfirm"; } }
3.在service中添加deleteOrder()方法
public int deleteOrder(AlipayForm frm) { int result = updateDao.execute("Cart.deleteOrder", frm); return result; }
4.在sql文中写删除订单的代码
<delete id="deleteOrder" parameterClass="cn.agriculture.web.form.AlipayForm"> DELETE FROM alipay_history WHERE out_trade_no = #outTradeNo# </delete>
三.未付款的订单重新付款
1.在页面中添加重新付款按钮,并传入订单号
2.在controller中
@RequestMapping(value = "replayOrder", method = RequestMethod.GET) public String replayAlipayOrder(Model model, AlipayForm alipayForm, HttpSession session, Device device) { GoodsForm goodsForm=new GoodsForm(); List<GoodsForm> commodityType = goodsService.getType(); goodsForm.setCommodityTypeId(commodityType.get(0).getCommodityTypeId()); model.addAttribute("goodsForm", goodsForm); model.addAttribute("commodityType", commodityType); log.info("重新支付"); AlipayForm result = cartService.searchAlipayHistory(alipayForm); //获取客户订单的相关信息 alipayForm.setOutTradeNo(result.getOutTradeNo()); alipayForm.setBody(result.getBody()); alipayForm.setPrice(result.getPrice()); alipayForm.setReceiveAddress(result.getReceiveAddress()); alipayForm.setReceiveMobile(result.getReceiveMobile()); alipayForm.setReceiveName(result.getReceiveName()); alipayForm.setReceivePhone(result.getReceivePhone()); alipayForm.setReceiveZip(result.getReceiveZip()); alipayForm.setShowUrl(result.getShowUrl()); alipayForm.setSubject(result.getSubject()); model.addAttribute("alipayForm", alipayForm); CartForm cartForm = new CartForm(); UVO uvo = (UVO)session.getAttribute("UVO"); if (uvo == null || StringUtils.isEmpty(uvo.getGuestId())) { return "redirect:/initGuestLogin"; } cartForm.setGuestId(uvo.getGuestId()); model.addAttribute("cartList", cartService.searchCartList(cartForm)); // model.addAttribute("orderList", cartService.searchOrderList(cartForm)); if (device.isNormal()) { model.addAttribute("sHtmlText", alipayRequestWeb(alipayForm)); //alipayRequestWeb私有方法 } else { model.addAttribute("sHtmlText", alipayRequestMobile(alipayForm)); } return "manager/charge/alipay"; }
3.在service中
public AlipayForm searchAlipayHistory(AlipayForm frm) { AlipayForm result = queryDao.executeForObject("Cart.selectAlipayHistory", frm, AlipayForm.class); return result; }
4.在sql文中
<select id="selectAlipayHistory" parameterClass="cn.agriculture.web.form.AlipayForm" resultClass="cn.agriculture.web.form.AlipayForm"> SELECT out_trade_no as outTradeNo, subject as subject, price as price, body as body, show_url as showUrl, receive_name as receiveName, receive_address as receiveAddress, receive_zip as receiveZip, receive_phone as receivePhone, receive_mobile as receiveMobile, guest_id as guestId, update_time as updateTime, update_user as updateUser FROM alipay_history WHERE out_trade_no = #outTradeNo# </select>
5上述的私有方法
private String alipayRequestWeb(AlipayForm alipayForm) { // 支付类型 String payment_type = "1"; // 必填,不能修改 // 服务器异步通知页面路径 String host = env.getProperty("host.web"); String notify_url = host + "/initReturn"; // 需http://格式的完整路径,不能加?id=123这类自定义参数 // 页面跳转同步通知页面路径 String return_url = host + "/initPayResult"; // 需http://格式的完整路径,不能加?id=123这类自定义参数,不能写成http://localhost/ // 商户订单号 String out_trade_no = alipayForm.getOutTradeNo(); // 订单名称 String subject = alipayForm.getSubject(); // 付款金额 String total_fee = alipayForm.getPrice(); // 订单描述 String body = alipayForm.getBody(); // 商品展示地址 String show_url = alipayForm.getShowUrl(); // 需以http://开头的完整路径,如:http://www.商户网站.com/myorder.html //防钓鱼时间戳 String anti_phishing_key = ""; //若要使用请调用类文件submit中的query_timestamp函数 //客户端的IP地址 String exter_invoke_ip = ""; //非局域网的外网IP地址,如:221.0.0.1 // 收货人姓名 String receive_name = alipayForm.getReceiveName(); // 收货人地址 String receive_address = alipayForm.getReceiveAddress(); // 收货人邮编 String receive_zip = alipayForm.getReceiveZip(); // 收货人电话号码 String receive_phone = alipayForm.getReceivePhone(); // 收货人手机号码 String receive_mobile = alipayForm.getReceiveMobile(); body = body + ";" + receive_name + ";" + receive_address + ";" + receive_zip + ";" + receive_phone + ";" + receive_mobile; Map<String, String> sParaTemp = new HashMap<String, String>(); sParaTemp.put("service", "create_direct_pay_by_user"); sParaTemp.put("partner", AlipayConfig.partner); sParaTemp.put("seller_email", AlipayConfig.seller_email); sParaTemp.put("_input_charset", AlipayConfig.input_charset); sParaTemp.put("payment_type", payment_type); sParaTemp.put("notify_url", notify_url); sParaTemp.put("return_url", return_url); sParaTemp.put("out_trade_no", out_trade_no); sParaTemp.put("subject", subject); sParaTemp.put("total_fee", total_fee); sParaTemp.put("body", body); sParaTemp.put("show_url", show_url); sParaTemp.put("anti_phishing_key", anti_phishing_key); sParaTemp.put("exter_invoke_ip", exter_invoke_ip); String sHtmlText = AlipaySubmit.buildRequest(sParaTemp, "get", "确认"); return sHtmlText; }