下单库存校验

This commit is contained in:
2026-04-10 16:57:30 +08:00
parent 0e600d76f8
commit 3fe532ee7d
5 changed files with 71 additions and 207 deletions

View File

@@ -91,10 +91,6 @@ public interface ConsInfoService extends IService<ConsInfo> {
*/ */
void onOffConsInfo(Long id, Integer isStock); void onOffConsInfo(Long id, Integer isStock);
/**
* 是否退款退回
*/
void isRefundStockConsInfo(Long id, Integer isRefundStock);
/** /**
* 修改耗材单位 * 修改耗材单位

View File

@@ -2,10 +2,12 @@ package com.czg.service.order.mapper;
import com.czg.account.vo.HandoverCategoryListVo; import com.czg.account.vo.HandoverCategoryListVo;
import com.czg.account.vo.HandoverProductListVo; import com.czg.account.vo.HandoverProductListVo;
import com.czg.product.vo.ConsStockRecord;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 订单表 映射层。 * 订单表 映射层。
@@ -15,106 +17,6 @@ import java.util.List;
*/ */
public interface OrderInfoCustomMapper{ public interface OrderInfoCustomMapper{
/**
* 交班现金支付统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 现金支付总额
*/
BigDecimal getHandoverCashAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班微信支付统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 现金支付总额
*/
BigDecimal getHandoverWechatAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班支付宝支付统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 支付宝支付总额
*/
BigDecimal getHandoverAlipayAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班VIP支付统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return VIP支付总额
*/
BigDecimal getHandoverVipPayAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班VIP充值统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return VIP充值总额
*/
BigDecimal getHandoverVipChargeAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班快捷支付统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 快捷支付总额
*/
BigDecimal getHandoverQuickPayAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班退款统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 退款总额
*/
BigDecimal getHandoverRefundAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班挂账统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 挂账总额
*/
BigDecimal getHandoverCreditAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班营业额统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 营业额
*/
BigDecimal getHandoverTotalAmount(Long shopId, String loginTime, String handoverTime);
/**
* 交班订单数统计
*
* @param shopId 店铺id
* @param loginTime 上岗时间
* @param handoverTime 交班时间
* @return 交班订单数
*/
int getHandoverOrderNum(Long shopId, String loginTime, String handoverTime);
/** /**
* 交班售出商品明细 * 交班售出商品明细
* *
@@ -138,4 +40,8 @@ public interface OrderInfoCustomMapper{
int decrMoney(@Param("id") Long id, @Param("amount") BigDecimal amount); int decrMoney(@Param("id") Long id, @Param("amount") BigDecimal amount);
int updatePayOrderId(@Param("orderId") Long orderId, @Param("paymentId") Long paymentId, @Param("payType") String payType, @Param("remark") String remark); int updatePayOrderId(@Param("orderId") Long orderId, @Param("paymentId") Long paymentId, @Param("payType") String payType, @Param("remark") String remark);
List<ConsStockRecord> getConsByProductAndNum(
@Param("productUsageMap") Map<Long, BigDecimal> productUsageMap
);
} }

View File

@@ -43,11 +43,14 @@ import com.czg.order.enums.PayEnums;
import com.czg.order.service.*; import com.czg.order.service.*;
import com.czg.order.vo.*; import com.czg.order.vo.*;
import com.czg.pay.PayNotifyRespDTO; import com.czg.pay.PayNotifyRespDTO;
import com.czg.product.entity.ConsInfo;
import com.czg.product.entity.Product; import com.czg.product.entity.Product;
import com.czg.product.entity.ShopProdCategory; import com.czg.product.entity.ShopProdCategory;
import com.czg.product.service.ConsInfoService;
import com.czg.product.service.ProductRpcService; import com.czg.product.service.ProductRpcService;
import com.czg.product.service.ProductService; import com.czg.product.service.ProductService;
import com.czg.product.service.ShopProdCategoryService; import com.czg.product.service.ShopProdCategoryService;
import com.czg.product.vo.ConsStockRecord;
import com.czg.product.vo.ProductStockVO; import com.czg.product.vo.ProductStockVO;
import com.czg.resp.CzgResult; import com.czg.resp.CzgResult;
import com.czg.sa.StpKit; import com.czg.sa.StpKit;
@@ -78,6 +81,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -111,6 +115,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
@DubboReference @DubboReference
private ProductService productService; private ProductService productService;
@DubboReference @DubboReference
private ConsInfoService consInfoService;
@DubboReference
private ShopProdCategoryService shopProdCategoryService; private ShopProdCategoryService shopProdCategoryService;
@DubboReference @DubboReference
private ProductRpcService productRpcService; private ProductRpcService productRpcService;
@@ -1044,17 +1050,14 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
*/ */
private void processOrderDetails(List<OrderDetail> orderDetails, LimitRateDTO limitRate, OrderInfoAddDTO param) throws CzgException { private void processOrderDetails(List<OrderDetail> orderDetails, LimitRateDTO limitRate, OrderInfoAddDTO param) throws CzgException {
BigDecimal packFee = BigDecimal.ZERO; BigDecimal packFee = BigDecimal.ZERO;
Map<Long, BigDecimal> productNumMap = new HashMap<>();
for (OrderDetail detail : orderDetails) { for (OrderDetail detail : orderDetails) {
if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) { if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) {
//TODO 库存问题 商品无库存 统一走 耗材 if (productNumMap.containsKey(detail.getProductId())) {
// Product product = productService.getOne(QueryWrapper.create() productNumMap.put(detail.getProductId(), productNumMap.get(detail.getProductId()).add(detail.getNum().subtract(detail.getReturnNum())));
// .eq(Product::getId, detail.getProductId()) } else {
// .eq(Product::getShopId, detail.getShopId()) productNumMap.put(detail.getProductId(), detail.getNum().subtract(detail.getReturnNum()));
// .eq(Product::getIsDel, 0) }
// .eq(Product::getIsStock, 1));
// if (product != null && detail.getNum().compareTo(new BigDecimal(product.getStockNumber())) > 0) {
// throw new CzgException("下单失败" + product.getName() + "库存不足");
// }
} }
if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
detail.setUnitPrice(detail.getDiscountSaleAmount()); detail.setUnitPrice(detail.getDiscountSaleAmount());
@@ -1072,9 +1075,42 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
detail.setPayAmount(detail.getNum().multiply(detail.getUnitPrice())); detail.setPayAmount(detail.getNum().multiply(detail.getUnitPrice()));
packFee = packFee.add(detail.getPackAmount().multiply(detail.getPackNumber())); packFee = packFee.add(detail.getPackAmount().multiply(detail.getPackNumber()));
} }
if (CollUtil.isNotEmpty(productNumMap)) {
checkStock(param.getShopId(), productNumMap);
}
param.setPackFee(packFee); param.setPackFee(packFee);
} }
/**
* 校验库存数
*
* @param productNumMap 商品Id ,使用数量
*/
private void checkStock(Long shopId, Map<Long, BigDecimal> productNumMap) {
if (CollUtil.isEmpty(productNumMap)) {
return;
}
List<ConsInfo> consStockList = consInfoService.list(new QueryWrapper().select(ConsInfo::getId, ConsInfo::getConName, ConsInfo::getConUnit, ConsInfo::getStockNumber)
.eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getIsStock, 1));
if (CollUtil.isEmpty(consStockList)) {
return;
}
Map<Long, ConsInfo> map = consStockList.stream()
.collect(Collectors.toMap(
ConsInfo::getId,
Function.identity()
));
List<ConsStockRecord> consNumList = orderInfoCustomMapper.getConsByProductAndNum(productNumMap);
for (ConsStockRecord consStockRecord : consNumList) {
if (map.containsKey(consStockRecord.getConsId())) {
ConsInfo consInfo = map.get(consStockRecord.getConsId());
if (consStockRecord.getStockNumber().compareTo(consInfo.getStockNumber()) > 0) {
throw new CzgException("耗材:" + consInfo.getConName() + "库存不足,当前库存:" + consInfo.getStockNumber() + consInfo.getConUnit());
}
}
}
}
@Override @Override
@Transactional @Transactional
public void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount) { public void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount) {

View File

@@ -45,39 +45,6 @@
where id = #{orderId}; where id = #{orderId};
</update> </update>
<select id="getHandoverCashAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(t1.pay_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
and t1.pay_type = 'cash_pay'
</where>
</select>
<select id="getHandoverRefundAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(t1.refund_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
</where>
</select>
<select id="getHandoverTotalAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(t1.pay_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
</where>
</select>
<select id="getHandoverOrderNum" resultType="java.lang.Integer">
SELECT
count(*)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
</where>
</select>
<select id="getHandoverDetailList" resultType="com.czg.account.vo.HandoverProductListVo"> <select id="getHandoverDetailList" resultType="com.czg.account.vo.HandoverProductListVo">
SELECT SELECT
t2.product_id, t2.product_id,
@@ -96,53 +63,7 @@
t2.product_id, t2.product_id,
t2.sku_id t2.sku_id
</select> </select>
<select id="getHandoverWechatAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(t1.pay_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
and t1.pay_type = 'wechat_mini'
</where>
</select>
<select id="getHandoverAlipayAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(t1.pay_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
and t1.pay_type = 'alipay_mini'
</where>
</select>
<select id="getHandoverVipPayAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(t1.pay_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
and t1.pay_type = 'vip_pay'
</where>
</select>
<select id="getHandoverVipChargeAmount" resultType="java.math.BigDecimal">
select ifnull(sum(t1.amount), 0)
from tb_shop_user_flow t1
where t1.shop_id = #{shopId}
and t1.biz_code in ('cashIn', 'wechatIn', 'alipayIn', 'adminIn')
and t1.recharge_id is not null
<![CDATA[
AND t1.create_time >= str_to_date(#{loginTime}, '%Y-%m-%d %H:%i:%s')
AND t1.create_time <= str_to_date(#{handoverTime}, '%Y-%m-%d %H:%i:%s')
]]>
</select>
<select id="getHandoverQuickPayAmount" resultType="java.math.BigDecimal">
SELECT
ifnull(sum(pay_amount),0)
FROM tb_order_info t1
<where>
<include refid="handoverCommonWhere"/>
and t1.pay_type in ('main_scan','back_scan')
</where>
</select>
<select id="getHandoverCategoryList" resultType="com.czg.account.vo.HandoverCategoryListVo"> <select id="getHandoverCategoryList" resultType="com.czg.account.vo.HandoverCategoryListVo">
SELECT case when t3.category_id is null then 0 else t3.category_id end as category_id, SELECT case when t3.category_id is null then 0 else t3.category_id end as category_id,
case when t4.name is null then '未分类' else t4.name end as category_name, case when t4.name is null then '未分类' else t4.name end as category_name,
@@ -158,14 +79,24 @@
</where> </where>
GROUP BY t3.category_id GROUP BY t3.category_id
</select> </select>
<select id="getHandoverCreditAmount" resultType="java.math.BigDecimal">
<select id="getConsByProductAndNum" resultType="com.czg.product.vo.ConsStockRecord">
SELECT SELECT
ifnull(sum(t1.pay_amount),0) r.cons_info_id AS consId,
FROM tb_order_info t1 SUM(
<where> CASE r.product_id
<include refid="handoverCommonWhere"/> <foreach collection="productUsageMap.entrySet()" item="qty" index="pid">
and t1.pay_type = 'credit_pay' WHEN #{pid} THEN #{qty}
</where> </foreach>
END
) AS stockNumber
FROM tb_prod_cons_relation r
WHERE r.product_id IN
<foreach collection="productUsageMap.keySet()" item="pid" open="(" separator="," close=")">
#{pid}
</foreach>
GROUP BY r.cons_info_id
</select> </select>
</mapper> </mapper>

View File

@@ -27,7 +27,7 @@ import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
* @author Tankaikai tankaikai@aliyun.com * @author Tankaikai tankaikai@aliyun.com
* @since 1.0 2025-02-20 * @since 1.0 2025-02-20
*/ */
@Service @DubboService
@AllArgsConstructor @AllArgsConstructor
public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> implements ConsInfoService { public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> implements ConsInfoService {
@@ -182,11 +182,6 @@ public class ConsInfoServiceImpl extends ServiceImpl<ConsInfoMapper, ConsInfo> i
super.updateById(entity); super.updateById(entity);
} }
@Override
public void isRefundStockConsInfo(Long id, Integer isRefundStock) {
}
@Override @Override
public void modifySubUnit(ConsSubUnitParam param) { public void modifySubUnit(ConsSubUnitParam param) {