Search in sources :

Example 1 with OmsOrder

use of com.xatu.gmall.entity.OmsOrder in project GMall by 18391713434.

the class OrderServiceImpl method updateOrderStatus.

@Override
public void updateOrderStatus(String out_trade_no) {
    // 发送订单已支付的队列提供给库存
    Connection connection = null;
    Session session = null;
    try {
        connection = activeMQUtil.getConnectionFactory().createConnection();
        session = connection.createSession(true, Session.SESSION_TRANSACTED);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        OmsOrder omsOrder = new OmsOrder();
        omsOrder.setStatus(1);
        orderMapper.update(omsOrder, new UpdateWrapper<OmsOrder>().eq("out_trade_no", out_trade_no));
        // 调用mq发送支付成功的消息
        Queue order_pay_quene = session.createQueue("ORDER_PAY_QUENE");
        MessageProducer producer = session.createProducer(order_pay_quene);
        // 字符串文本
        TextMessage textMessage = new ActiveMQTextMessage();
        // hash结构
        MapMessage mapMessage = new ActiveMQMapMessage();
        mapMessage.setString("out_trade_no", out_trade_no);
        session.commit();
    } catch (Exception e) {
        // 消息回滚
        try {
            session.rollback();
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    } finally {
        try {
            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
Also used : ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) OmsOrder(com.xatu.gmall.entity.OmsOrder) ActiveMQMapMessage(org.apache.activemq.command.ActiveMQMapMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 2 with OmsOrder

use of com.xatu.gmall.entity.OmsOrder in project GMall by 18391713434.

the class OrderController method submitOrder.

@RequestMapping("/submitOrder")
@LoginRequired(loginSuccess = true)
public ModelAndView submitOrder(String tradeCode, String receiveAddressId, BigDecimal totalAmount, HttpServletRequest request, HttpServletResponse response, HttpSession session, ModelMap modelMap) {
    String memberId = (String) request.getAttribute("memberId");
    String nickname = (String) request.getAttribute("nickname");
    // 检查交易码
    String success = orderService.checkTradeCode(memberId, tradeCode);
    if (success.equals("success")) {
        // 订单项对象
        List<OmsOrderItem> omsOrderItems = new ArrayList<>();
        // 订单对象
        OmsOrder omsOrder = new OmsOrder();
        omsOrder.setAutoConfirmDay(7);
        String outTradeNo = "gmall";
        // 将毫秒时间戳拼接到外部订单号
        outTradeNo = outTradeNo + System.currentTimeMillis();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYYMMDDHHmmss");
        // 将时间字符串拼接到外部订单号
        outTradeNo = outTradeNo + simpleDateFormat.format(new Date());
        // 设置外部订单号
        omsOrder.setOrderSn(outTradeNo);
        omsOrder.setPayAmount(totalAmount);
        omsOrder.setOrderType(1);
        MemberReceiveAddress receiveAddressByReceiveAddressId = userService.getReceiveAddressByReceiveAddressId(receiveAddressId);
        omsOrder.setReceiverDetailAddress(receiveAddressByReceiveAddressId.getDetailAddress());
        omsOrder.setReceiverPhone(receiveAddressByReceiveAddressId.getPhoneNumber());
        omsOrder.setReceiverPostCode(receiveAddressByReceiveAddressId.getPostCode());
        omsOrder.setReceiverProvince(receiveAddressByReceiveAddressId.getProvince());
        omsOrder.setReceiverRegion(receiveAddressByReceiveAddressId.getRegion());
        // 当前日期加一天
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, 1);
        Date date = calendar.getTime();
        omsOrder.setReceiveTime(date);
        omsOrder.setSourceType(0);
        omsOrder.setStatus(0);
        omsOrder.setTotalAmount(totalAmount);
        // 根据用户id获得要购买的商品列表(购物车),和总价格
        List<OmsCartItem> omsCartItems = cartService.carList(memberId);
        for (OmsCartItem omsCartItem : omsCartItems) {
            if (omsCartItem.getIsChecked().equals("1")) {
                // 获得订单详情列表
                OmsOrderItem omsOrderItem = new OmsOrderItem();
                // 验价
                BigDecimal price = omsCartItem.getPrice();
                boolean b = skuService.checkPrice(omsCartItem.getProductSkuId(), price);
                if (b == false) {
                    return new ModelAndView("tradeFail");
                }
                // 验库存
                omsOrderItem.setProductPic(omsCartItem.getProductPic());
                omsOrderItem.setProductName(omsCartItem.getProductName());
                // 外部订单号,用来和其他系统进行交互
                omsOrderItem.setOrderSn(outTradeNo);
                omsOrderItem.setProductCategoryId(omsCartItem.getProductCategoryId());
                omsOrderItem.setProductPrice(omsCartItem.getPrice());
                omsOrderItem.setRealAmount(new BigDecimal(omsCartItem.getTotalPrice()));
                omsOrderItem.setProductQuantity(omsCartItem.getQuantity());
                omsOrderItem.setProductSkuCode("11111111111");
                omsOrderItem.setProductSkuId(omsCartItem.getProductSkuId());
                omsOrderItem.setProductId(omsCartItem.getProductId());
                // 在仓库中对应的skuId
                omsOrderItem.setProductSn("仓库对应的商品编号");
                omsOrderItems.add(omsOrderItem);
            }
        }
        omsOrder.setOmsOrderItems(omsOrderItems);
        // 将订单和订单详情写入数据库
        // 删除购物车的对应商品
        orderService.saveOrder(omsOrder);
        // 重定向到支付系统
        ModelAndView modelAndView = new ModelAndView("redirect:http://localhost:8087");
        modelAndView.addObject("outTradeNo", outTradeNo);
        modelAndView.addObject("totalAmount", totalAmount);
        return modelAndView;
    } else {
        ModelAndView modelAndView = new ModelAndView("tradeFail");
        return modelAndView;
    }
}
Also used : Calendar(java.util.Calendar) OmsCartItem(com.xatu.gmall.entity.OmsCartItem) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) OmsOrderItem(com.xatu.gmall.entity.OmsOrderItem) MemberReceiveAddress(com.xatu.gmall.entity.MemberReceiveAddress) Date(java.util.Date) BigDecimal(java.math.BigDecimal) OmsOrder(com.xatu.gmall.entity.OmsOrder) SimpleDateFormat(java.text.SimpleDateFormat) LoginRequired(com.xatu.gmall.annotations.LoginRequired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with OmsOrder

use of com.xatu.gmall.entity.OmsOrder in project GMall by 18391713434.

the class PaymentController method alipay.

@RequestMapping("/alipay/submit")
@LoginRequired(loginSuccess = true)
@ResponseBody
public String alipay(String outTradeNo, BigDecimal totalAmount, HttpServletRequest request, ModelMap modelMap) {
    String form = null;
    AlipayTradePayRequest alipayTradePayRequest = new AlipayTradePayRequest();
    // 回调函数地址
    alipayTradePayRequest.setReturnUrl(AlipayConfig.return_payment_url);
    alipayTradePayRequest.setNotifyUrl(AlipayConfig.notify_payment_url);
    Map<String, Object> map = new HashMap<>();
    map.put("out_trade_no", outTradeNo);
    map.put("product_code", "FAST_INSTANT_TRADB_PAY");
    map.put("total_amount", totalAmount);
    map.put("subject", "华为p40徕卡八摄影");
    String mapJSONStr = JSON.toJSONString(map);
    alipayTradePayRequest.setBizContent(mapJSONStr);
    // 获得一个支付宝请求客户端(它并不是一个连接,而是一个封装号的http的表单请求)
    try {
        form = alipayClient.pageExecute(alipayTradePayRequest).getBody();
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    // 生成并保存用户的支付信息
    OmsOrder omsOrder = orderService.getOrderByOutTradeNo(outTradeNo);
    PaymentInfo paymentInfo = new PaymentInfo();
    paymentInfo.setCreateTime(new Date());
    paymentInfo.setOrderId(omsOrder.getId().toString());
    paymentInfo.setPaymentStatus("未付款");
    paymentInfo.setSubject("GMALL商城商品一件");
    paymentInfo.setTotalAmount(totalAmount);
    paymentService.savePaymentInfo(paymentInfo);
    // 向消息中间件发送一个检查支付状态(支付服务消费)的延迟消息队列
    paymentService.sendDelayPaymentCheckQueue(outTradeNo, 5);
    return form;
}
Also used : PaymentInfo(com.xatu.gmall.entity.PaymentInfo) HashMap(java.util.HashMap) OmsOrder(com.xatu.gmall.entity.OmsOrder) AlipayApiException(com.alipay.api.AlipayApiException) AlipayTradePayRequest(com.alipay.api.request.AlipayTradePayRequest) Date(java.util.Date) LoginRequired(com.xatu.gmall.annotations.LoginRequired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

OmsOrder (com.xatu.gmall.entity.OmsOrder)3 LoginRequired (com.xatu.gmall.annotations.LoginRequired)2 Date (java.util.Date)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AlipayApiException (com.alipay.api.AlipayApiException)1 AlipayTradePayRequest (com.alipay.api.request.AlipayTradePayRequest)1 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)1 MemberReceiveAddress (com.xatu.gmall.entity.MemberReceiveAddress)1 OmsCartItem (com.xatu.gmall.entity.OmsCartItem)1 OmsOrderItem (com.xatu.gmall.entity.OmsOrderItem)1 PaymentInfo (com.xatu.gmall.entity.PaymentInfo)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 ActiveMQMapMessage (org.apache.activemq.command.ActiveMQMapMessage)1 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1