删除已下单商品接口

This commit is contained in:
张松 2025-03-29 14:19:40 +08:00
parent 38e2956537
commit fa36cd135f
4 changed files with 32 additions and 0 deletions

View File

@ -58,4 +58,6 @@ public interface OrderInfoService extends IService<OrderInfo> {
Boolean printOrder(Long shopId, OrderInfoPrintDTO orderInfoPrintDTO);
Boolean removeOrderDetail(Long shopId, Long orderId, Long detailId);
}

View File

@ -5,6 +5,7 @@ import com.czg.account.vo.HandoverProductListVo;
import com.czg.order.entity.OrderInfo;
import com.czg.order.vo.OrderDetailPrintVo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.List;
@ -136,4 +137,6 @@ public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
* @return 售出商品分类统计
*/
List<HandoverCategoryListVo> getHandoverCategoryList(Long shopId, String loginTime, String handoverTime);
int decrMoney(@Param("id") Long id, @Param("amount") BigDecimal amount);
}

View File

@ -961,4 +961,28 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
}
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean removeOrderDetail(Long shopId, Long orderId, Long detailId) {
OrderInfo orderInfo = getOne(new QueryWrapper().eq(OrderInfo::getId, orderId).eq(OrderInfo::getShopId, shopId));
if (orderInfo == null) {
throw new ApiNotPrintException("订单不存在");
}
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
throw new ApiNotPrintException("订单不处于待支付状态");
}
OrderDetail orderDetail = orderDetailService.getOne(new QueryWrapper().eq(OrderDetail::getId, detailId).eq(OrderDetail::getOrderId, orderId));
if (orderDetail == null || !orderDetail.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
throw new ApiNotPrintException("不处于待支付或订单详情不存在");
}
int i = mapper.decrMoney(orderInfo.getId(), orderDetail.getPayAmount().add(orderDetail.getPackAmount()));
if (i > 0) {
return orderDetailService.removeById(orderDetail.getId());
}
throw new ApiNotPrintException("操作失败");
}
}

View File

@ -30,6 +30,9 @@
)
]]>
</sql>
<update id="decrMoney">
update tb_order_info set origin_amount = origin_amount-#{amount}, update_time=now() where id=#{id} and origin_amount-#{amount} >= 0;
</update>
<select id="getHandoverCashAmount" resultType="java.math.BigDecimal">
SELECT