支付、订单查询模块
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package com.atguigu.ssyx.order.controller;
|
||||
|
||||
|
||||
import com.atguigu.ssyx.common.auth.AuthContextHolder;
|
||||
import com.atguigu.ssyx.common.result.Result;
|
||||
import com.atguigu.ssyx.model.order.OrderInfo;
|
||||
import com.atguigu.ssyx.order.service.OrderInfoService;
|
||||
import com.atguigu.ssyx.vo.order.OrderConfirmVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderSubmitVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderUserQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -22,10 +27,28 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("/api/order")
|
||||
public class OrderInfoController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@ApiOperation(value = "订单查询")
|
||||
@GetMapping("auth/findUserOrderPage/{page}/{limit}")
|
||||
public Result findUserOrderPage(
|
||||
@ApiParam(name = "page", value = "当前页码", required = true)
|
||||
@PathVariable Long page,
|
||||
@ApiParam(name = "limit", value = "每页记录数", required = true)
|
||||
@PathVariable Long limit,
|
||||
@ApiParam(name = "orderVo", value = "查询对象", required = false)
|
||||
OrderUserQueryVo orderUserQueryVo) {
|
||||
//获取userId
|
||||
Long userId = AuthContextHolder.getUserId();
|
||||
orderUserQueryVo.setUserId(userId);
|
||||
|
||||
//分页查询条件
|
||||
Page<OrderInfo> pageParam = new Page<>(page, limit);
|
||||
IPage<OrderInfo> pageModel = orderInfoService.getOrderInfoByUserIdPage(pageParam, orderUserQueryVo);
|
||||
return Result.ok(pageModel);
|
||||
}
|
||||
|
||||
@ApiOperation("确认订单")
|
||||
@GetMapping("auth/confirmOrder")
|
||||
public Result confirm() {
|
||||
|
@@ -0,0 +1,44 @@
|
||||
package com.atguigu.ssyx.order.receiver;
|
||||
|
||||
import com.atguigu.ssyx.mq.constant.MqConst;
|
||||
import com.atguigu.ssyx.order.service.OrderInfoService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* ClassName: OrderReceiver
|
||||
* Package: com.atguigu.ssyx.order.receiver
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/10/13 14:15
|
||||
*/
|
||||
@Component
|
||||
public class OrderReceiver {
|
||||
@Autowired
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
//订单支付成功,更新订单状态,扣减库存
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
value = @Queue(value = MqConst.QUEUE_ORDER_PAY, durable = "true"),
|
||||
exchange = @Exchange(value = MqConst.EXCHANGE_PAY_DIRECT),
|
||||
key = {MqConst.ROUTING_PAY_SUCCESS}
|
||||
))
|
||||
public void orderPay(String orderNo,
|
||||
Message message,
|
||||
Channel channel) throws IOException {
|
||||
if (!StringUtils.isEmpty(orderNo)) {
|
||||
orderInfoService.orderPay(orderNo);
|
||||
}
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),
|
||||
false);
|
||||
}
|
||||
}
|
@@ -3,6 +3,9 @@ package com.atguigu.ssyx.order.service;
|
||||
import com.atguigu.ssyx.model.order.OrderInfo;
|
||||
import com.atguigu.ssyx.vo.order.OrderConfirmVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderSubmitVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderUserQueryVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
@@ -45,4 +48,20 @@ public interface OrderInfoService extends IService<OrderInfo> {
|
||||
* @return
|
||||
*/
|
||||
OrderInfo getOrderInfoByOrderNo(String orderNo);
|
||||
|
||||
/**
|
||||
* 订单支付成功,更新订单状态,扣减库存
|
||||
*
|
||||
* @param orderNo
|
||||
*/
|
||||
void orderPay(String orderNo);
|
||||
|
||||
/**
|
||||
* 订单查询
|
||||
*
|
||||
* @param pageParam
|
||||
* @param orderUserQueryVo
|
||||
* @return
|
||||
*/
|
||||
IPage<OrderInfo> getOrderInfoByUserIdPage(Page<OrderInfo> pageParam, OrderUserQueryVo orderUserQueryVo);
|
||||
}
|
||||
|
@@ -24,9 +24,12 @@ import com.atguigu.ssyx.order.service.OrderItemService;
|
||||
import com.atguigu.ssyx.vo.order.CartInfoVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderConfirmVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderSubmitVo;
|
||||
import com.atguigu.ssyx.vo.order.OrderUserQueryVo;
|
||||
import com.atguigu.ssyx.vo.product.SkuStockLockVo;
|
||||
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.BoundHashOperations;
|
||||
@@ -328,7 +331,61 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
||||
*/
|
||||
@Override
|
||||
public OrderInfo getOrderInfoByOrderNo(String orderNo) {
|
||||
return null;
|
||||
return baseMapper.selectOne(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getOrderNo, orderNo));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付成功,更新订单状态,扣减库存
|
||||
*
|
||||
* @param orderNo
|
||||
*/
|
||||
@Override
|
||||
public void orderPay(String orderNo) {
|
||||
//查询订单状态是否已经修改完成了支付状态
|
||||
OrderInfo orderInfo = this.getOrderInfoByOrderNo(orderNo);
|
||||
if (orderInfo == null || orderInfo.getOrderStatus() != OrderStatus.UNPAID) {
|
||||
return;
|
||||
}
|
||||
//更新状态
|
||||
this.updateOrderStatus(orderInfo.getId());
|
||||
|
||||
//扣减库存
|
||||
rabbitService.sendMessage(MqConst.EXCHANGE_ORDER_DIRECT, MqConst.ROUTING_MINUS_STOCK, orderNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单查询
|
||||
*
|
||||
* @param pageParam
|
||||
* @param orderUserQueryVo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<OrderInfo> getOrderInfoByUserIdPage(Page<OrderInfo> pageParam, OrderUserQueryVo orderUserQueryVo) {
|
||||
IPage<OrderInfo> pageModel = baseMapper.selectPage(pageParam, new LambdaQueryWrapper<OrderInfo>()
|
||||
.eq(OrderInfo::getUserId, orderUserQueryVo.getUserId())
|
||||
.eq(OrderInfo::getOrderStatus, orderUserQueryVo.getOrderStatus()));
|
||||
|
||||
//获取每个订单,把每个订单里面订单项查询封装
|
||||
List<OrderInfo> orderInfoList = pageModel.getRecords();
|
||||
for (OrderInfo orderInfo : orderInfoList) {
|
||||
//根据订单id查询里面所有订单项列表
|
||||
List<OrderItem> orderItemList = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItem>()
|
||||
.eq(OrderItem::getOrderId, orderInfo.getId()));
|
||||
//把订单项集合封装到每个订单里面
|
||||
orderInfo.setOrderItemList(orderItemList);
|
||||
//封装订单状态名称
|
||||
orderInfo.getParam().put("orderStatusName", orderInfo.getOrderStatus().getComment());
|
||||
}
|
||||
return pageModel;
|
||||
}
|
||||
|
||||
//更新状态
|
||||
private void updateOrderStatus(Long id) {
|
||||
OrderInfo orderInfo = baseMapper.selectById(id);
|
||||
orderInfo.setOrderStatus(OrderStatus.WAITING_DELEVER);
|
||||
orderInfo.setProcessStatus(ProcessStatus.WAITING_DELEVER);
|
||||
baseMapper.updateById(orderInfo);
|
||||
}
|
||||
|
||||
//计算总金额
|
||||
|
Reference in New Issue
Block a user