文章目录
-
- 概要
- 整体架构流程
- 技术细节
- 小结
概要
商家拒单是电子商务、外卖平台、在线零售等多个行业中可能出现的情况,指的是商家拒绝接受或完成某个订单。这种情况的发生可能由多种原因引起,同时也涉及到商家、平台和消费者的利益平衡。
需求分析以及接口设计
技术细节
1.Controller层:
@ApiOperation("拒单")
@PutMapping("/rejection")
public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectDTO){
log.info("接单,{}",ordersRejectDTO);
orderService.rejection(ordersRejectDTO);
return Result.success();
}
2.Service层:
public void rejection(OrdersRejectionDTO ordersRejectionDTO) {
//根据id查询该订单
Orders order = orderMapper.getById(ordersRejectionDTO.getId());
//查询该订单的状态
Integer status = order.getStatus();
if (status == null || status.equals(Orders.TO_BE_CONFIRMED)){
throw new OrderBusinessException(MessageConstant.ORDER_STATUS_ERROR);
}
//获取到支付状态
Integer payStatus = order.getPayStatus();
if (payStatus == Orders.PAID) {
//用户已支付,需要退款(略)
}
//更新订单(状态,取消原因,取消时间)
Orders orders = new Orders();
orders.setId(orders.getId());
orders.setStatus(Orders.CANCELLED);
orders.setRejectionReason(ordersRejectionDTO.getRejectionReason());
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>