文章目录
-
- 概要
- 整体架构流程
- 技术细节
- 小结
概要
取消订单是电子商务、外卖平台、在线零售等多个行业中常见的业务需求之一。这项功能允许消费者或商家取消已下的订单,通常是因为各种原因(如商品缺货、配送问题、支付问题等)。
需求分析以及接口设计
技术细节
1.Controller层:
@ApiOperation("取消订单")
@PutMapping("/cancel")
public Result rejection(@RequestBody OrdersCancelDTO ordersCancelDTO){
log.info("取消订单,{}",ordersCancelDTO);
orderService.cancel(ordersCancelDTO);
return Result.success();
}
2.Service层:
public void cancel(OrdersCancelDTO ordersCancelDTO) {
Orders order = orderMapper.getById(ordersCancelDTO.getId());
//获取到支付状态
Integer payStatus = order.getPayStatus();
if (payStatus == Orders.PAID) {
//用户已支付,需要退款(略)
}
Orders orders = new Orders();
orders.setId(orders.getId());
orders.setCancelReason(ordersCancelDTO.getCancelReason());
orders.setCancelTime(LocalDateTime.now());
orderMapper.update(orders);
}
3.Mapper层:
<update id="update" parameterType="com.sky.entity.Orders">
update orders
<set>
<if test="cancelReason != null and cancelReason!='' ">
cancel_reason=#{cancelReason},
</if>
<if test="rejectionReason != null and rejectionReason!='' ">
rejection_reason=#{rejectionReason},
</if>
<if test="cancelTime != null">
cancel_time=#{cancelTime},
</if>
<if test="payStatus != null">
pay_status=#{payStatus},
</if>
<if test="payMethod != null">
pay_method=#{payMethod},
</if>
<if test="checkoutTime != null">
checkout_time=#{checkoutTime},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="deliveryTime != null">
delivery_time = #{deliveryTime}
</if>
</set>
where id = #{id}
</update>