Search in sources :

Example 1 with Order

use of com.guhanjie.model.Order in project weixin-boot by guhanjie.

the class OrderController method searchOrder.

@RequestMapping(value = "search", method = RequestMethod.GET)
public String searchOrder(HttpServletRequest req, HttpServletResponse resp, Model model) {
    resp.setHeader("Cache-Control", "no-cache");
    User user = getSessionUser();
    List<Order> orders = orderService.getOrdersByUser(user);
    model.addAttribute("orders", orders);
    model.addAttribute("now", new Date());
    return "order_search";
}
Also used : Order(com.guhanjie.model.Order) User(com.guhanjie.model.User) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Order

use of com.guhanjie.model.Order in project weixin-boot by guhanjie.

the class TestMessageKit method testSendKFMsg.

@Test
public void testSendKFMsg() {
    Order order = new Order();
    order.setAmount(new BigDecimal(307.0));
    order.setContactor("顾汉杰");
    order.setDistance(new BigDecimal(34.0));
    Position from = new Position();
    from.setAddress("莲泰苑");
    from.setDetail("4号602室");
    from.setFloor((short) 6);
    order.setFrom(from);
    Position to = new Position();
    to.setAddress("莲泰苑");
    to.setDetail("5号502室");
    to.setFloor((short) 5);
    order.setTo(to);
    order.setPhone("13052333613");
    order.setRemark("测试");
    order.setStartTime(new Date());
    order.setVehicle(VehicleEnum.JINBEI.code());
    StringBuffer sb = new StringBuffer("主人,您有新的订单:\n");
    sb.append("订单金额:").append(order.getAmount()).append("元\n");
    sb.append("路程:").append(order.getDistance()).append("公里\n");
    sb.append("联系人:").append(order.getContactor()).append("\n");
    sb.append("电话:").append(order.getPhone()).append("\n");
    sb.append("车型:").append(VehicleEnum.valueOf(order.getVehicle()).desc()).append("\n");
    sb.append("预订时间:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(order.getStartTime())).append("\n");
    sb.append("起始地:").append(order.getFrom().getAddress()).append(" ").append(order.getFrom().getDetail()).append(" 第").append(order.getFrom().getFloor()).append("楼\n");
    sb.append("目的地:").append(order.getTo().getAddress()).append(" ").append(order.getTo().getDetail()).append(" 第").append(order.getTo().getFloor()).append("楼\n");
    sb.append("备注:").append(order.getRemark()).append("\n");
    MessageKit.sendKFMsg(weixinConstants.KF_OPENIDS, sb.toString());
}
Also used : Order(com.guhanjie.model.Order) Position(com.guhanjie.model.Position) SimpleDateFormat(java.text.SimpleDateFormat) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 3 with Order

use of com.guhanjie.model.Order in project weixin-boot by guhanjie.

the class OrderController method payOrder.

@RequestMapping(value = "pay", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> payOrder(HttpServletRequest req, HttpServletResponse resp, final Integer orderid, final Integer tip) {
    resp.setHeader("Cache-Control", "no-cache");
    final String APPID = weixinContants.APPID;
    final String MCH_ID = weixinContants.MCH_ID;
    final String MCH_KEY = weixinContants.MCH_KEY;
    // 查询订单
    final Order order = orderService.getOrderById(orderid);
    if (order == null) {
        return fail("无效的订单号");
    }
    // 获取订单的微信预支付id
    String prepayid = order.getPayId();
    try {
        if (prepayid != null) {
            // 若先前发起过支付,需要验证prepayid是否已关闭
            Map<String, String> map = PayKit.search(order, APPID, MCH_ID, MCH_KEY);
            String payStatus = map.get("result");
            if ("CLOSED".equals(payStatus)) {
                // 若该prepayid已失效则重新下单
                prepayid = null;
            }
        }
        if (prepayid == null) {
            // 设置订单小费(只有在第一次支付时可以设,数据模型有问题,建议订单和支付单独两个表,1:N关系)
            if (tip != null) {
                order.setTip(new BigDecimal(tip));
            }
            prepayid = PayKit.unifiedorder(req, order, APPID, MCH_ID, MCH_KEY);
            order.setPayId(prepayid);
            orderService.updatePayInfo(order);
        }
        // 定时(10分钟)查询订单支付情况
        long now = new Date().getTime();
        taskScheduler.schedule(new Runnable() {

            @Override
            public void run() {
                Map<String, String> map;
                try {
                    map = PayKit.search(order, APPID, MCH_ID, MCH_KEY);
                    String result = map.get("result");
                    Integer orderid = Integer.valueOf(map.get("out_trade_no"));
                    String total_fee = map.get("total_fee");
                    String time_end = map.get("time_end");
                    boolean success = "SUCCESS".equals(result);
                    orderService.updateOrderByPay(success, orderid, total_fee, time_end);
                } catch (Exception e) {
                    LOGGER.error("error in search pay result for order[{}].", orderid, e);
                }
            }
        }, // 产生支付预付单后的10分钟查询,以防微信支付回调没有接收到。
        new Date(now + 10 * 60 * 1000));
    } catch (IOException e) {
        LOGGER.error("error in unified weixin pay for order[{}].", order.getId());
    }
    if (StringUtils.isBlank(prepayid)) {
        throw WebExceptionFactory.exception(WebExceptionEnum.PAY_ERROR, "支付系统有误,目前无法支付");
    }
    Map<String, String> payParams = new HashMap<String, String>();
    final String nonceStr = String.valueOf(new Random().nextInt(10000));
    // 公众号id
    payParams.put("appId", APPID);
    // 时间戳
    payParams.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
    // 随机字符串
    payParams.put("nonceStr", nonceStr);
    // 订单详情扩展字符串
    payParams.put("package", "prepay_id=" + prepayid);
    // 签名方式
    payParams.put("signType", "MD5");
    // 签名
    payParams.put("paySign", PayKit.sign(payParams, MCH_KEY));
    return success(payParams);
}
Also used : Order(com.guhanjie.model.Order) HashMap(java.util.HashMap) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) Date(java.util.Date) WebException(com.guhanjie.exception.WebException) IOException(java.io.IOException) Random(java.util.Random) HashMap(java.util.HashMap) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with Order

use of com.guhanjie.model.Order in project weixin-boot by guhanjie.

the class OrderController method listOrders.

@RequestMapping(value = "list", method = RequestMethod.GET)
public String listOrders(HttpServletRequest req, HttpServletResponse resp, Model model, // yyyy-mm-dd
@RequestParam(required = false) String beginDate, // yyyy-mm-dd
@RequestParam(required = false) String endDate, @PageableDefault(page = 0, size = 5) Pageable pageable) {
    resp.setHeader("Cache-Control", "no-cache");
    Date beginTime = null;
    Date endTime = null;
    if (StringUtils.isNotBlank(beginDate)) {
        beginTime = DateTimeUtil.getDate(beginDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
    }
    if (StringUtils.isNotBlank(endDate)) {
        endTime = DateTimeUtil.getDate(endDate + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
    }
    PageImpl<Order> page = orderService.listOrders(beginTime, endTime, pageable);
    model.addAttribute("orders", page.getContent());
    model.addAttribute("current", page.getNumber());
    model.addAttribute("pages", page.getTotalPages());
    model.addAttribute("now", new Date());
    return "order_list";
}
Also used : Order(com.guhanjie.model.Order) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Order

use of com.guhanjie.model.Order in project weixin-boot by guhanjie.

the class OrderService method updatePayInfo.

/**
 * Method Name:	updatePayInfo<br/>
 * Description:			[更新订单的预支付信息]
 * @author				GUHANJIE
 * @time					2016年10月17日 上午10:30:28
 * @param order
 */
public void updatePayInfo(Order order) {
    if (order != null && order.getId() != null) {
        // just update pay related info, disable status and other fields update for security
        if (order.getTip() != null || order.getPayId() != null) {
            Order o = new Order();
            o.setId(order.getId());
            o.setTip(order.getTip());
            o.setPayId(order.getPayId());
            orderMapper.updateByPrimaryKeySelective(o);
        }
    }
}
Also used : Order(com.guhanjie.model.Order)

Aggregations

Order (com.guhanjie.model.Order)7 Date (java.util.Date)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Position (com.guhanjie.model.Position)2 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2 WebException (com.guhanjie.exception.WebException)1 User (com.guhanjie.model.User)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Map (java.util.Map)1 Random (java.util.Random)1 Test (org.junit.Test)1 PageImpl (org.springframework.data.domain.PageImpl)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1