积分专区的实现 #6

Merged
chenxin merged 1 commits from main-cx into main 2025-02-18 13:59:37 +08:00
3 changed files with 345 additions and 296 deletions

View File

@@ -38,5 +38,9 @@ public interface PmsProductMapper {
PmsProduct getProductInfoById(Long id);
PmsProduct getProductByOrderSn(String orderSn);
}

View File

@@ -921,4 +921,14 @@
where ppfr.product_id=#{id,jdbcType=BIGINT} limit 1
</select>
<select id="getProductByOrderSn" resultMap="BaseResultMap">
SELECT p.*
FROM pms_product p
WHERE p.product_sn = (
SELECT oi.product_sn
FROM oms_order_item oi
WHERE oi.order_sn = #{orderSn}
LIMIT 1
)
</select>
</mapper>

View File

@@ -357,7 +357,18 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
orderResult.setDeliveryCompany(order.getDeliveryCompany());
orderResult.setDeliverySn(order.getDeliverySn());
orderResult.setPaymentTime(order.getPaymentTime());
// 获取商品信息,判断是否是积分专区商品
PmsProduct product = productMapper.getProductByOrderSn((order.getOrderSn()));
boolean isPointsExchangeStatus = product != null && product.getPointsExchangeStatus() == 1;
//支付类型: 0->未支付1->支付宝2->微信; 3->线下支付; 4->积分支付
//判断是否为积分专区商品
if(isPointsExchangeStatus) {
orderResult.setPayType(4); // 设置为积分支付
orderResult.setPayTypeName("积分支付");
}else {
// 如果不是积分兑换专区商品,则继续使用其他支付方式
if (order.getPayType() != null) {
orderResult.setPayType(order.getPayType());
if (order.getPayType() == 0) {
@@ -387,6 +398,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
orderResult.setPayType(0);
orderResult.setPayTypeName("未支付");
}
}
orderResult.setDeliveryTime(order.getDeliveryTime());
orderResult.setReceiveTime(order.getReceiveTime());
@@ -702,7 +714,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
/**
* 直接购买,根据提交信息生成订单
*/
@Transactional
@Transactional(rollbackFor = Exception.class)
@Override
/**
* 创建订单
@@ -736,13 +748,16 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
return CommonResult.validateFailed("未查询到商品信息");
}
PmsProduct product = new PmsProduct();
// 判断商品是否属于积分兑换区
boolean isPointsExchangeStatus = product.getPointsExchangeStatus() == 1;
//判断商品是否都有库存 (库存 - 锁定库存 = 真实库存)
if ((skuStock.getStock() - skuStock.getLockStock()) < orderParam.getQuantity()) {
return CommonResult.validateFailed("库存不足,无法下单");
}
//根据商品id查询商品信息
PmsProduct product = productMapper.selectByPrimaryKey(skuStock.getProductId());
Map<String, Object> result = new HashMap<>();
if(product != null) {
@@ -758,6 +773,24 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
BigDecimal zero = new BigDecimal(0);
totalAmount = price.multiply(new BigDecimal(orderParam.getQuantity()));
// 如果是积分兑换区商品
if (isPointsExchangeStatus) {
// 直接使用积分支付,不进行实际支付金额的处理
BigDecimal integrationAmount = totalAmount;
// 确保会员有足够的积分
if (member.getIntegration() < integrationAmount.intValue()) {
return CommonResult.validateFailed("积分不足,无法兑换");
}
// 冻结会员积分
member.setIntegration(member.getIntegration() - integrationAmount.intValue()); // 扣除积分
member.setFreeze(member.getFreeze().add(new BigDecimal(integrationAmount.intValue()))); // 冻结积分
memberMapper.updateByPrimaryKey(member);
totalAmount = zero; // 设置支付金额为零
orderParam.setIntegration(integrationAmount); // 设置积分金额
}
if(orderParam.getIntegration() == null) {
orderParam.setIntegration(zero);
}
@@ -798,6 +831,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
//生成订单信息
OmsOrder order = new OmsOrder();
order.setTotalAmount(totalAmount); // 订单总金额
order.setIntegrationAmount(orderParam.getIntegration() == null ? zero : orderParam.getIntegration());
if(integerationFlag == 1) {
int flag = orderParam.getIntegration().compareTo(totalAmount);
BigDecimal integeration = new BigDecimal(0);
@@ -837,6 +871,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
order.setModifyTime(date);
order.setMemberUsername(member.getUsername());
order.setFreightAmount(zero); //运费
order.setPayType(isPointsExchangeStatus ? 4 : 0); // payType为4代表积分支付
order.setPromotionAmount(zero); //促销优化金额(促销价、满减、阶梯价)
order.setCouponAmount(zero);
order.setDiscountAmount(zero);