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();
}
}
}
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;
}
}
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;
}
Aggregations