开发者学堂课程【RocketMQ 知识精讲与项目实战(第二阶段):下单基本流程小结】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/703/detail/12422
下单基本流程小结
1、确认订单就是将之前所完成的预订单的状态更新为可见,本质上是更新的操作
//6.确认订单
updateOrderStatus (order);
//确认更新状态,设置支付状态,设置日期
private void updateOrderStatus (TradeOrder order)
{
order. setOrderStatus (ShopCode . SHOP_ORDER_CONFIRM. getCode());
order . setPayStatus (ShopCode . SHOP_ORDER_PAY_ STATUS_ NO_ PAY. getCode());
order . setConfirmTime(new Date());
int r = orderMapper . updateByPrimaryKey(order);
//返回值小于0,代表有问题,订单确认失败
if(r<=0)
{
CastException.cast(ShopCode.SHOP_ ORDER_ CONFIRM_ FAIL);
}
//如果没问题,代表订单完成
log. info("订单:"+order . get0rderId()+" 确认订单成功");
}
2、//7.返回成功状态
Return new Result(ShopCode.
SHOP_SUCCESS.getSuccess(), ShopCode . SHOP_ SUCCESS.
getMessage());
3、@Override
public Result confirmOrder(TradeOrder order) {
//1.校验订单
checkOrder(order);
//2.生成预订单
Long orderId = savePreOrder(order);
try {
//3.扣减库存
reduceGoodsNum( order);
//4.扣减优惠券
updateCouponStatus( order);
//5.使用余额
reduceMoneyPaid(order);
//6.确认订单
updateOrderStatus ( order);
//7.返回成功状态return new Result(ShopCode.SHOP_SUCCESS.getSuccess(),
ShopCode . SHOP_ SUCCESS. getMessage());
} catch (Exception e) {