Search in sources :

Example 51 with XmallException

use of cn.exrick.common.exception.XmallException in project xmall by Exrick.

the class OrderServiceImpl method createOrder.

@Override
public Long createOrder(OrderInfo orderInfo) {
    TbMember member = tbMemberMapper.selectByPrimaryKey(Long.valueOf(orderInfo.getUserId()));
    if (member == null) {
        throw new XmallException("获取下单用户失败");
    }
    TbOrder order = new TbOrder();
    // 生成订单ID
    Long orderId = IDUtil.getRandomId();
    order.setOrderId(String.valueOf(orderId));
    order.setUserId(Long.valueOf(orderInfo.getUserId()));
    order.setBuyerNick(member.getUsername());
    order.setPayment(orderInfo.getOrderTotal());
    order.setCreateTime(new Date());
    order.setUpdateTime(new Date());
    // 0、未付款,1、已付款,2、未发货,3、已发货,4、交易成功,5、交易关闭,6、交易失败
    order.setStatus(0);
    if (tbOrderMapper.insert(order) != 1) {
        throw new XmallException("生成订单失败");
    }
    List<CartProduct> list = orderInfo.getGoodsList();
    for (CartProduct cartProduct : list) {
        TbOrderItem orderItem = new TbOrderItem();
        // 生成订单商品ID
        Long orderItemId = IDUtil.getRandomId();
        orderItem.setId(String.valueOf(orderItemId));
        orderItem.setItemId(String.valueOf(cartProduct.getProductId()));
        orderItem.setOrderId(String.valueOf(orderId));
        orderItem.setNum(Math.toIntExact(cartProduct.getProductNum()));
        orderItem.setPrice(cartProduct.getSalePrice());
        orderItem.setTitle(cartProduct.getProductName());
        orderItem.setPicPath(cartProduct.getProductImg());
        orderItem.setTotalFee(cartProduct.getSalePrice().multiply(BigDecimal.valueOf(cartProduct.getProductNum())));
        if (tbOrderItemMapper.insert(orderItem) != 1) {
            throw new XmallException("生成订单商品失败");
        }
        // 删除购物车中含该订单的商品
        try {
            List<String> jsonList = jedisClient.hvals(CART_PRE + ":" + orderInfo.getUserId());
            for (String json : jsonList) {
                CartProduct cart = new Gson().fromJson(json, CartProduct.class);
                if (cart.getProductId().equals(cartProduct.getProductId())) {
                    jedisClient.hdel(CART_PRE + ":" + orderInfo.getUserId(), cart.getProductId() + "");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // 物流表
    TbOrderShipping orderShipping = new TbOrderShipping();
    orderShipping.setOrderId(String.valueOf(orderId));
    orderShipping.setReceiverName(orderInfo.getUserName());
    orderShipping.setReceiverAddress(orderInfo.getStreetName());
    orderShipping.setReceiverPhone(orderInfo.getTel());
    orderShipping.setCreated(new Date());
    orderShipping.setUpdated(new Date());
    if (tbOrderShippingMapper.insert(orderShipping) != 1) {
        throw new XmallException("生成物流信息失败");
    }
    return orderId;
}
Also used : Gson(com.google.gson.Gson) XmallException(cn.exrick.common.exception.XmallException) Date(java.util.Date) XmallException(cn.exrick.common.exception.XmallException) CartProduct(cn.exrick.manager.dto.front.CartProduct)

Example 52 with XmallException

use of cn.exrick.common.exception.XmallException in project xmall by Exrick.

the class OrderServiceImpl method payOrder.

@Override
public int payOrder(TbThanks tbThanks) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String time = sdf.format(new Date());
    tbThanks.setTime(time);
    tbThanks.setDate(new Date());
    TbMember tbMember = tbMemberMapper.selectByPrimaryKey(Long.valueOf(tbThanks.getUserId()));
    if (tbMember != null) {
        tbThanks.setUsername(tbMember.getUsername());
    }
    if (tbThanksMapper.insert(tbThanks) != 1) {
        throw new XmallException("保存捐赠支付数据失败");
    }
    // 设置订单为已付款
    TbOrder tbOrder = tbOrderMapper.selectByPrimaryKey(tbThanks.getOrderId());
    tbOrder.setStatus(1);
    tbOrder.setUpdateTime(new Date());
    tbOrder.setPaymentTime(new Date());
    if (tbOrderMapper.updateByPrimaryKey(tbOrder) != 1) {
        throw new XmallException("更新订单失败");
    }
    // 发送通知确认邮件
    String tokenName = UUID.randomUUID().toString();
    String token = UUID.randomUUID().toString();
    // 设置验证token键值对 tokenName:token
    jedisClient.set(tokenName, token);
    jedisClient.expire(tokenName, PAY_EXPIRE);
    emailUtil.sendEmailDealThank(EMAIL_SENDER, "【XMall商城】支付待审核处理", tokenName, token, tbThanks);
    return 1;
}
Also used : XmallException(cn.exrick.common.exception.XmallException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

XmallException (cn.exrick.common.exception.XmallException)52 Date (java.util.Date)26 TbMember (cn.exrick.manager.pojo.TbMember)12 DataTablesResult (cn.exrick.common.pojo.DataTablesResult)11 TbMemberExample (cn.exrick.manager.pojo.TbMemberExample)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Gson (com.google.gson.Gson)4 TbItem (cn.exrick.manager.pojo.TbItem)3 TbThanksExample (cn.exrick.manager.pojo.TbThanksExample)3 PageInfo (com.github.pagehelper.PageInfo)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 CartProduct (cn.exrick.manager.dto.front.CartProduct)2 SearchItem (cn.exrick.manager.dto.front.SearchItem)2 TbContentCategory (cn.exrick.manager.pojo.TbContentCategory)2 TbItemCat (cn.exrick.manager.pojo.TbItemCat)2 TbItemDesc (cn.exrick.manager.pojo.TbItemDesc)2 TbPanel (cn.exrick.manager.pojo.TbPanel)2 TbThanks (cn.exrick.manager.pojo.TbThanks)2 TransportClient (org.elasticsearch.client.transport.TransportClient)2